0

i added some properties like First name,last name,telephone to the Identitymodel.cs and it goes together with the default username and password when you want to signup. now my problem is this, The first name, last name and telephone i added into it. i want to use it for the profile page but i don't know how to retrieve it and edit it since it is in the Identitymodel.cs

Can it be edited and if yes, how do i go about it. please i am stuck.

 public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string HomeAddress { get; set; }
    public string Phone { get; set; }
    public string Country { get; set; }
    public string Zip { get; set; }
    public string SelfDescription { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    public ApplicationDbContext()
        : base("DefaultConnection")
    {
    }
}

}

1 Answers1

0

You can definitely access and edit these properties. Check out this intro to Asp.Net Identity. To make the profile page and access all the details you listed above I would start by making a view model to pass the details to:

public class profileViewModel
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string HomeAddress { get; set; }
}

Then in your controller, use UserManager to access the profile details and send them to your view:

public ActionResult ProfileViewModel()
    {
        var userid = User.Identity.GetUserId();
        var mngr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
        var theuser = mngr.FindById(userid);

        profileViewModel profile = new profileViewModel();
        profile.FirstName = theuser.FirstName;
        profile.LastName = theuser.LastName;
        profile.HomeAddress = theuser.HomeAddress;

        return View(profile);
    }

You'll want to make another POST method in your controller to update profile information. When you get to that step check out this SE post which has some great code samples.

Community
  • 1
  • 1
scurrie
  • 403
  • 1
  • 6
  • 12