Пример #1
0
        private static void GenerateDbData(SalesContext context)
        {
            var product = new Product
            {
                Name     = "Samsung",
                Price    = 323.5M,
                Quantity = 10
            };

            context.Add(product);

            var customer = new Customer
            {
                CreditCardNumber = "54546546546",
                Email            = "*****@*****.**",
                Name             = "Ivan Ivanov"
            };

            context.Add(customer);

            var store = new Store
            {
                Name = "TP Burgas"
            };

            context.Add(store);
            context.SaveChanges();

            var sale = new Sale
            {
                CustomerId = customer.CustomerId,
                ProductId  = product.ProductId,
                StoreId    = store.StoreId
            };

            context.Add(sale);
            context.SaveChanges();
        }
Пример #2
0
        private static void Seed(SalesContext db)
        {
            Customer customer = new Customer
            {
                Name             = "Gosho",
                Email            = "*****@*****.**",
                CreditCardNumber = "123",
            };


            Customer customer2 = new Customer
            {
                Name             = "Ivan",
                Email            = "*****@*****.**",
                CreditCardNumber = "567",
            };

            db.Add(customer2);

            db.Add(customer);



            Sale sale = new Sale
            {
                Date       = DateTime.Now,
                ProductId  = 1,
                CustomerId = 1,
                StoreId    = 2,
            };

            db.AddRange(sale);



            Sale sale2 = new Sale
            {
                Date       = DateTime.Now,
                ProductId  = 2,
                CustomerId = 2,
                StoreId    = 1,
            };

            db.Add(sale2);

            Sale sale3 = new Sale
            {
                Date       = DateTime.Now,
                ProductId  = 1,
                CustomerId = 1,
                StoreId    = 2,
            };

            db.Add(sale3);

            Product product = new Product
            {
                Name        = "Sirene",
                Quantity    = 15,
                Price       = 120,
                Description = "Unikalno",
            };

            product.Sales.Add(sale);
            product.Sales.Add(sale2);



            Product product2 = new Product
            {
                Name        = "Salam",
                Quantity    = 5,
                Price       = 13,
                Description = "Vkusno",
            };

            product2.Sales.Add(sale);
            product2.Sales.Add(sale2);

            db.Add(product2);

            Store store = new Store
            {
                Name = "Metro"
            };

            store.Sales.Add(sale3);



            db.Add(store);
            db.SaveChanges();
        }