public IActionResult CreateAirport([FromBody] Airport airport) { var response = new PostAirportResponse(); try { response = _airportService.PostAirport(new PostAirportRequest { NewAirport = airport }); } catch (Exception ex) { return(BadRequest(ex.ToString())); } if (response.IsSuccessful) { return(Ok(response.Message)); } else { return(BadRequest(response.Message)); } }
public PostAirportResponse PostAirport(PostAirportRequest request) { var response = new PostAirportResponse { IsSuccessful = false, Message = "" }; try { _context.Add(request.NewAirport); _context.SaveChanges(); response.IsSuccessful = true; response.Message = "Airport successfully added to database."; } catch (Exception ex) { response.IsSuccessful = false; response.Message = ex.ToString(); } return(response); }