public async Task <IActionResult> Create(IEnumerable <CartProduct> cartProducts) { var cartProductIds = from cp in cartProducts where cp != null select cp.Id; if (cartProductIds.Count() == 0) { return(RedirectToAction("Index", "Cart")); } cartProducts = await _cartService.GetCartItems(cartProductIds); // user view his cart items, and then admin close the activity // (all the the products of this activity in user's cart will be removed) // user create an order with removed item(s). if (cartProductIds.Count() > cartProducts.Count()) { ViewBag.CountOfMissedCartItems = cartProductIds.Count() - cartProducts.Count(); return(View("CartItemsMissed")); } var invalidCartItems = cartProducts.Where(cp => cp.ActivityProduct.Activity.Status == ActivityState.Closed || cp.ActivityProduct.Activity.EndTime < DateTime.Now).ToList(); if (invalidCartItems.Count() > 0) { return(View("CartItemsInvalid", invalidCartItems)); } var pointsNeeded = cartProducts.Sum(cp => cp.Quantity * cp.ActivityProduct.PointsPayment); var pointsBalance = await _pointsService.CalculatePointsBalance(Guid.Parse(User.GetUserId())); if (pointsNeeded > pointsBalance) { return(View("NoEnoughPoints")); } // create order var order = await _orderService.Create(cartProducts, Guid.Parse(User.GetUserId())); return(RedirectToAction("Index")); }