public virtual ActionResult Edit(string userName) { var loggedInUser = _userService.GetApplicationUser(); var user = this._userService.GetApplicationUser(userName); var domicileId = Convert.ToInt32(this._userService.GetApplicationUser().Domiciles.FirstOrDefault().DomicileId); var manCos = this._manCoService.GetManCos(domicileId); var userRoles = this._userService.GetRoles(loggedInUser.Id).ToList(); var editModel = new EditUserViewModel(user, loggedInUser.UserName); editModel.DomicileId = domicileId; editModel.UserManCoViewModel.SelectedItems = this.GenerateManCoCheckedList(user.ManCos); editModel.UserManCoViewModel.AddManCos(manCos.ToList()); editModel.AddDomiciles(this._userService.GetUserDomiciles().ToList()); var identityRoles = this._identityRoleService.GetRoles(); //editModel.AddIdentityRoles(identityRoles); editModel.AddIdentityRoles(this._identityRoleService.GetRoles(), userRoles); editModel.SelectedRoleItems = this.GenerateRolesCheckedList( identityRoles, this._userService.GetRoles(user.Id).ToList()); return(View(editModel)); }
public virtual ActionResult Edit(string submitButton, EditUserViewModel editModel) { if (!this.ModelState.IsValid) { var errorList = this.ModelState.Values.SelectMany(x => x.Errors).ToList(); if (errorList.Count > 0) { this.TempData["comment"] = errorList[0].ErrorMessage; } else { this.TempData["comment"] = "Required fields are empty"; } var user = this._userService.GetApplicationUser(editModel.UserName); editModel.AddDomiciles(this._userService.GetUserDomiciles().ToList()); var identityRoles = this._identityRoleService.GetRoles(); editModel.AddIdentityRoles(identityRoles); var manCos = this._manCoService.GetManCos(editModel.DomicileId).ToList(); editModel.UserManCoViewModel.SelectedItems = this.GenerateManCoCheckedList(user.ManCos); editModel.UserManCoViewModel.AddManCos(manCos); if (editModel.UserManCoViewModel.PostedCheckBox != null) { editModel.UserManCoViewModel.SelectedItems = this.GenerateManCoCheckedList( manCos, editModel.UserManCoViewModel.PostedCheckBox.CheckBoxValues.ToList()); } editModel.SelectedRoleItems = this.GenerateRolesCheckedListByRoleIds( identityRoles, editModel.PostedRolesCheckBox.CheckBoxValues); return(this.View(editModel)); } switch (submitButton) { case "Save": return(this.SubmitUserChanges(editModel)); case "Unlock User": return(this.UnlockUser(editModel.UserId)); default: return(View()); } }