private void SaveCartSession(ClientCartResponse response) { var shoppingCart = new ShoppingCart { Cart = response.Cart, CartPromoCode = response.PromoCode }; Session[cartSession] = shoppingCart; }
// GET: Cart public ActionResult Index() { var shoppingCart = (ShoppingCart)Session[cartSession] ?? new ShoppingCart(); var cart = new ClientCartResponse() { Cart = shoppingCart.Cart }; if (cart.Cart != null) { cart.TotalPrice = cart.Cart.Sum(m => m.Product.Price * (100 - m.Product.Discount.DiscountValue) / 100 * m.Quantity); } return(View(cart)); }
public async Task <ActionResult> CheckoutConfirmed(ClientCartResponse order, string user = null) { if (ModelState.IsValid) { var shoppingCart = (ShoppingCart)Session[cartSession]; var orderToAdd = order.OrderInfo; if (await _clientOrderService.PlaceOrder(shoppingCart, orderToAdd, user) > 0) { Session.Remove(cartSession); return(RedirectToAction("OrderComplete")); } } return(RedirectToAction("Checkout")); }
public async Task <ClientCartResponse> AddCodeToCart(List <CartItem> carts, string code) { var temp = await _discountRepository.GetDiscountByPromoCode(code); var cartPrice = carts.Sum(m => m.Product.Price * (100 - m.Product.Discount.DiscountValue) / 100 * m.Quantity); var response = new ClientCartResponse { Cart = carts, TotalPrice = cartPrice }; if (temp != null) { response.PromoCode = temp.DiscountCode; response.TotalPrice = cartPrice; response.CodePriceBonus = cartPrice * (100 - temp.DiscountValue) / 100; return(response); } return(response); }