Esempio n. 1
0
        public void CreateOrder(OrderDetailDTO order)
        {
            Order orderToCreate = new Order()
            {
                CustomerId = order.CustomerId,
                StoreId    = order.StoreId,
                OrderDate  = DateTime.Now,
                Subtotal   = order.Subtotal
            };

            _context.Add(orderToCreate);
            _context.SaveChanges();

            Order justCreated        = _context.Orders.OrderBy(x => x.OrderId).Last();
            var   deetsOfJustCreated = _context.OrderDetails.OrderBy(x => x.OrderId).Last();

            List <OrderDetail> listOfDeets = new List <OrderDetail>();

            foreach (var item in order.Products)
            {
                var moreInfo = new OrderDetail
                {
                    OrderId   = justCreated.OrderId,
                    ProductId = item.ProductId,
                    Quantity  = item.Quantity
                };
                listOfDeets.Add(moreInfo);
            }

            foreach (var deet in listOfDeets)
            {
                _context.Add(deet);
                _context.SaveChanges();
            }
        }
Esempio n. 2
0
 static void locationHelper(Project1Context context)
 {
     context.StoreLocations.AddRange(
         new StoreLocation
     {
         Location = "Houston"
     },
         new StoreLocation
     {
         Location = "Dallas"
     },
         new StoreLocation
     {
         Location = "Austin"
     },
         new StoreLocation
     {
         Location = "San Antonio"
     },
         new StoreLocation
     {
         Location = "Midland"
     }
         );
     context.SaveChanges();
 }
Esempio n. 3
0
 static void storeInventoryHelper(Project1Context context)
 {
     context.StoreItemInventories.AddRange(
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     },
         new StoreItemInventory
     {
         itemInventory = 10
     }
         );
     context.SaveChanges();
 }
Esempio n. 4
0
 static void storeItemHelper(Project1Context context)
 {
     context.StoreItems.AddRange(
         new StoreItem
     {
         itemName           = "German Shepherd",
         itemPrice          = 600,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 1),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 1)
     },
         new StoreItem
     {
         itemName           = "Siberian Husky",
         itemPrice          = 700,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 1),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 2)
     },
         new StoreItem
     {
         itemName           = "Border Collie",
         itemPrice          = 850,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 1),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 3)
     },
         new StoreItem
     {
         itemName           = "Siamese Cat",
         itemPrice          = 10000,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 2),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 4)
     },
         new StoreItem
     {
         itemName           = "Persian Cat",
         itemPrice          = 1200,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 2),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 5)
     },
         new StoreItem
     {
         itemName           = "Himalayan Cat",
         itemPrice          = 1250,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 2),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 6)
     },
         new StoreItem
     {
         itemName           = "Peach Cream Gecko",
         itemPrice          = 300,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 3),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 7)
     },
         new StoreItem
     {
         itemName           = "Spotted Viper",
         itemPrice          = 750,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 3),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 8)
     },
         new StoreItem
     {
         itemName           = "Red Tarantula",
         itemPrice          = 150,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 3),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 9)
     },
         new StoreItem
     {
         itemName           = "Zebra Angel Fish",
         itemPrice          = 40,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 4),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 10)
     },
         new StoreItem
     {
         itemName           = "Elephant Nose Fish",
         itemPrice          = 30,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 4),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 11)
     },
         new StoreItem
     {
         itemName           = "Royal Purple Discus",
         itemPrice          = 120,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 4),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 12)
     },
         new StoreItem
     {
         itemName           = "Colombian Boa",
         itemPrice          = 275,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 5),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 13)
     },
         new StoreItem
     {
         itemName           = "King Snake",
         itemPrice          = 175,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 5),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 14)
     },
         new StoreItem
     {
         itemName           = "Blood Pythond",
         itemPrice          = 500,
         StoreLocation      = context.StoreLocations.First(x => x.StoreLocationId == 5),
         StoreItemInventory = context.StoreItemInventories
                              .First(x => x.StoreItemInventoryId == 15)
     }
         );
     context.SaveChanges();
 }