public IActionResult Post([FromBody] ApiReservationViewModel newReservation) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userReservation = Mapper.Map <Reservation>(newReservation); var reservationOwner = _reservationContactRepo.CreateNew(userReservation.ReservationContact); var created = _reservationRepo.CreateNewReservation(userReservation, reservationOwner.Id); if (created != null) { if (this.User.Identity.IsAuthenticated) { var userId = _userMgr.GetUserId(HttpContext.User); if (!_reservationRepo.AddReservationToUser(created, userId)) { return(BadRequest()); } } return(Created("", Mapper.Map <ApiReservationViewModel>(created))); } return(BadRequest("error occured")); }
public IActionResult Put(long confirmationNumber, [FromBody] ApiReservationViewModel updatedReservation) { var reservationToUpdate = Mapper.Map <Reservation>(updatedReservation); var oldReservation = _reservationRepo.GetReservationByConfirmationNumber(confirmationNumber); if (oldReservation == null) { return(NotFound($"Reservation with {confirmationNumber} could not be found")); } Mapper.Map <Reservation, Reservation>(reservationToUpdate, oldReservation); if (!_reservationRepo.UpdateReservation(oldReservation)) { return(BadRequest($"{confirmationNumber} could not be updated")); } return(Ok($"{confirmationNumber} has been updated")); }