Ejemplo n.º 1
0
        public async void LoadData()
        {
            // i implement that method because inmemorydatabase cant configure seed on onmodelcreating
            if (!Products.Any())
            {
                List <Products> P = new List <Products>()
                {
                    new Products {
                        Id             = 1,
                        Name           = "Barbie Developer",
                        AgeRestriction = 12,
                        Price          = 25.99m,
                        Company        = "Mattel",
                        Description    = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porta arcu arcu, vel varius enim ia"
                    },
                    new Products {
                        Id             = 2,
                        Name           = "xyc",
                        AgeRestriction = 4,
                        Price          = 75.50m,
                        Company        = "Marvel",
                        Description    = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porta arcu arcu, vel varius enim ia"
                    },
                    new Products {
                        Id             = 3,
                        Name           = "abc",
                        AgeRestriction = 18,
                        Price          = 99.99m,
                        Company        = "Nintendo",
                        Description    = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris porta arcu arcu, vel varius enim ia"
                    }
                };
                await Products.AddRangeAsync(P);
                await SaveChangesAsync();

                Guid           ADMIN_ID = Guid.NewGuid();
                Guid           User     = Guid.NewGuid();
                var            hasher   = new PasswordHasher <AppUser>();
                List <AppUser> Users    = new List <AppUser>()
                {
                    new AppUser
                    {
                        Id                 = ADMIN_ID,
                        UserName           = "******",
                        NormalizedUserName = "******",
                        Email              = "*****@*****.**",
                        NormalizedEmail    = "*****@*****.**",
                        EmailConfirmed     = true,
                        PasswordHash       = hasher.HashPassword(null, "unosquareAdmin2020."),
                    },
                    new AppUser
                    {
                        Id                 = User,
                        UserName           = "******",
                        NormalizedUserName = "******",
                        Email              = "*****@*****.**",
                        NormalizedEmail    = "*****@*****.**",
                        EmailConfirmed     = true,
                        PasswordHash       = hasher.HashPassword(null, "2020Client."),
                    }
                };
                List <Role> Roles = new List <Role>()
                {
                    new Role {
                        Id             = ADMIN_ID,
                        Name           = "Admin",
                        NormalizedName = "ADMIN"
                    }
                };
                List <UserRoles> userRoles = new List <UserRoles>()
                {
                    new UserRoles {
                        RoleId = ADMIN_ID,
                        UserId = ADMIN_ID
                    }
                };
                foreach (var i in Users)
                {
                    await AddAsync(i);
                    await SaveChangesAsync();
                }
                foreach (var i in Roles)
                {
                    await AddAsync(i);
                    await SaveChangesAsync();
                }
                foreach (var i in userRoles)
                {
                    await AddAsync(i);
                    await SaveChangesAsync();
                }
            }
        }