Beispiel #1
0
        public async Task <IActionResult> Post([FromBody] AddRestaurantCommand restaurant)
        {
            if (string.IsNullOrWhiteSpace(restaurant.Name))
            {
                return(BadRequest());
            }

            await _restaurantService.AddRestaurant(new Restaurant(restaurant.Name, restaurant.Address, restaurant.City, restaurant.State));

            return(Accepted());
        }
 public ActionResult <RestaurantDto> PostRestaurant([FromBody] RestaurantDto restaurant)
 {
     try
     {
         AddRestaurantCommand addRestaurantCommand = CommandFactory.CreateAddRestaurantCommand(restaurant);
         addRestaurantCommand.Execute();
         RestaurantDto savedRestaurant = addRestaurantCommand.GetResult();
         _logger?.LogInformation($"Restaurante creado exitosamente con el ID {savedRestaurant.Id}");
         return(savedRestaurant);
     }
     catch (InvalidAttributeException e)
     {
         _logger?.LogError(e, "Error en campos de la entidad restaurante");
         return(BadRequest(new ErrorMessage(e.Message)));
     }catch (DatabaseException ex)
     {
         _logger?.LogError(ex, "Database exception when trying to add a restaurant");
         return(StatusCode(500, ex.Message));
     }
 }
        public async Task <IActionResult> AddRestaurant([FromBody] AddRestaurantCommand command)
        {
            var response = await _mediator.Send(command);

            return(Ok(response));
        }