Ejemplo n.º 1
0
        public static async Task SeedRepairPerson(TmanagerServiceContext dbContext, UserManager <ApplicationUser> userManager)
        {
            var repairPersonRoleString  = RoleValues.RepairPerson.ToDescription();
            var repairPersonClaimString = Claim.ReceiveRequest.ToDescription();

            foreach (var user in await DataValues.RepairPersonDataAsync(dbContext, userManager))
            {
                if (await userManager.FindByNameAsync(user.UserName) == null)
                {
                    await userManager.CreateAsync(user, DataValues.default_user_password);

                    var userClaim = await userManager.GetClaimsAsync(user);

                    if (!await userManager.IsInRoleAsync(user, repairPersonRoleString))
                    {
                        await userManager.AddToRoleAsync(user, repairPersonRoleString);
                    }

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