public async Task <ActionResult> ChangeRole([Bind(Include = "UserId,OldRole,Role")] ChangeRoleModel model) { if (ModelState.IsValid) { try { ChangeRoleDTO changeRoleDTO = new ChangeRoleDTO { UserId = model.UserId, OldRole = model.OldRole, Role = model.Role }; await UserService.ChangeUserRole(changeRoleDTO); TempData["success"] = "Изменения сохранены."; } catch (Exception) { ModelState.AddModelError("", "Произошла ошибка. Попробуйте еще раз либо обратитесь к администратору."); } } ViewBag.Role = GetRoleNameSelectList(model.Role); return(View()); }
public async Task ChangeUserRole(ChangeRoleDTO changeRoleDTO) { await worker.UserManager.RemoveFromRoleAsync(changeRoleDTO.UserId, changeRoleDTO.OldRole); await worker.UserManager.AddToRoleAsync(changeRoleDTO.UserId, changeRoleDTO.Role); await worker.SaveAsync(); }
public Facilitator ChangeRole(ChangeRoleDTO roleDTO) { Facilitator facilitator = Data.Facilitators.Where(w => w.FacilitatorID == roleDTO.FacilitatorId).FirstOrDefault(); if (facilitator == null) { return(facilitator); } facilitator.Role = roleDTO.NewRole; Data.Update(facilitator); Data.SaveChanges(); return(facilitator); }
public async Task ChangeUserRole(ChangeRoleDTO changeRoleDTO) { if (!string.IsNullOrEmpty(changeRoleDTO.OldRole)) { await _unitOfWork.UserManager.RemoveFromRoleAsync(changeRoleDTO.UserId, changeRoleDTO.OldRole); } if (!string.IsNullOrEmpty(changeRoleDTO.Role)) { await _unitOfWork.UserManager.AddToRoleAsync(changeRoleDTO.UserId, changeRoleDTO.Role); } await _unitOfWork.SaveAsync(); }
public IActionResult ChangeRole([FromBody] ChangeRoleDTO changeRole) { return(Ok(userManager.ChangeRole(changeRole))); }