// This method will create and seed the database. public void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Products if (context.Orders.Any()) { return; // DB has been seeded } Order order = new Order() { Id = 1, CustomerId = 1, Date = DateTime.Today, OrderLines = new List <OrderLine> { new OrderLine() { ProductId = 1, Quantity = 2 }, new OrderLine() { ProductId = 2, Quantity = 3 } } }; context.Orders.Add(order); context.SaveChanges(); }
// This method will create and seed the database. public void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Orders if (context.Orders.Any()) { return; // DB has been seeded } List <Order> orders = new List <Order> { new Order { Date = DateTime.Today, OrderLines = new List <OrderLine> { new OrderLine { ProductId = 1, Quantity = 2 } } } }; context.Orders.AddRange(orders); context.SaveChanges(); }
// This method will create and seed the database. public static void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Products if (context.Orders.Any()) { return; // DB has been seeded } List <Order> orders = new List <Order> { new Order { Date = DateTime.Today, ProductId = 1, Quantity = 2, CustomerRegNo = 1, Status = OrderStatusEnum.Completed } }; context.Orders.AddRange(orders); context.SaveChanges(); }
public void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); if (context.Orders.Any()) { return; } List <Order> orders = new List <Order> { new Order { Date = DateTime.Today, ProductId = 1, Quantity = 2 } }; context.Orders.AddRange(orders); context.SaveChanges(); }
// This method will create and seed the database. public static void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Products if (context.Orders.Any()) { return; // DB has been seeded } List <Order> orders = new List <Order> { new Order { Date = DateTime.Today, Items = CreateMockData(), CustomerId = 1 } }; context.Orders.AddRange(orders); context.SaveChanges(); }
// This method will create and seed the database. public static void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Products if (context.Orders.Any()) { return; // DB has been seeded } List <Order> orders = new List <Order> { new Order { Date = DateTime.Today, ProductId = 1, Quantity = 2, CustomerRN = 1, IsShipped = false }, new Order { Date = DateTime.Today, ProductId = 2, Quantity = 2, CustomerRN = 2, IsShipped = true } }; context.Orders.AddRange(orders); context.SaveChanges(); }
public OrderRepository(OrderApiContext context) { db = context; }
// This method will create and seed the database. public static void Initialize(OrderApiContext context) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Look for any Products if (context.Orders.Any()) { return; // DB has been seeded } List <Product> products = new List <Product> { new Product { Id = 1, Name = "Shoe", Price = 999, Quantity = 3 }, new Product { Id = 2, Name = "T-Shirt", Price = 50, Quantity = 2 } }; List <Order> orders = new List <Order> { new Order { Id = 1, Date = DateTime.Today, CustomerRegNo = 1, OrderStatus = OrderStatuss.Requested, ShippingCharge = 999, Items = products }, new Order { Id = 2, Date = DateTime.Today, CustomerRegNo = 1, OrderStatus = OrderStatuss.Paid, ShippingCharge = 999, Items = products }, new Order { Id = 3, Date = DateTime.Today, CustomerRegNo = 1, OrderStatus = OrderStatuss.Paid, ShippingCharge = 999, Items = products } }; context.Orders.AddRange(orders); context.SaveChanges(); }