示例#1
0
        public async Task <IActionResult> EditRole(RoleClaimViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _roleRepo.CreateRoleClaimsAsync(model);

                return(RedirectToAction(nameof(ViewRoles)));
            }
            // Need to repopulate the checkbox list.

            var claims = await _roleRepo.GetIdentityClaimListAsync();

            var claimsList = claims.ToList();

            var roleList = claimsList.GroupBy(x => x.ClaimType)
                           .Select(list => list.Select(element => new ClaimCheckboxViewModel
            {
                ID          = element.ID,
                ClaimType   = element.ClaimType,
                ClaimValue  = element.ClaimValue,
                DisplayName = element.DisplayName
            })
                                   .ToList())
                           .ToList();

            model.ClaimLists = roleList;

            return(View(model));
        }
示例#2
0
        public async Task <IActionResult> EditRole(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Get the corresponding Role
            var repoRolesList = await _roleRepo.GetIdentityRolesAsync();

            var role = repoRolesList.FirstOrDefault(x => x.ID == id);

            if (role == null)
            {
                return(NotFound());
            }

            var model = new RoleClaimViewModel
            {
                RoleID   = role.ID,
                RoleName = role.Name
            };

            var claims = await _roleRepo.GetIdentityClaimListAsync();

            // Get the existing RoleClaims for Role
            var existingClaims = await _roleRepo.GetIdentityClaimsForRoleAsync(role.ID);

            var selected = new List <int>();

            if (existingClaims != null)
            {
                selected.AddRange(existingClaims.Select(claim => claim.ID));
            }

            var roleList = claims.GroupBy(x => x.ClaimType)
                           .Select(list => list.Select(element => new ClaimCheckboxViewModel
            {
                ID          = element.ID,
                ClaimType   = element.ClaimType,
                ClaimValue  = element.ClaimValue,
                DisplayName = element.DisplayName
            })
                                   .ToList())
                           .ToList();

            model.ClaimLists     = roleList;
            model.SelectedClaims = selected;

            return(View(model));
        }
示例#3
0
        public async Task <int> CreateRoleClaimsAsync(RoleClaimViewModel model)
        {
            try
            {
                var encodedString = model.RoleID.ToString() + ',' + string.Join(',', model.SelectedClaims);

                using (var connection = _connectionProvider.Create())
                {
                    return(await connection.ExecuteScalarAsync <int>("dbig5_admin.ADD_CLAIMS_TO_ROLE_VIASQLDEV", new { pEncodedString = encodedString }, commandType : CommandType.StoredProcedure));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            // Return "Fail to Insert"
            return(0);
        }
示例#4
0
        public async Task <IActionResult> CreateRole()
        {
            var model = new RoleClaimViewModel();

            var claims = await _roleRepo.GetIdentityClaimListAsync();

            var roleList = claims.GroupBy(x => x.ClaimType)
                           .Select(list => list.Select(element => new ClaimCheckboxViewModel
            {
                ID          = element.ID,
                ClaimType   = element.ClaimType,
                ClaimValue  = element.ClaimValue,
                DisplayName = element.DisplayName
            })
                                   .ToList())
                           .ToList();

            model.ClaimLists = roleList;

            return(View(model));
        }
示例#5
0
        //[Permission("Administrator")]
        public async Task <IdentityResult> RemoveClaim([FromBody] RoleClaimViewModel roleClaim)
        {
            var result = await _appRoleService.RemoveClaimAsync(roleClaim.RoleId, roleClaim.ClaimValue);

            return(result);
        }