public async Task <IActionResult> UpdateRole(string id) { IdentityRole identityRole = await roleManager.FindByIdAsync(id); if (identityRole == null) { ViewBag.ErrorMessage = $"Role with the ID: {id} is not available."; return(View()); } else { var users = userManager.Users.ToList(); List <string> userslist = new List <string>(); foreach (var user in users) { if (await userManager.IsInRoleAsync(user, identityRole.Name)) { userslist.Add(user.UserName); } } UpdateRoleViewModel updateRoleViewModel = new UpdateRoleViewModel() { ID = id, RoleName = identityRole.Name, Users = userslist }; return(View(updateRoleViewModel)); } }
public async Task <IActionResult> UpdateRole(UpdateRoleViewModel updateRoleViewModel) { if (ModelState.IsValid) { IdentityRole identityRole = await roleManager.FindByIdAsync(updateRoleViewModel.ID); if (identityRole == null) { ViewBag.ErrorMessage = $"Role with the ID: {updateRoleViewModel.ID} is not available."; return(View()); } else { identityRole.Name = updateRoleViewModel.RoleName; var result = await roleManager.UpdateAsync(identityRole); if (result.Succeeded) { return(RedirectToAction("DisplayRoles", "Administrator")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } } } return(View()); }
public async Task <IActionResult> SaveEditRolePermissions([FromBody] UpdateRoleViewModel viewModel) { if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageRoles)) { return(Forbid()); } var role = (Role)await _roleManager.FindByNameAsync(_roleManager.NormalizeKey(viewModel.RoleName)); if (role == null) { return(NotFound()); } role.RoleDescription = viewModel.RoleDescription; var rolePermissions = new List <RoleClaim>(); //Current, permissions of role are updated from a UI, maybe we can setup it inside code instead of using UI foreach (string permissionName in viewModel.SelectedPermissions) { rolePermissions.Add(new RoleClaim { ClaimType = Permission.ClaimType, ClaimValue = permissionName }); } role.RoleClaims.RemoveAll(c => c.ClaimType == Permission.ClaimType); role.RoleClaims.AddRange(rolePermissions); await _roleManager.UpdateAsync(role); return(Ok("Save permissions of role successfully")); }
public async Task <ActionResult> EditRole(string id) { var role = await roleManager.FindByIdAsync(id); if (role == null) { return(NotFound()); } var model = new UpdateRoleViewModel() { RoleId = role.Id, RoleName = role.Name }; foreach (var user in userManager.Users) { if (await userManager.IsInRoleAsync(user, role.Name)) { model.Users.Add(user.UserName); } } return(View(model)); }
public async Task <IActionResult> Update(UpdateRoleViewModel model) { var role = await _roleManager.FindByIdAsync(model.Id); if (role != null) { if (!_roleManager.RoleExistsAsync(model.Name).Result) { role.Name = model.Name; var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction(nameof(List))); } else { AddErrosToModelState(result); } } else { ModelState.AddModelError("", "نقش با این نام ثبت شده."); } return(View(model)); } else { ModelState.AddModelError("", "نقش پیدا نشد"); return(RedirectToAction(nameof(List), new { errors = GetErrosFromModelState() })); } }
public async Task <IActionResult> Update(UpdateRoleViewModel model) { var role = await _roleManager.FindByIdAsync(model.Id.ToString()); if (role == null) { return(View("StatusCodes/RoleNotFound", model.Id)); } else { role.Name = model.RoleName; var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction("GetRoles")); } foreach (var resultError in result.Errors) { ModelState.AddModelError("", resultError.Description); } } return(View(model)); }
public async Task <IActionResult> EditRolePartialView(Guid?id) { if (id == null) { return(NotFound()); } var applicationRole = await _roleManager.FindByIdAsync(id.ToString()); if (applicationRole == null) { return(NotFound()); } var rolePermissionId = await _applicationDbContext.Set <RolePermission>().Where(x => x.RoleId == id) .Select(x => x.PermissionId.ToString()).ToListAsync(); var model = new UpdateRoleViewModel { Id = applicationRole.Id, Name = applicationRole.Name, Title = applicationRole.Title, IsDeleted = applicationRole.IsDeleted, IsNoEditable = applicationRole.IsNoEditable, Permissions = await _applicationDbContext.Permissions.AsNoTracking() .Where(x => x.ClientId == applicationRole.ClientId).ToListAsync(), SelectedPermissionId = rolePermissionId }; return(PartialView("Partial/EditRolePartialView", model)); }
public async Task <IActionResult> UpdateRole(UpdateRoleViewModel model) { var role = await roleManager.FindByIdAsync(model.Id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {model.Id} cannot be found"; return(View("Not Found")); } else { role.Name = model.RoleName; var result = await roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction("ReadRoles")); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } return(View(model)); } }
public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(NotFound()); } var applicationRole = await _roleManager.FindByIdAsync(id.ToString()); if (applicationRole == null) { return(NotFound()); } var rolePermissionId = await _permissionsContext.RolePermissions.Where(x => x.RoleId == id) .Select(x => x.PermissionId.ToString()).ToListAsync(); var model = new UpdateRoleViewModel { Id = applicationRole.Id, ClientName = ConfigurationDbContext.Clients.FirstOrDefault(x => x.Id.Equals(applicationRole.ClientId)) ?.ClientName, Name = applicationRole.Name, Title = applicationRole.Title, IsDeleted = applicationRole.IsDeleted, IsNoEditable = applicationRole.IsNoEditable, Permissions = await _permissionsContext.Permissions.AsNoTracking() .Where(x => x.ClientId == applicationRole.ClientId).ToListAsync(), SelectedPermissionId = rolePermissionId, TenantId = applicationRole.TenantId }; return(View(model)); }
public async Task <IActionResult> UpdateRole(string id) { var role = await roleManager.FindByIdAsync(id); if (role == null) { ViewBag.ErrorMessage = $"Role with Id = {id} cannot be found"; return(View("Not Found")); } var model = new UpdateRoleViewModel { Id = role.Id, RoleName = role.Name }; foreach (var user in userManager.Users) { if (await userManager.IsInRoleAsync(user, role.Name)) { model.Users.Add(user.UserName); } } return(View(model)); }
public IActionResult UpdateRole(string id) { var model = new UpdateRoleViewModel(); model.UserName = id; return(this.View(model)); }
public UpdateRolePage(RoleUser role) { InitializeComponent(); var viewModel = new UpdateRoleViewModel(); viewModel.Role = role; BindingContext = viewModel; }
public IHttpActionResult Put(UpdateRoleViewModel modifiedModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _service.Update(_mapper.Map <Role>(modifiedModel)); return(Ok()); }
public async Task <ActionResult <DefaultResponse <bool> > > UpdateRole([FromBody] UpdateRoleViewModel model) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(Response(false)); } await _roleManagerAppService.Update(model); return(Response(true)); }
public async Task <ActionResult> UpdateRole(string role, [FromBody] UpdateRoleViewModel model) { if (!ModelState.IsValid) { NotifyModelStateErrors(); return(ModelStateErrorResponseError()); } await _roleManagerAppService.Update(role, model); return(ResponsePutPatch()); }
public IActionResult Update(int Id, [FromBody] UpdateRoleViewModel viewModel) { return(ApiAction(() => { var contract = _mapper.Map <UpdateRoleContract>(viewModel); contract.Id = Id; _roleService.Update(contract); return Accepted(new { Id }); })); }
/// <summary> /// 修改用户权限 /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task UpdateRole(UpdateRoleViewModel model) { await _userRepository.EditAsync(new User { Id = model.Id, Level = model.Level, DepartmentId = model.DepartmentId, DomainAccount = model.DomainAccount, EmpNo = model.EmpNo, UserName = model.UserName }); }
public IActionResult Update(int id, UpdateRoleViewModel model) { var role = _roleAppService.GetRoleById(id); model = new UpdateRoleViewModel { Id = role.Id, IsDefault = role.IsDefault, Name = role.Name }; return(PartialView("_Update", model)); }
public async Task <IActionResult> UpdateRoleAsync(UpdateRoleViewModel model) { RoleDto role = new RoleDto { Id = model.Role.Id, Name = model.Role.Name }; await roleService.UpdateAsync(role); return(RedirectToAction("RolesList", "Account")); }
public async Task <IActionResult> UpdateRole(int id) { var role = await _roleManager.Roles.FirstOrDefaultAsync(p => p.Id == id); UpdateRoleViewModel model = new UpdateRoleViewModel { Id = role.Id, Name = role.Name }; return(View(model)); }
public async Task <IActionResult> UpdateRole(UpdateRoleViewModel model) { var user = await this.userManagerWrapper.FindByNameAsync(model.UserName); if (user == null) { throw new ArgumentNullException("User not found!"); } await this.userManagerWrapper.AddToRoleAsync(user, model.RoleName); return(this.RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Edit(UpdateRoleViewModel model) { if (ModelState.IsValid) { try { await _roleService.UpdateAsync(model.Name, model.Claims?.Where(itm => itm.Checked).Select(itm => itm.Value)); return(Content(Url.Action(nameof(Index)))); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } } return(BadRequest(GetModelError())); }
public async Task <UpdateRoleViewModel> GetUserIdentityByUsername(string userName, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager) { var user = await userManager.FindByNameAsync(userName); var model = new UpdateRoleViewModel(); model.UserID = user.Id; var identityrole = await roleManager.FindByIdAsync(user.Id); model.RoleName = identityrole.Name; model.Username = user.UserName; var roles = roleManager.Roles; foreach (var item in roles) { model.Roles.Add(item.Name); } return(model); }
public async Task <IActionResult> UpdateRole(UpdateRoleViewModel model) { if (ModelState.IsValid) { var role = await _roleManager.Roles.FirstOrDefaultAsync(p => p.Id == model.Id); role.Name = model.Name; var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction("Index")); } foreach (var item in result.Errors) { ModelState.AddModelError("", item.Description); } } return(View(model)); }
public async Task <JsonResult> UpdateRole(UpdateRoleViewModel model) { JsonResult result = new JsonResult(); result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; if (!ModelState.IsValid) { var Errors = new List <string>(); foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { Errors.Add(error.ErrorMessage.ToString()); } } result.Data = new { Success = false, Errors = Errors }; return(result); } else { try { await ControlPanelService.Instance.UpdateRole(new IdentityRole() { Id = model.ID, Name = model.Name }); result.Data = new { Success = true }; } catch (Exception ex) { result.Data = new { Success = false, Errors = ex.InnerException }; } } return(result); }
public async Task <IActionResult> UpdateRole(UpdateRoleViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var roleToUpdate = RoleDTOToUpdateRoleMapper.Instance.MapBack(model); var result = await adminService.UpdateRole(roleToUpdate); if (result.NotFound) { return(NotFound(result)); } if (result.Succeeded) { return(RedirectToAction(nameof(GetAllRoles), "Admin", new { area = "Admin" })); } AddModelErrors(result); return(View(model)); }
public async Task <IActionResult> Update(string id) { var role = await _roleManager.FindByIdAsync(id); if (role != null) { var model = new UpdateRoleViewModel() { Name = role.Name, OldName = role.Name, Id = role.Id, }; return(View(model)); } else { ModelState.AddModelError("", "نقش یافت نشد"); } return(RedirectToAction(nameof(List), new { errors = GetErrosFromModelState() })); }
public IActionResult Update(UpdateRoleViewModel model) { var role = new RoleModel() { Id = model.Id, Name = model.Name, IsDefault = model.IsDefault }; role = _roleAppService.UpdateRole(role); return(Json(new JsonResultEntity() { Message = "修改角色基本信息成功!", JsonObject = Json(new RoleViewModel() { Id = role.Id, Name = role.Name, IsDefault = role.IsDefault, LastModificationTime = role.LastModificationTime?.ToStandardDateOfChina(), }) })); }
public async Task <IActionResult> _EditRole(string id) { if (id == null) { return(NotFound()); } var applicationRole = await RoleManager.FindByIdAsync(id); if (applicationRole == null) { return(NotFound()); } var roleProfilesId = await ApplicationDbContext.Set <RoleProfile>() .Where(x => x.ApplicationRoleId == applicationRole.Id).Select(x => x.ProfileId.ToString()) .ToListAsync(); var rolePermissionId = await ApplicationDbContext.Set <RolePermission>().Where(x => x.RoleId == id) .Select(x => x.PermissionId.ToString()).ToListAsync(); var model = new UpdateRoleViewModel { Profiles = await ApplicationDbContext.Profiles.Where(x => x.IsDeleted == false) .ToListAsync(), // ApplicationDbContext.GetAll<Profile>(x => x.IsDeleted == false), Id = applicationRole.Id, Name = applicationRole.Name, SelectedProfileId = roleProfilesId, Title = applicationRole.Title, IsDeleted = applicationRole.IsDeleted, IsNoEditable = applicationRole.IsNoEditable, PermissionsList = await ApplicationDbContext.Permissions.AsNoTracking() .Where(x => x.ClientId == applicationRole.ClientId).ToListAsync(), SelectedPermissionId = rolePermissionId }; return(PartialView(model)); }
public async Task <ActionResult> EditRole(UpdateRoleViewModel model) { var role = await roleManager.FindByIdAsync(model.RoleId); if (role == null) { return(NotFound()); } role.Name = model.RoleName; var result = await roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction(nameof(AllRoles))); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); }