public ActionResult Edit(Guid?id) { if (id == null) { GetAlert(Danger, "ID cannot be null!"); return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var user = TheUserManager.GetUserById(id); if (user == null) { GetAlert(Danger, "User cannot be found!"); return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var model = new UserVm.Edit() { UserId = user.UserId, UserName = user.Name, UserEnabled = user.Enabled, UserLocked = user.Locked }; var userRoles = TheUserManager.GetRolesForUser(id); var roles = TheRoleManager.GetAllRoles(); var roleDetail = roles.Select(rd => new CheckBoxListItem() { Id = rd.RoleId, Display = rd.Name, IsChecked = userRoles.Any(ur => ur.RoleId == rd.RoleId) }).ToList(); model.Roles = roleDetail; return(View("Edit", model)); }
public ActionResult Edit(UserVm.Edit model) { if (ModelState.IsValid) { var rolesToAdd = model.Roles.Where(x => x.IsChecked).Select(x => x.Id).ToList(); TheUserManager.UpdateUser(model.UserId, model.UserName, model.UserEnabled, model.UserLocked, rolesToAdd); GetAlert(Success, "Role updated!"); return(RedirectToAction("Index")); } GetAlert(Danger, "Error!"); return(View("Edit", model)); }
public ActionResult Edit(UserVm.Edit model) { if (ModelState.IsValid) { var rolesToAdd = model.RolesList.Where(p => p.IsChecked).Select(r => r.Id).ToList(); var teamsToAdd = model.TeamsList.Where(p => p.IsChecked).Select(r => r.Id).ToList(); _userSvc.Edit(model.UserId, model.UserName, model.UserFirstName, model.UserLastName, model.UserAlias, model.UserEmailAddress, model.UserLoginEnabled, rolesToAdd, teamsToAdd); GetAlert(Success, "User updated!"); return(RedirectToAction("Index")); } GetAlert(Danger, "Error!"); return(View("Edit", model)); }
public ActionResult Edit(Guid id) { var user = _userSvc.GetById(id); if (user == null) { GetAlert(Danger, "User cannot be found!"); return(new HttpStatusCodeResult(HttpStatusCode.NotFound)); } var model = new UserVm.Edit() { UserId = user.UserId, UserName = user.UserName, UserFirstName = user.FirstName, UserLastName = user.LastName, UserAlias = user.Alias, UserEmailAddress = user.EmailAddress, UserLoginEnabled = user.LoginEnabled }; var userRoles = _userSvc.GetRolesForUser(id); var rolesList = _roleSvc.GetAll().Select(vm => new CheckBoxListItem { Id = vm.RoleId, Display = vm.Name, IsChecked = userRoles.Any(p => p.RoleId == vm.RoleId) }).ToList(); var userTeams = _userSvc.GetTeamsForUser(id); var teamsList = _teamSvc.GetAll().Select(vm => new CheckBoxListItem { Id = vm.TeamId, Display = vm.Name, IsChecked = userTeams.Any(p => p.TeamId == vm.TeamId) }).ToList(); model.RolesList = rolesList; model.TeamsList = teamsList; return(View("Edit", model)); }