public IActionResult AddReservation(ReservationModel reservationModel) { try { if (!ModelState.IsValid) { return(BadRequest(ErrorHelper.ExtractErrors(ModelState))); } ReservationModel addedReservation = reservationLogic.AddReservation(reservationModel); return(Created("api/reservations/" + addedReservation.ReservationID, addedReservation)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ErrorHelper.GetExceptionMessage(ex))); } }
public IHttpActionResult AddReservation([FromBody] ReservationData data) { if (data == null) { //Bad request code 400 return(BadRequest()); } if (reservationLogic.AddReservation(data)) { //petición correcta y se ha creado un nuevo recurso code 201 return(StatusCode(HttpStatusCode.Created)); } else { //No se pudo crear el recurso por un error interno code 500 return(InternalServerError()); } }