public IActionResult MakeOrder(string returnUrl)
        {
            if (!(_cart.Lines.Count() == 0))
            {
                Order order = new Order()
                {
                    CustomerID   = Guid.Parse(_userManager.GetUserId(User)),
                    OrderDate    = DateTime.Now,
                    ShipmentDate = null,
                    OrderNumber  = _unitOfWork.Orders.GetAllItems().Count() + 1,
                    StatusID     = (int)Statuses.New,
                    Products     = new List <OrderProduct>()
                };

                foreach (var line in _cart.Lines)
                {
                    order.Products.Add(new OrderProduct()
                    {
                        ID           = Guid.NewGuid(),
                        OrderID      = order.ID,
                        ProductID    = line.Product.ID,
                        ProductCount = _cart.Lines.Sum(p => p.Quantity)
                    });
                }

                _unitOfWork.Orders.AddItem(order);
                _unitOfWork.SaveChanges();
                _cart.Clear();
            }

            return(Redirect(returnUrl ?? "/"));
        }
Пример #2
0
 public IActionResult CreateOrder()
 {
     if (User.Identity.IsAuthenticated)
     {
         if (!(_cart.Lines.Count() == 0))
         {
             var info = new OrderInfo(
                 Guid.Parse(_userManager.GetUserId(User)),
                 _unit.GetRepo <Order>().Get().Count() + 1,
                 _cart);
             change = new CreateOrder(info);
             change.Change();
             _unit.GetRepo <Order>().Create(change.GetT());
             _unit.SaveChanges();
             _cart.Clear();
         }
         return(RedirectToAction("Index", "Shop"));
     }
     else
     {
         return(RedirectToAction("Login", "Account"));
     }
 }