public async Task <IActionResult> UpdateBookingAsync(int id, [FromBody] BookingUpdateRequest request) { if (!ModelState.IsValid) { throw new ServiceException(400, "Model is invalid"); } return(Ok(await _bookingService.UpdateBookingAsync(id, request))); }
public async Task <BookingUpdateResponse> UpdateBookingAsync(int id, BookingUpdateRequest request) { if (id != request.Id) { throw new Exception("Bad Request"); } if (await IsDuplicate(request.RoomId, request.From, request.To, true, request.Id)) { throw new ServiceException(400, "Duplicate Entry"); } var booking = _mapper.Map <Booking>(request); _context.Entry(booking).State = EntityState.Modified; await _context.SaveChangesAsync(); return(_mapper.Map <BookingUpdateResponse>(booking)); }