public CustomerRepoStub()
        {
            orderlineModel = new Orderline()
            {
                Count = 1,
                OrderId = 1,
                OrderlineId = 1,
                ProductId = 1,
                ProductName = "Tank",
                ProductPrice = 500000
            };

            orderlineModels = new List<Orderline>();
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);
            orderlineModels.Add(orderlineModel);

            orderModel = new Order()
            {
                CustomerId = 1,
                Date = new DateTime(2015, 1, 1),
                OrderId = 1,
                Orderlines = orderlineModels
            };

            orderModels = new List<Order>();
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);
            orderModels.Add(orderModel);

            customerModel =  new Customer()
            {
                CustomerId = 1,
                Email = "*****@*****.**",
                Firstname = "Ole",
                Lastname = "Olsen",
                Address = "Persveien 5",
                Postal = new Postal
                {
                    Zipcode = "0123",
                    City = "Oslo"
                },
                Orders = orderModels
            };
        }
Example #2
0
        public int PlaceOrder(OrderModel order)
        {
            using (var db = new TankshopDbContext())
            {
                try
                {
                    var newOrder = new Nettbutikk.Model.Order()
                    {
                        CustomerId = order.CustomerId,
                        Date = order.Date
                    };

                    foreach (var item in order.Orderlines)
                    {
                        var product = db.Products.Find(item.ProductId);
                        var orderline = new Orderline()
                        {
                            Product = product,
                            Count = item.Count,
                            ProductId = item.ProductId
                        };

                        newOrder.Orderlines.Add(orderline);
                    }

                    db.Orders.Add(newOrder);
                    db.SaveChanges();
                    return newOrder.OrderId;
                }
                catch (Exception)
                {
                    return 0;
                }
            }
        }
 public bool UpdateOrderline(Orderline orderline)
 {
     throw new NotImplementedException();
 }
        public int PlaceOrder(Order order)
        {
            try
            {
                var newOrder = new Order()
                {
                    CustomerId = order.CustomerId,
                    Date = order.Date
                };

                foreach (var item in order.Orderlines)
                {
                    var product = db.Products.Find(item.ProductId);
                    var orderline = new Orderline()
                    {
                        Product = product,
                        Count = item.Count,
                        ProductId = item.ProductId
                    };

                    newOrder.Orderlines.Add(orderline);
                }

                db.Orders.Add(newOrder);
                db.SaveChanges();
                return newOrder.OrderId;
            }
            catch (Exception)
            {
                return 0;
            }
        }
 public bool UpdateOrderline(Orderline orderline)
 {
     return _orderrepo.UpdateOrderline(orderline);
 }