Ejemplo n.º 1
0
        public ActionResult Order(Cart cart, ShopOrderViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.PayoutOptions = _payRepository.GetAll().ToList();
                return View(model);
            }
            Order o = new Order();
            o.CustomerFullName = model.FullName;
            o.Email = model.Email;
            o.Phone = model.Phone;
            o.PostAddress = model.PostAddress;
            o.OrerDate = DateTime.Now;
            o.PayOutId = _payRepository.FindBy(po => po.id == model.SelectedPayOutId).SingleOrDefault().id;
            //  o.OrderStatus = _orderStatusRepository.GetAll().OrderBy(s => s.id).FirstOrDefault();
            o.OrderStatusId = _orderStatusRepository.GetAll().Min(x => x.id);
            _orderRepository.Add(o);
            if (cart.CartItems.Count > 0)
            {
                foreach (CartItem item in cart.CartItems)
                {
                    OrderProduct op = new OrderProduct();
                    op.Order = o;
                    op.ProductId = item.Product.ProductId;
                    op.Quantity = item.Quantity;
                    _orderProuctRepository.Add(op);
                }

            }
            _orderProuctRepository.Save();

            int id = o.OrderId;
            return RedirectToAction("OrderSummary", new { id = id });
        }
Ejemplo n.º 2
0
        //[HttpGet]
        //public ActionResult Buy(int? productId)
        //{
        //    if (productId.HasValue)
        //    {
        //        Product p = _productRepository.FindBy(pp => pp.ProductId == productId).SingleOrDefault();
        //        if (p != null)
        //        {
        //            BuyViewModel model = new BuyViewModel();
        //            model.Price = p.ProductPrice;
        //            model.ProductName = p.ProductName;
        //            model.PayoutOptions = _payRepository.GetAll().ToList();
        //            return View(model);
        //        }
        //        else
        //        {
        //            return HttpNotFound();
        //        }
        //    }
        //    return HttpNotFound();
        //}
        //[HttpPost]
        //public ActionResult Buy(BuyViewModel model)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        model.PayoutOptions = _payRepository.GetAll().ToList();
        //        return View(model);
        //    }
        //    Order o = new Order();
        //    o.CustomerFullName = model.FullName;
        //    o.Email = model.Email;
        //    o.Phone = model.Phone;
        //    o.PostAddress = model.PostAddress;
        //    o.OrerDate = DateTime.Now;
        //    o.PayOutId = _payRepository.FindBy(po => po.id == model.SelectedPayOutId).SingleOrDefault().id;
        //    //  o.OrderStatus = _orderStatusRepository.GetAll().OrderBy(s => s.id).FirstOrDefault();
        //    o.OrderStatusId = _orderStatusRepository.GetAll().Min(x => x.id);
        //    Product p = _productRepository.FindBy(pp => pp.ProductId == model.ProductId).SingleOrDefault();
        //    OrderProduct op = new OrderProduct();
        //    op.Order = o;
        //    op.ProductId = p.ProductId;
        //    op.Quantity = model.Quantity;
        //    _orderRepository.Add(o);
        //    _orderProuctRepository.Add(op);
        //    _orderProuctRepository.Save();
        //    int id = op.Id;
        //    return RedirectToAction("OrderSummary", new { id = id });
        //}
        public ActionResult Order(Cart cart)
        {
            if (cart.CartItems.Count != 0)
            {
                ShopOrderViewModel model = new ShopOrderViewModel();
                model.PayoutOptions = _payRepository.GetAll().ToList();

                return View(model);
            }
            else
            {
                return RedirectToAction("index", "Catalog");
            }
        }