예제 #1
0
        public IActionResult CreateRestaurant([FromBody] RestaurantForCreationDto restaurantInfo)
        {
            var        restaurantError = "Please look at the data and make sure it's not empty, incorrect, or has values that are the same!";
            Restaurant restaurant      = new Restaurant();

            if (restaurantInfo == null)
            {
                return(BadRequest(restaurantError));
            }


            restaurant.Name = restaurantInfo.Name;
            if (restaurantInfo.Name == null || restaurantInfo.Name.Length > 50)
            {
                return(StatusCode(500, "The name is either null or too long"));
            }


            restaurant.Adress = restaurantInfo.Adress;
            if (restaurantInfo.Adress == null || restaurantInfo.Adress.Length > 50)
            {
                return(StatusCode(500, "The adress is null or too long"));
            }



            restaurant.foods = restaurantInfo.foods;

            restaurant.CreatedAtDate = DateTime.Now;
            restaurant.UpdatedAtDate = DateTime.Now;



            _restaurantInfoRepository.AddRestaurant(restaurant);

            if (!_restaurantInfoRepository.Save())
            {
                return(StatusCode(500, "SOmething wEnT WrOnG wHilE HanDlIng yOuR ReQUesT."));
            }

            return(Ok(restaurant));
        }