Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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();
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
 public IActionResult ChangeRole([FromBody] ChangeRoleDTO changeRole)
 {
     return(Ok(userManager.ChangeRole(changeRole)));
 }