Beispiel #1
0
        public async Task <ActionResult> DeleteRole(string ID)
        {
            AppRole appRole = await RoleManager.FindByIdAsync(ID);

            if (appRole == null)
            {
                ViewBag.Error = $"Error occurred while deleting role with ID = {ID}";
                return(View("Error"));
            }
            else
            {
                IdentityResult identityResult = await RoleManager.DeleteAsync(appRole);

                if (identityResult.Succeeded)
                {
                    TempData["Message"] = new Message()
                    {
                        Text = "Success! <strong>You have successfully deleted a role.</strong>", ClassName = "alertMessage successful"
                    };
                    return(RedirectToAction("List"));
                }
                foreach (var x in identityResult.Errors)
                {
                    ModelState.AddModelError("", x);
                }
                TempData["Message"] = new Message()
                {
                    Text = "Error! <strong>There was a problem while deleting a role.</strong>", ClassName = "alertMessage error"
                };
                return(View());
            }
        }
Beispiel #2
0
        public async Task <IHttpActionResult> DeleteRole(string Id)
        {
            var role = await AppRoleManager.FindByIdAsync(Id);

            if (role != null)
            {
                IdentityResult result = await AppRoleManager.DeleteAsync(role);

                if (!result.Succeeded)
                {
                    GetErrorResult(result);
                }
                return(Ok());
            }

            return(NotFound());
        }
        public async Task <ActionResult> Delete(string id)
        {
            var role = await _roleManager.FindByIdAsync(id);

            if (role == null)
            {
                return(View("Error", new[] { "Role Not Found" }));
            }

            var result = await _roleManager.DeleteAsync(role);

            if (result.Succeeded)
            {
                return(RedirectToAction("Index"));
            }

            return(View("Error", result.Errors));
        }
Beispiel #4
0
        public async Task <HttpResponseMessage> Delete(HttpRequestMessage request, string id)
        {
            var role = await AppRoleManager.FindByIdAsync(id);

            var listPermission = _permissionService.GetByRoleId(id);

            if (listPermission.Count > 0)
            {
                _permissionService.Delete(id);
            }
            var result = await AppRoleManager.DeleteAsync(role);

            if (result.Succeeded)
            {
                return(request.CreateResponse(HttpStatusCode.OK, "Xóa thành công" + nameof(id)));
            }
            else
            {
                return(request.CreateErrorResponse(HttpStatusCode.BadRequest, string.Join(",", result.Errors)));
            }
        }
        public async Task <ActionResult> Delete(string id)
        {
            AppRole role = await RoleManager.FindByIdAsync(id);

            if (role != null)
            {
                IdentityResult result = await RoleManager.DeleteAsync(role);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("_Error", result.Errors));
                }
            }
            else
            {
                return(View("_Error", new string[] { "Role Not Found" }));
            }
        }
 public async Task <IdentityResult> DeleteAsync(ApplicationRole role)
 {
     return(await _roleManager.DeleteAsync(role));
 }