public IEnumerable <string> GetAllClaims() { var claims = repository.GetAllClaims(); if (claims.Any()) { return(claims.Select(it => it.StatusType)); } return(null); }
public async Task <IActionResult> Rights(string Id) { var CurrentUser = await _userManager.GetUserAsync(User); var DefaultLanguageID = CurrentUser.DefaultLanguageId; var UICustomizationArray = new UICustomization(_context); ViewBag.Terms = await UICustomizationArray.UIArray(this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), DefaultLanguageID); Menus a = new Menus(_context); ViewBag.menuItems = await a.TopMenu(DefaultLanguageID); var NewClaims = new List <AddRightsToRoleViewModel>(); var AllClaimList = _claim.GetAllClaims(); var role = await _roleManager.FindByIdAsync(Id); var AssignedClaims = await _roleManager.GetClaimsAsync(role); foreach (var AllClaim in AllClaimList) { bool AlreadyHave = false; foreach (var AssignedClaim in AssignedClaims) { if (AllClaim.Claim == AssignedClaim.Value) { AlreadyHave = true; } } var NewClaim = new AddRightsToRoleViewModel { RoleID = Id , ClaimType = "Menu" , ClaimValue = AllClaim.Claim }; if (!AlreadyHave) { NewClaim.IsSelected = false; } else { NewClaim.IsSelected = true; } NewClaims.Add(NewClaim); } ViewBag.Id = Id; return(View(NewClaims)); }
public async Task <List <ClaimModel> > GetAllClaims() { try { var claims = await _claimRepository.GetAllClaims(); List <BusinessModels.UserAccessControl.ClaimModel> claimList = new List <BusinessModels.UserAccessControl.ClaimModel>(); foreach (var claim in claims) { claimList.Add(ModelConverterService.ConvertTo(claim, new BusinessModels.UserAccessControl.ClaimModel())); } return(claimList); } catch (SqlCustomException e) { throw new SqlCustomException("No Claims Found.", e.InnerException); } }
public async Task <Result <bool> > CreateClaimsPrincipal(ClaimsPrincipal claimsPrincipal) { var scopes = claimsPrincipal.Scopes; var claims = claimsPrincipal.Claims; scopes.ForEach(async x => await _userScopeRepository.CreateScope(new DALUserScopeModel { Type = x.Type, UserAccountId = claimsPrincipal.UserAccountId })); claims.ForEach(async x => await _userClaimRepository.CreateUserClaim(new DALUserClaimModel() { Type = x.Type, Value = x.Value, UserAccountId = claimsPrincipal.UserAccountId })); var allDalScopes = await _scopeRepository.GetAllScopes(); var allDalClaims = await _claimRepository.GetAllClaims(); var dalScopes = new List <ScopeModel>(); foreach (var dalScope in allDalScopes) { foreach (var scope in scopes) { if (dalScope.Type.ToUpper() == scope.Type.ToUpper()) { dalScopes.Add(dalScope); } } } var dalClaims = new List <ClaimModel>(); foreach (var dalClaim in allDalClaims) { foreach (var claim in claims) { if (dalClaim.Type.ToUpper() == claim.Type.ToUpper()) { dalClaims.Add(dalClaim); } } } var dalUserScopes = await _userScopeRepository.GetAllUserScopesByUserAccountId(claimsPrincipal.UserAccountId); var dalUserClaims = await _userClaimRepository.GetAllUserClaimsByUserAccountId(claimsPrincipal.UserAccountId); var allBlScopes = await _scopeService.GetAllScopes(); var allBlClaims = await _claimService.GetAllClaims(); var blScopes = new List <BusinessModels.UserAccessControl.ScopeModel>(); foreach (var blScope in allBlScopes) { foreach (var dalScope in dalUserScopes) { if (blScope.Type.ToUpper() == dalScope.Type.ToUpper()) { blScopes.Add(blScope); } } } var blClaims = new List <BusinessModels.UserAccessControl.ClaimModel>(); foreach (var blClaim in allBlClaims) { foreach (var dalClaim in dalClaims) { if (blClaim.Type.ToUpper() == dalClaim.Type.ToUpper()) { blClaims.Add(blClaim); } } } foreach (var dalUserScope in dalUserScopes) { var requiredClaims = blScopes.Where(x => x.Type == dalUserScope.Type).FirstOrDefault().Claims; var requiredDALClaims = dalUserClaims.Where(x => x.Type == (requiredClaims.Where(y => y.Type == x.Type).FirstOrDefault().Type)).ToList(); foreach (var dalUserClaim in dalUserClaims) { foreach (var requiredClaim in requiredClaims) { if (requiredClaim.Type.ToUpper() == dalUserClaim.Type.ToUpper()) { requiredDALClaims.Add(dalUserClaim); } } } requiredDALClaims.ForEach(async x => await _userScopeClaimRepository.CreateUserScopeClaim(new UserScopeClaimModel { UserAccountId = claimsPrincipal.UserAccountId, UserScopeId = dalUserScope.Id, UserClaimId = x.Id, Role = claimsPrincipal.Role })); } return(Result <bool> .Success(true)); }