public async Task <ActionResult> Cart() { ShoppingCartVM cart; cart = HttpContext.Session.GetObject <ShoppingCartVM>(KEY_SHOPPINGCART); if (cart == null) { cart = new ShoppingCartVM { Cart = new List <CartVM>() }; HttpContext.Session.SetObject(KEY_SHOPPINGCART, cart); } if (TempData["CartError"] != null) { ModelState.AddModelError("Cart", TempData["CartError"].ToString()); TempData["CartError"] = null; } cart.TotalPrice = 0.0; foreach (var item in cart.Cart) { if (item.MatchTicket.HasValue) { var msl = await _mslService.GetById(item.MatchTicket.Value); if (item.Count > msl.RemainingSeats) { item.Count = msl.RemainingSeats; ModelState.AddModelError("Cart", "Niet genoeg beschikbare plaatsen voor 1 van de wedstrijden. Aantal werd aangepast."); } cart.TotalPrice += msl.Price * item.Count; } else if (item.TeamSubscription.HasValue) { var tcl = await _tclService.GetById(item.TeamSubscription.Value); cart.TotalPrice += tcl.Price; } } HttpContext.Session.SetObject(KEY_SHOPPINGCART, cart); return(View(cart)); }
public async Task <IViewComponentResult> InvokeAsync(CartVM cartItem) { var msl = await _mslService.GetById(cartItem.MatchTicket.Value); MSLVM mslVM = _mapper.Map <MSLVM>(msl); return(View(new CartTicketInfoVM { MSLVM = mslVM, Count = cartItem.Count })); }