public HttpResponseMessage Post(FlightPlanViewModel flightPlan) { HttpResponseMessage response; if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } try { _flightPlanService.BookFlight(flightPlan); response = Request.CreateResponse(HttpStatusCode.Created); } catch (Exception e) { response = Request.CreateResponse(HttpStatusCode.BadRequest); } return(response); }
public async Task <HttpResponseMessage> Post(FlightPlan flightPlan) { HttpResponseMessage response; if (!ModelState.IsValid) { return(Request.CreateResponse(HttpStatusCode.BadRequest, flightPlan)); } try { var result = await _flightPlanService.BookFlight(flightPlan); if (!result) { response = new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = "The Flight Is Full." } } ; else { response = Request.CreateResponse(HttpStatusCode.Created, flightPlan); } } catch (Exception e) { response = new HttpResponseMessage(HttpStatusCode.BadRequest) { ReasonPhrase = e.Message }; throw new HttpResponseException(response); } return(response); }