Esempio n. 1
0
        public async Task <IActionResult> OnPostAsync(Role role, List <int> selectedPermissions)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            await _permissionService.EditRoleAsync(role);

            await _permissionService.RemovePermissionRolesByRoleIdAsync(role.Id);

            foreach (var permissionId in selectedPermissions)
            {
                var rolePermission = new RolePermission
                {
                    PermissionId = permissionId,
                    RoleId       = role.Id
                };
                await _permissionService.AddPermissionRoleAsync(rolePermission);
            }


            TempData["Success"] = "اطلاعات نقش با موفقیت بروز شد";
            return(RedirectToPage("/Admin/Roles/Index"));
        }
Esempio n. 2
0
        public async Task <IActionResult> OnPostAsync(Role role, List <int> selectedPermissions)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (!selectedPermissions.Any())
            {
                TempData["Error"] = "حداقل یک سطح دسترسی باید انتخاب گردد";
                return(RedirectToPage("CreateRole"));
            }

            var roleId = await _permissionService.AddRoleAsync(role);

            foreach (var permissionId in selectedPermissions)
            {
                var rolePermission = new RolePermission
                {
                    PermissionId = permissionId,
                    RoleId       = roleId
                };
                await _permissionService.AddPermissionRoleAsync(rolePermission);
            }

            TempData["Success"] = "نقش با موفقیت افزوده شد";
            return(RedirectToPage("/Admin/Roles/Index"));
        }