Beispiel #1
0
        public async Task <IActionResult> CheckoutCart()
        {
            /// <summary>
            /// Adds cart items to orderitems db then empties cart
            /// </summary>
            List <OrderItemViewModel> CurrentCart = (List <OrderItemViewModel>)_cache.Get("customerCart");

            foreach (OrderItemViewModel thisOIVM in CurrentCart)
            {
                //OrderItem(int CustomerIdIn, int LocationIdIn, int ProductIdIn, double TotalPriceWhenOrderedIn, int OrderCountIn)
                OrderItem thisOrderItem = new OrderItem(
                    thisOIVM.CustomerId,
                    thisOIVM.LocationId,
                    thisOIVM.ProductId,
                    thisOIVM.TotalPriceWhenOrdered,
                    thisOIVM.OrderCount
                    );
                _context.Add(thisOrderItem);
                _context = UtilMethods.DecrementStockItem(thisOrderItem, _context);
            }
            await _context.SaveChangesAsync();

            System.Diagnostics.Debug.WriteLine($"Orders updated");
            _cache.Set("customerCart", new List <OrderItemViewModel>());
            return(Redirect("/Home/History"));
        }