Пример #1
0
        public async Task <IActionResult> RoleDelete(
            Guid?siteId,
            Guid roleId,
            int returnPageNumber = 1)
        {
            var selectedSite = await _siteManager.GetSiteForDataOperations(siteId, true);

            var role = await _roleManager.FindByIdAsync(roleId.ToString());

            if (role != null && role.SiteId == selectedSite.Id && role.IsDeletable(_setupOptions.RolesThatCannotBeDeleted))
            {
                var rejectReasons = new List <string>();
                foreach (var guard in _roleGuards)
                {
                    var rejectReason = await guard.GetEditRejectReason(selectedSite.Id, role.RoleName);

                    if (!string.IsNullOrWhiteSpace(rejectReason))
                    {
                        rejectReasons.Add(rejectReason);
                    }
                }
                if (rejectReasons.Count > 0)
                {
                    var alertMessage = string.Join("<br />", rejectReasons.ToArray());

                    this.AlertDanger(alertMessage, true);

                    return(RedirectToAction("Index", new { siteId = selectedSite.Id }));
                }


                await _roleManager.DeleteUserRolesByRole(roleId);

                await _roleManager.DeleteRole(roleId);

                string successFormat = _sr["The role <b>{0}</b> was successfully deleted."];

                this.AlertWarning(string.Format(successFormat, role.RoleName), true);
            }

            return(RedirectToAction("Index", new { siteId = selectedSite.Id, pageNumber = returnPageNumber }));
        }
Пример #2
0
        public async Task <IActionResult> RoleDelete(
            Guid?siteId,
            Guid roleId,
            int returnPageNumber = 1)
        {
            var selectedSite = await _siteManager.GetSiteForDataOperations(siteId, true);

            var role = await _roleManager.FindByIdAsync(roleId.ToString());

            if (role != null && role.SiteId == selectedSite.Id && role.IsDeletable(_setupOptions.RolesThatCannotBeDeleted))
            {
                await _roleManager.DeleteUserRolesByRole(roleId);

                await _roleManager.DeleteRole(roleId);

                string successFormat = _sr["The role <b>{0}</b> was successfully deleted."];

                this.AlertWarning(string.Format(successFormat, role.RoleName), true);
            }

            return(RedirectToAction("Index", new { siteId = selectedSite.Id, pageNumber = returnPageNumber }));
        }