public IActionResult EditBooking([FromBody] BookingUpdateDto bookingUpdateDto, int id) { if (bookingUpdateDto == null) { return(BadRequest()); } var spot = _repository.GetSpot(bookingUpdateDto.SpotId); if (spot == null) { return(StatusCode(404, $"Couldn't find the spot that has an id: {bookingUpdateDto.SpotId} associated with booking of id: {id}")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var bookingDto = Mapper.Map <BookingDto>(bookingUpdateDto); _repository.EditBooking(id, bookingDto); if (!_repository.SaveChanges()) { return(StatusCode(500, "Changes has not been saved.")); } return(Ok(_repository.GetBooking(id))); }
public async Task <IActionResult> UpdateBookingAsync(int id, BookingUpdateDto bookingUpdateDto) { if (id != bookingUpdateDto.Id) { return(BadRequest()); } var bookingFromRepo = await _repository.GetByIdAsync(id); if (bookingFromRepo == null) { return(NotFound()); } _mapper.Map(bookingUpdateDto, bookingFromRepo); //_repository.UpdateBooking(bookingFromRepo.Value); // this is achieved by the previous code try { await _repository.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if ((await _repository.GetByIdAsync(id)) == null) { return(NotFound()); } } return(NoContent()); }
public async Task <ActionResult> UpdateBooking(BookingUpdateDto bookingUpdateDto) { var booking = await _bookingService.GetBookingAsync(bookingUpdateDto.Id); _mapper.Map(bookingUpdateDto, booking); _bookingService.UpdateBooking(bookingUpdateDto); if (await _bookingService.SaveAllAsync()) { return(NoContent()); } return(BadRequest("Failed to modify booking")); }
public HttpResponseMessage UpdateBooking(BookingUpdateDto bookingDto) { if (!bookingBusiness.IsBookingIDValid(bookingDto.BookingID)) { HttpError err = new HttpError("The bookingID you entered is not valid."); return(Request.CreateResponse(HttpStatusCode.BadRequest, err)); } else if (!bookingBusiness.IsStatusValid(bookingDto.Status)) { HttpError err = new HttpError("The Status must be either Active, Completed or Cancelled."); return(Request.CreateResponse(HttpStatusCode.BadRequest, err)); } bookingBusiness.UpdateBooking(bookingDto.BookingID, bookingDto.Status); return(Request.CreateResponse(HttpStatusCode.OK, "Booking updated")); }
public void UpdateBooking(BookingUpdateDto bookingDto) { _context.Entry(bookingDto).State = EntityState.Modified; }