public async Task <ActionResult> Create(string id, ManageDetailsViewModel model) { if (string.IsNullOrEmpty(id)) { return(NotFound()); } id = id.Normalize(); var user = await _context.Users.SingleOrDefaultAsync(u => u.NormalizedUserName == id); if (user == null) { return(NotFound()); } if (!await _roleManager.RoleExistsAsync(model.NewRole)) { await _roleManager.CreateAsync(new IdentityRole(model.NewRole)); } if (!await _userManager.IsInRoleAsync(user, model.NewRole)) { await _userManager.AddToRoleAsync(user, model.NewRole); } return(RedirectToAction(nameof(Index), "Manage", new { id = user.UserName })); }
public async Task <ActionResult> UserDetails(ManageDetailsViewModel model) { if (ModelState.IsValid) { var UserId = User.Identity.GetUserId(); var user = await _db.Users.FirstOrDefaultAsync(applicationUser => applicationUser.Id == UserId); user.FirstName = model.FirstName; user.LastName = model.LastName; user.MiddleName = model.MiddleName; user.AccountName = model.AccountName; _db.Entry(user).State = EntityState.Modified; await _db.SaveChangesAsync(); } return(RedirectToAction("UserDetails", new { id = User.Identity.GetUserId() })); }