public async Task UpdateHotelAsync(Guid id, HotelForAddOrUpdateDto hotelToUpdate) { var hotelEntity = await _hotelInfoRepository.GetFirstAsync <Hotel>(h => h.Id == id); if (hotelEntity == null) { throw new NotFoundException($"Could not find hotel with id '{id.ToString()}'"); } _mapper.Map(hotelToUpdate, hotelEntity); _hotelInfoRepository.Update(hotelEntity); if (!await _hotelInfoRepository.SaveChangesAsync()) { throw new Exception($"Trying to update hotel with id '{id.ToString()}' failed"); } }
public async Task <HotelDto> AddHotelAsync(HotelForAddOrUpdateDto hotelToAdd) { var hotelEntity = _mapper.Map <Hotel>(hotelToAdd); _hotelInfoRepository.Add(hotelEntity); if (!await _hotelInfoRepository.SaveChangesAsync()) { throw new Exception("Trying to add hotel failed"); } var createdId = hotelEntity.Id; hotelEntity = await _hotelInfoRepository .GetFirstAsync <Hotel>(h => h.Id == createdId); if (hotelEntity == null) { throw new NotFoundException($"Could not find hotel with id '{createdId.ToString()}'"); } return(_mapper.Map <HotelDto>(hotelEntity)); }
public async Task <IActionResult> UpdateHotel(Guid id, [FromBody] HotelForAddOrUpdateDto hotelToUpdate) { await _hotelService.UpdateHotelAsync(id, hotelToUpdate); return(NoContent()); }
public async Task <IActionResult> AddHotel(HotelForAddOrUpdateDto hotelToAdd) { var hotel = await _hotelService.AddHotelAsync(hotelToAdd); return(CreatedAtAction(nameof(GetHotelById), new { id = hotel.Id }, hotel)); }