Example #1
0
        public static async void AddQuantityOfProducts(WebshopAppContext context)
        {
            var products = context.Products.ToList();

            foreach (var product in products)
            {
                product.Quantity = new Random().Next(10, 50);
            }

            await context.SaveChangesAsync();
        }
Example #2
0
        public static async void SeedRoles(WebshopAppContext context)
        {
            var roleStore = new RoleStore <IdentityRole>(context);

            if (!context.Roles.Any(r => r.Name == "Admin"))
            {
                await roleStore.CreateAsync(new IdentityRole { Name = "Admin", NormalizedName = "ADMIN" });
            }

            if (!context.Roles.Any(r => r.Name == "User"))
            {
                await roleStore.CreateAsync(new IdentityRole { Name = "User", NormalizedName = "USER" });
            }

            //var adminUser = context.Users.FirstOrDefault(x => x.UserName == "*****@*****.**") ?? new WebshopAppUser
            //{
            //    UserName = "******",
            //    NormalizedUserName = "******",
            //    Email = "*****@*****.**",
            //    NormalizedEmail = "*****@*****.**",
            //    EmailConfirmed = true,
            //    LockoutEnabled = false,
            //    SecurityStamp = Guid.NewGuid().ToString()
            //};

            //if (!context.Users.Any(u => u.UserName == adminUser.UserName))
            //{
            //    var password = new PasswordHasher<WebshopAppUser>();
            //    var hashed = password.HashPassword(adminUser, "kamenica");
            //    adminUser.PasswordHash = hashed;
            //    var userStore = new UserStore<WebshopAppUser>(context);
            //    await userStore.CreateAsync(adminUser);
            //    await userStore.AddToRoleAsync(adminUser, "admin");
            //}

            await context.SaveChangesAsync();
        }