public Order Add(Order entity)
        {
            if (entity.Date == null)
            {
                entity.Date = DateTime.Now;
            }

            var newOrder = db.Orders.Add(entity).Entity;

            db.SaveChanges();
            return(newOrder);
        }
Exemplo n.º 2
0
        Order IRepository <Order> .Add(Order entity)
        {
            if (entity.Date == null)
            {
                entity.Date = DateTime.Now;
            }

            var newOrder = db.Orders.Add(entity).Entity;

            db.SaveChanges();
            return(newOrder);
        }
Exemplo n.º 3
0
        // 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();
        }
Exemplo n.º 4
0
        // 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();
        }
Exemplo n.º 5
0
        // 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();
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        // 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();
        }
Exemplo n.º 8
0
        // 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();
        }
Exemplo n.º 9
0
        // 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();
        }