Example #1
0
        private static async Task <bool> UpdateClaims(ApplicationUser user, UserManager <ApplicationUser> userManager, System.Collections.Generic.IList <Claim> claims, string type, string value)
        {
            var shouldUpdate = false;

            if (claims.Any(x => x.Type == type && x.Value != value) ||
                !claims.Any(x => x.Type == type))
            {
                await userManager.RemoveClaimsAsync(user, claims.Where(x => x.Type == type));

                await userManager.AddClaimAsync(user, new Claim(type, value));

                shouldUpdate = true;
            }

            return(shouldUpdate);
        }
Example #2
0
        public static async Task CreateUserRoles(IApplicationBuilder app)
        {
            using (IServiceScope scope = app.ApplicationServices.CreateScope())
            {
                RoleManager <IdentityRole>    RoleManager = scope.ServiceProvider.GetRequiredService <RoleManager <IdentityRole> >();
                UserManager <ApplicationUser> UserManager = scope.ServiceProvider.GetRequiredService <UserManager <ApplicationUser> >();
                //var JobsRepo = scope.ServiceProvider.GetRequiredService<IJobPostingRepository>();
                //await JobsRepo.BuildCache();
                ApplicationDbContext content = scope.ServiceProvider.GetRequiredService <ApplicationDbContext>();

                IdentityResult roleResult;

                //Adding Admin Role
                bool roleCheck = await RoleManager.RoleExistsAsync("Admin");

                if (!roleCheck)
                {
                    //create the roles and seed them to the database
                    roleResult = await RoleManager.CreateAsync(new IdentityRole("Admin"));
                }

                //Assign Admin role to the main User here we have given our newly registered
                //login id for Admin management
                // Also Assigning them Claims to perform CUD operations
                ApplicationUser user = await UserManager.FindByEmailAsync("*****@*****.**");

                if (user != null)
                {
                    System.Collections.Generic.IList <string> currentUserRoles = await UserManager.GetRolesAsync(user);

                    if (!currentUserRoles.Contains("Admin"))
                    {
                        await UserManager.AddToRoleAsync(user, "Admin");
                    }

                    System.Collections.Generic.IList <Claim> currentClaims = await UserManager.GetClaimsAsync(user);

                    if (!currentClaims.Any())
                    {
                        Claim CanCreatePostingClaim = new Claim("CanCreatePosting", "True");
                        await UserManager.AddClaimAsync(user, CanCreatePostingClaim);

                        Claim CanEditPostingClaim = new Claim("CanEditPosting", "True");
                        await UserManager.AddClaimAsync(user, CanEditPostingClaim);

                        Claim CanDeletePostingClaim = new Claim("CanDeletePosting", "True");
                        await UserManager.AddClaimAsync(user, CanDeletePostingClaim);
                    }
                }
            }
        }
Example #3
0
 public System.Collections.Generic.IList <StrObjectDict> filterSource(System.Collections.Generic.IList <StrObjectDict> source, string expression)
 {
     System.Collections.Generic.IList <StrObjectDict> filterData = this.getDataPermissble();
     string[] exps = expression.Split("|".ToCharArray(), System.StringSplitOptions.RemoveEmptyEntries);
     return((
                from item in source
                where filterData.Any(delegate(StrObjectDict item2)
     {
         bool result = false;
         //string[] expss = exps;
         for (int i = 0; i < exps.Length; i++)
         {
             string key = exps[i];
             if (Utils.GetString(item2["XXMXID"]) == Utils.GetString(item[key]))
             {
                 result = true;
                 break;
             }
         }
         return result;
     })
                select item).ToList <StrObjectDict>());
 }