Пример #1
0
 public void Update(Order order)
 {
     context.Entry(order).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
Пример #2
0
 public void Create(Order order)
 {
     context.Orders.Add(order);
     context.SaveChanges();
 }
Пример #3
0
        public ActionResult CheckOut(BasketViewModel model)
        {
            Basket basket = _basketRepository.Get(User.Identity.Name);

            if (basket != null)
            {
                Order order = new Order
                {
                    Items = new List<OrderLine>(),
                    Status = OrderStatus.Draft,
                    UserId = basket.UserId,
                    OrderDate = DateTime.Today
                };

                foreach (BasketItem basketItem in basket.Items)
                {
                    OrderLine orderLine = new OrderLine { itemId = basketItem.ItemId, Quantity = basketItem.Quantity };
                    Item item = _itemRepository.Get(basketItem.ItemId);
                    orderLine.unitPrice = item.Price;
                    orderLine.Name = item.Name;
                    order.Items.Add(orderLine);
                }
                _orderRepository.Create(order);

                basket.Items.Clear();
                _basketRepository.Delete(basket.Id);

                return Redirect(Url.Action("Confirm", "Order", new {orderId = order.Id}));


            }
            return View(model);
        }