Exemplo n.º 1
0
        public IActionResult Create([FromBody] FoodOrder foodOrder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            string   userJWTId = User.FindFirst("id")?.Value;
            Customer customer  = dbFoodOrder.GetCustomer(userJWTId);

            if (customer != null)
            {
                foodOrder.CustomerId = customer.Id;
            }
            //foodOrder.Customer = dbCustomer.GetEntity(foodOrder.CustomerId);
            Cart cart = dbFoodOrder.GetCart(foodOrder);

            foodOrder.AddressId    = cart.AddressId;
            foodOrder.DeliveryDate = cart.DeliveryDate;
            foodOrder.TotalCost    = ml.GetTotalCost(foodOrder);
            dbFoodOrder.Create(foodOrder);
            dbFoodOrder.Save();
            foodOrder.Customer = null;
            return(Ok(foodOrder));
        }