Esempio n. 1
0
        public async Task <ActionResult> Remove(string role)
        {
            var model = new RemoveRoleViewModel(role);
            await _roleManagerAppService.Remove(model);

            return(ResponseDelete());
        }
Esempio n. 2
0
        public async Task <ActionResult <DefaultResponse <bool> > > Remove([FromBody] RemoveRoleViewModel model)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return(Response(false));
            }
            await _roleManagerAppService.Remove(model);

            return(Response(true));
        }
        public async Task <IActionResult> RemoveRole(RemoveRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByIdAsync(model.Id);

                await _userManager.RemoveFromRoleAsync(user, model.Role);

                return(RedirectToAction("Edit", new { id = user.Id }));
            }
            else
            {
                return(View());
            }
        }
Esempio n. 4
0
        public async Task <IActionResult> Delete(string returnUrl = null)
        {
            var model = new RemoveRoleViewModel();
            var role  = new ApplicationRole()
            {
                Name = model.Name, Description = model.Description, Id = model.Id
            };
            var result = await _roleManager.UpdateAsync(role);

            if (result.Succeeded)
            {
                return(View("Index"));
            }
            AddErrors(result);
            return(View("Index"));
        }
        public IActionResult RemoveRole(string id, string username, string role)
        {
            if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(role))
            {
                var removeRoleModel = new RemoveRoleViewModel()
                {
                    Username = username,
                    Id       = id,
                    Role     = role
                };

                return(View(removeRoleModel));
            }
            else
            {
                return(View());
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> RemoveRole(RemoveRoleViewModel model)
        {
            var roleExist = await this.roleManager.RoleExistsAsync(model.Role);

            var user = await this.userManager.FindByIdAsync(model.UserId);

            if (!roleExist || user == null)
            {
                this.ModelState.AddModelError(string.Empty, "Invalid identity details.");
            }

            if (!this.ModelState.IsValid)
            {
                return(this.RedirectToAction(nameof(this.AddToRole)));
            }

            this.TempData.AddSuccessMessage($"User {user.UserName} successfully removed from {model.Role} role.");
            await this.userManager.RemoveFromRoleAsync(user, model.Role);

            return(this.RedirectToAction(nameof(this.AddToRole)));
        }
        public Task Remove(RemoveRoleViewModel model)
        {
            var command = _mapper.Map <RemoveRoleCommand>(model);

            return(Bus.SendCommand(command));
        }