Ejemplo n.º 1
0
        public async Task <IActionResult> CreateNewOrder()
        {
            try
            {
                using var reader = new StreamReader(Request.Body, Encoding.UTF8);

                var requestBodyAsJsonString = await reader.ReadToEndAsync();

                if (string.IsNullOrWhiteSpace(requestBodyAsJsonString))
                {
                    throw new ArgumentException("No request body was given to AddPizza");
                }

                var pizzaOrder = JsonConvert.DeserializeObject <PizzaOrder>(requestBodyAsJsonString);

                _ordersService.CreateNewOrder(pizzaOrder);

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError($"An error occurred in CreateNewOrder: {ex.Message}");
                return(BadRequest());
            }
        }
Ejemplo n.º 2
0
        public ActionResult CompleteCheckout(string extraDetails, string deliveryAddress)
        {
            OrderDto finalOrder = new OrderDto();

            finalOrder           = sessionStorage.GetCurrentOrder().CompileOrder();
            finalOrder.Message   = extraDetails;
            finalOrder.AddressID = int.Parse(deliveryAddress);

            bool   canComplete = true;
            string errorDish   = "";

            finalOrder.DishesIDs.ForEach(x =>
            {
                var dish = dishService.GetDishByID(x);
                if (!dish.IsActive)
                {
                    canComplete = false;
                    errorDish   = dish.Name;
                }
            });
            if (!canComplete)
            {
                sessionStorage.ResetOrder(CurrentUser.Id);
                return(RedirectToAction("Index", new { errorMessage = $"{errorDish} is not available anymore, your order cannot be completed." }));
            }

            var id = ordersService.CreateNewOrder(finalOrder);

            //queueService.PushOrder(id);
            new Thread(WaitThread).Start(id);
            sessionStorage.ResetOrder(CurrentUser.Id);

            return(RedirectToAction("Index", new { completedPurchase = true, oldId = id }));
        }