public IActionResult RegisterRestaurant(RestaurantCreationDto restaurantCreationDto) { var restaurant = this.Mapper.Map <Restaurant>(restaurantCreationDto); this.AuthenticationRepository.RegisterRestaurant(restaurant); var restaurantToReturn = this.Mapper.Map <RestaurantDto>(restaurant); return(CreatedAtRoute("GetRestaurant", new { restaurantId = restaurantToReturn.Id }, restaurantToReturn)); }
public async Task <ActionResult <RestaurantDto> > AddRestaurantAsync(RestaurantCreationDto restaurantCreationDto) { var restaurant = _mapper.Map <Restaurant>(restaurantCreationDto); _restaurantService.AddRestaurant(restaurant); if (!await _restaurantService.SaveAsync()) { throw new Exception("Creating a Restaurant failed to save. Please try again later"); } var restaurantToReturn = _mapper.Map <RestaurantDto>(restaurant); return(CreatedAtRoute("GetRestaurant", new { id = restaurant.Id }, restaurantToReturn)); }
public async Task <ActionResult <RestaurantDto> > UpdateRestaurantAsync(Guid id, RestaurantCreationDto restaurantCreationDto) { var restaurantSaved = await _restaurantService.GetRestaurantAsync(id); if (restaurantSaved == null) { return(NotFound($"The restaurant with the given {id} is not present")); } _mapper.Map(restaurantCreationDto, restaurantSaved); _restaurantService.EditRestaurant(restaurantSaved); if (!await _restaurantService.SaveAsync()) { throw new Exception("Failed to update Restaurant. Please try again later"); } return(NoContent()); }