public IActionResult ManageUser(UserEditModel model) { model.Update(); using (var uow = _identityDataService.StartUnitOfWork()) { var dbUser = uow.UserRepository.Get(model.Id); var roles = uow.RoleRepository.GetAll(); var userRoles = uow.UserRoleRepository.FindByUser(dbUser).Select(ur => roles.Single(r => r.Id == ur)).ToList(); if (dbUser == null) { return(View("Error")); } if (ModelState.IsValid) { dbUser.Email = model.Email; dbUser.Name = model.Name; dbUser.Phone = model.Phone; uow.UserRepository.Update(dbUser); uow.Commit(); model.UpdateSuccess(); } model.UserRoles = userRoles.Select(ur => new UserRoleModel { Name = ur.Name }); model.Roles = roles.Except(userRoles).Select(r => new UserRoleModel { Name = r.Name }); } return(View(model)); }