Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
Basically I want users to reset password after initial login. I just need help with the UPDATE method.Updating password in database.


My controller

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jury_service.Models;

namespace jury_service.Controllers
{
    public class NewpasswordController : Controller
    {
        //
        // GET: /Newpassword/

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]           *blueerrorlinehere
        public ActionResult CreatePassword(CreateNewInfo login)
        {
            if (ModelState.IsValid)
            {
                //Retrieve User
                var uname = login.UpdateUser(login);
                var newpassword = login.UpdateUser(login);
                var confirmnewpassword = login.UpdateUser(login);

                if (uname != null)
                {
                    if
                        (newpassword == confirmnewpassword)
                    {
                        return Redirect("");
                    }

                    else
                    {
                        ModelState.AddModelError("Error", "Passwords Must Match");

                    }
                    return View();

                }
            }

        }
    
        //{
        //    if (ModelState.IsValid)
        //    {
        //        var ffcuser = UpdateInfoREcordByName(login.uname);
                
        //        //var valid = login.DoLogin();

        //        //if (valid)
        //        //{
        //        //    //return RedirectToAction("fccindex", "FCCLogin");
        //        //    return RedirectToAction("CreatePassword", "New password");
        //        //}
        //        ModelState.AddModelError("Error", "Wrong Username and/or Password");
        //        ModelState.Clear();

        //    }
        //    return View();
        //}

        public ActionResult CreatePassword()
        {
            return View();
        }

        public ActionResult CreateNewInfo()
        {
            return View();
        }
    }
}




View

C#
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Net;
using System.Web.Providers.Entities;
using jury_service.CommonService;

namespace jury_service.Models
{
    public class CreateNewInfo : BaseModel
    {

        [Display(Name = "Username")]
        [Required]
        public string uname { get; set; }

        //[Display(Name = "Old Password")]
        //[Required]
        //public string oldpassword { get; set; }

        [Display(Name = "New Password")]
        [Required]
        public string newpassword { get; set; }

        [Display(Name = "Confirm Password")]
        [Required]
        public string confirmnewpassword { get; set; }

        public CreateNewInfo(): base(new WebClient(), new CommonClient(), new Factory())
        {

        }


        //public CreateNewInfo(WebClient client)
        //{
        //    Client = client;
        //}

        //public FCC_Users infoModel;

        //public FCC_Users info;


        //public List<FCC_Users> infos;




        public FCC_Users UpdateUser(CreateNewInfo login)
        {
            try
            {
            //    //Add Request Headers
            //    Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
            //    //Make Request to API and return results
            //    return JsonConvert.DeserializeObject<FCC_Users>(Client.DownloadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname)));

                //Create Json object
              
                //Add Request Headers
                Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
                //Make Request to API and return results
                return JsonConvert.DeserializeObject<FCC_Users>(Client.UploadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname )));




            }
            catch (Exception ex)
            {
                return null;
            }


        }

        //        public FCC_Users UpdateInfoREcordByName(string infoName)
        //        {

        //            Client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
        //            infoModel = JsonConvert.DeserializeObject<FCC_Users>(client.UploadString(client.DownloadString(url));
        //            return info;
        //        }
        //}

    }
}


What I have tried:

Error:

[HttpPost] *blueerrorlinehere
public ActionResult CreatePassword(CreateNewInfo login)

Error 1 'jury_service.Controllers.NewpasswordController.CreatePassword(jury_service.Models.CreateNewInfo)': not all code paths return a value





Error line within the parentheses
return JsonConvert.DeserializeObject<fcc_users>(Client.UploadString(new Uri(Properties.Settings.Default.Api_Url + "Info" + "?infoname=" + login.uname )));

Error message
No overload for method 'UploadString' takes 1 arguments
Posted
Updated 21-Jun-16 9:04am

1 solution

  1. The method CreatePassword has two return statements. If ModelState.IsValid evaluates to false, nothing is returned. In case of true, if uname == null still nothing is returned.
  2. return JsonConvert.DeserializeObject… — please provide error information. Something can be missing, underfined, etc.
  3. Look at the signature of UploadString. Most likely, you are trying to use one of the methods System.Net.WebClient.UploadString. Look at their signatures:
    WebClient.UploadString Method (System.Net).

    As you can see, the expect one or two parameters. You are trying to pass Uri, but there are no methods expecting only this parameter; you need to add one or two string parameters — please see two last methods.

    Now, it's very likely that the error #2 is indirectly caused by this error, so please fix it.


I must note that all the compilation errors you face are clearly described by the error messages, very clearly. You have to learn understanding them, which is linked to understanding of the syntax and other fundamental and elementary language and programming concepts.

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900