コード例 #1
0
        public static async Task SeedOwner(UserManager <ApplicationUser> userManager)
        {
            var ownerRoleString        = Role.Owner.ToDescription();
            var ownerFirstClaimString  = Claim.CreateNewSoccerField.ToDescription();
            var ownerSecondClaimString = Claim.Bookfield.ToDescription();

            foreach (var owner in DataValues.OwnerData())
            {
                if (await userManager.FindByNameAsync(owner.UserName) == null)
                {
                    await userManager.CreateAsync(owner, DataValues.default_user_password);

                    if (!await userManager.IsInRoleAsync(owner, ownerRoleString))
                    {
                        await userManager.AddToRoleAsync(owner, ownerRoleString);
                    }

                    var ownerClaim = await userManager.GetClaimsAsync(owner);

                    if (!ownerClaim.Any(x => x.Type == ownerFirstClaimString))
                    {
                        await userManager.AddClaimAsync(owner, new System.Security.Claims.Claim(ownerFirstClaimString, true.ToString()));
                    }
                    if (!ownerClaim.Any(x => x.Type == ownerSecondClaimString))
                    {
                        await userManager.AddClaimAsync(owner, new System.Security.Claims.Claim(ownerSecondClaimString, true.ToString()));
                    }
                }
            }
        }
コード例 #2
0
        public static async Task SeedAdmin(UserManager <ApplicationUser> userManager)
        {
            var adminRoleString  = Role.Admin.ToDescription();
            var adminClaimString = Claim.CreateNewGrSoccerField.ToDescription();

            foreach (var admin in DataValues.AdminData())
            {
                if (await userManager.FindByNameAsync(admin.UserName) == null)
                {
                    await userManager.CreateAsync(admin, DataValues.default_admin_password);

                    var adminClaim = await userManager.GetClaimsAsync(admin);

                    if (!await userManager.IsInRoleAsync(admin, adminRoleString))
                    {
                        await userManager.AddToRoleAsync(admin, adminRoleString);
                    }

                    if (!adminClaim.Any(x => x.Type == adminClaimString))
                    {
                        await userManager.AddClaimAsync(admin, new System.Security.Claims.Claim(adminClaimString, true.ToString()));
                    }
                }
            }
        }
コード例 #3
0
        public static async Task SeedStaff(UserManager <ApplicationUser> userManager)
        {
            var staffRoleString  = Role.Staff.ToDescription();
            var staffClaimString = Claim.Bookfield.ToDescription();

            foreach (var staff in DataValues.StaffData())
            {
                if (await userManager.FindByNameAsync(staff.UserName) == null)
                {
                    await userManager.CreateAsync(staff, DataValues.default_user_password);

                    var staffClaim = await userManager.GetClaimsAsync(staff);

                    if (!await userManager.IsInRoleAsync(staff, staffRoleString))
                    {
                        await userManager.AddToRoleAsync(staff, staffRoleString);
                    }

                    if (!staffClaim.Any(x => x.Type == staffClaimString))
                    {
                        await userManager.AddClaimAsync(staff, new System.Security.Claims.Claim(staffClaimString, true.ToString()));
                    }
                }
            }
        }