Example #1
0
        public IActionResult CreateOrderedFood([FromBody] OrderedFoodForCreationDto orderedFoodForCreationDto)
        {
            var orderError = "Please ensure your entered data is correct";

            OrderedFood orderedFood = new OrderedFood();

            if (orderedFoodForCreationDto == null)
            {
                return(BadRequest(orderError));
            }


            orderedFood.FoodId        = orderedFoodForCreationDto.FoodId;
            orderedFood.OrderId       = orderedFoodForCreationDto.OrderId;
            orderedFood.CreatedAtDate = DateTime.Now;

            if (orderedFood.CreatedAtDate == null)
            {
                return(StatusCode(500, "The date is invalid"));
            }
            orderedFood.UpdatedAtDate = orderedFood.CreatedAtDate;

            _orderedFoodRepository.AddOrderedFood(orderedFood);

            if (!_orderedFoodRepository.Save())
            {
                return(StatusCode(500, "A problem happened while handling your request."));
            }

            return(Ok(orderedFood));
        }