Esempio n. 1
0
        private static void SeedOnSales()
        {
            var           fileJsonPath = Path.Combine(ServiceHelper.GetHostingEnv().ContentRootPath, "DataSeeds", "onSales.json");
            var           jsonData     = File.ReadAllText(fileJsonPath);
            List <OnSale> OnSales      =
                JsonConvert.DeserializeObject <List <OnSale> >(jsonData);

            if (!context.OnSales.Any())
            {
                context.OnSales.AddRange(OnSales);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        private static void SeedOrders()
        {
            var          fileJsonPath = Path.Combine(ServiceHelper.GetHostingEnv().ContentRootPath, "DataSeeds", "orders.json");
            var          jsonData     = File.ReadAllText(fileJsonPath);
            List <Order> Orders       =
                JsonConvert.DeserializeObject <List <Order> >(jsonData);
            int i           = 0;
            var customersId = context.Customers.Select(c => c.id).ToList();

            foreach (var order in Orders)
            {
                order.customerId = customersId.ElementAt(i);
                ++i;
                if (customersId.Count - 1 < i)
                {
                    i = 0;
                }
            }
            if (!context.Orders.Any())
            {
                context.Orders.AddRange(Orders);
                context.SaveChanges();
            }
        }
Esempio n. 3
0
        private static async Task SeedCustomers()
        {
            if (context.Customers.Any())
            {
                return;
            }
            var fileJsonPath = Path.Combine(ServiceHelper.GetHostingEnv().ContentRootPath, "DataSeeds", "customers.json");
            var jsonData     = File.ReadAllText(fileJsonPath);
            var customers    = JsonConvert.DeserializeObject <List <customerType> >(jsonData);
            var isConfimed   = false;

            foreach (var customer in customers)
            {
                isConfimed = !isConfimed;
                var newUser = new ApplicationUser {
                    Email    = customer.email,
                    UserName = customer.email,
                    //SecurityStamp=Guid.NewGuid().ToString(),
                    EmailConfirmed = isConfimed
                };
                await _userManager.CreateAsync(newUser);

                await _userManager.AddPasswordAsync(newUser, "Customer@123");

                await _userManager.AddToRoleAsync(newUser, GlobalVariables.CustomerRole);

                var newCustomer = new Customer {
                    id       = newUser.Id,
                    fullName = customer.fullName,
                    imgSrc   = "/images/Users",
                    User     = newUser
                };
                context.Customers.Add(newCustomer);
            }
            context.SaveChanges();
        }