Ejemplo n.º 1
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if (cart.LinesCollection.Count() == 0)
     {
         ModelState.AddModelError("", "Sorry, your cart is empty!");
     }
     if (ModelState.IsValid)
     {
         _customerManager = new UserManager <Customer>(new UserStore <Customer>(_context));
         Customer currentCustomer = _customerManager.FindByName(HttpContext.User.Identity.Name);
         //_orderProcessor.ProcessOrder(cart, shippingDetails);
         cart.CustomerId = currentCustomer.Id;
         _cartRepository.AddCart(cart);
         foreach (var line in cart.LinesCollection)
         {
             line.CartId = cart.CartId;
             _cartLineRepository.CreateLine(line);
         }
         cart.LinesCollection.ToList().ForEach(c => _context.Entry(c).State = System.Data.Entity.EntityState.Deleted);
         cart.Clear();
         return(View("Completed"));
     }
     else
     {
         return(View(shippingDetails));
     }
 }