public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description")] TaskTemplate taskTemplate) { if (id != taskTemplate.ID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(taskTemplate); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskTemplateExists(taskTemplate.ID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(taskTemplate)); }
public async Task <IActionResult> Edit(string id, [Bind("UserName,Email,Id,PasswordHash,EmailConfirmed,LockoutEnabled")] IdentityUser user) { if (id != user.Id) { return(NotFound()); } if (ModelState.IsValid) { try { user = _context.Users.Where(x => x.Id == user.Id).FirstOrDefault(); string selectedRole = Request.Form["SelectedRole"].ToString(); user.UserName = Request.Form["UserName"].ToString(); user.Email = Request.Form["Email"].ToString(); List <IdentityUserRole <string> > userRoles = _context.UserRoles.Where(x => x.UserId == user.Id).ToList(); foreach (var item in userRoles) { _context.Remove(item); } await _userManager.AddToRoleAsync(user, selectedRole); _context.Update(user); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserExists(user.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View()); }