I've added custom fields to the ApplicationUser
class
I've also created a form through which the user can enter/edit the fields.
However for some reason I'm not able to update the fields in the database.
[HttpPost]
[ActionName("Edit")]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Manage(EditProfileViewModel model)
{
if (ModelState.IsValid)
{
// Get the current application user
var user = User.Identity.GetApplicationUser();
// Update the details
user.Name = new Name { First = model.FirstName, Last = model.LastName, Nickname = model.NickName };
user.Birthday = model.Birthdate;
// This is the part that doesn't work
var result = await UserManager.UpdateAsync(user);
// However, it always succeeds inspite of not updating the database
if (!result.Succeeded)
{
AddErrors(result);
}
}
return RedirectToAction("Manage");
}
My problem is similar to MVC5 ApplicationUser custom properties, but that seems to use an older version of Identity because the IdentityManager class doesn't seem to exist.
Can someone guide me on how to update User
info in the database?
UPDATE:
If I include all the fields in the register form, all the values are stored in the appropriate field in a new record of the Users
table from the database.
I don't know to make changes to the fields of an existing user (row in the users
table). UserManager.UpdateAsync(user)
doesn't work.
Also note my issue is more Identity oriented than EntityFramework
ApplicationUser
. The fields of name is a column in the database (as Name_First, Name_Last and Name_NickName). My problem is with the file database not getting updated with the new values when I callUserManager.UpdateAsync(user)
. I just want to know how I'm supposed to go about updating the ApplicationUser (Users table) – galdin