Exemplo n.º 1
0
        public ActionResult PlaceOrder(OrderIndexVM orderIndexVM)
        {
            string drinkOrderString = JsonConvert.SerializeObject(orderIndexVM.DrinkOrders);

            TempData["DrinkOrders"]    = drinkOrderString;
            orderIndexVM.ErrorMessages = new List <string>();
            foreach (var drinkOrder in orderIndexVM.DrinkOrders)
            {
                if (drinkOrder.Quantity > 0)
                {
                    var inventory = _inventoryBL.GetInventoryByLocationIDAndDrinkID(orderIndexVM.LocationID, drinkOrder.DrinkId);
                    if (inventory.Quantity < drinkOrder.Quantity)
                    {
                        orderIndexVM.ErrorMessages.Add($"Not enough {drinkOrder.DrinkName} \r\n ");
                        orderIndexVM.ErrorMessages.Add($"We currently have {inventory.Quantity} in stock at this location \r\n");
                    }
                }
            }
            if (orderIndexVM.ErrorMessages != null && orderIndexVM.ErrorMessages.Any())
            {
                return(RedirectToAction("Index", "Order", orderIndexVM));
            }


            return(RedirectToAction("ConfirmOrder", "Order", orderIndexVM));
        }