Exemple #1
0
        // GET: Role/Delete/5
        public async Task <ActionResult> Delete(string username, string roleName)
        {
            DeleteUserRoleViewModel deleteuserVM = new DeleteUserRoleViewModel();

            deleteuserVM.ID           = FindUserIDByUsername(username);
            deleteuserVM.roleToDelete = roleName;

            if (deleteuserVM.ID != null && roleName != null)
            {
                await DeleteRolesAsync(deleteuserVM.ID, roleName);
            }

            return(RedirectToAction("Index"));
        }
Exemple #2
0
        public async Task <IActionResult> RemoveUserRoleAsync([FromBody] DeleteUserRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                var roleResult = await _userManager.RemoveFromRoleAsync(user, model.RoleName);

                if (!roleResult.Succeeded)
                {
                    AddErrors(roleResult);
                }
            }
            return(RedirectToAction("Manage", "Account"));
        }
Exemple #3
0
        public async Task <IActionResult> AddUserRoleAsync([FromBody] DeleteUserRoleViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                var roleResult = await _userManager.AddToRoleAsync(user, model.RoleName);

                if (!roleResult.Succeeded)
                {
                    AddErrors(roleResult);
                }
            }
            //return PartialView("_UserRolesPartial",roleInputViewModel);
            return(RedirectToAction("Manage", "Account"));
        }