/* * return flight plan of flight with specific id. */ public async Task <ActionResult <FlightPlan> > GetFP(string id) { string serverId = await _flightToServerDb.LoadFlightServer(id); if (serverId != null && serverId.Equals("Not Found")) { return(NotFound()); } if (serverId == null) { FlightPlan fp = await _fpDb.LoadFP(id); if (fp == null) { return(NotFound()); } return(fp); } Server server = await _serverDb.LoadServer(serverId); HttpResponseMessage response; try { response = await _client.GetAsync(new string(server.Url + "/api/FlightPlan/" + id)); } catch (Exception) { return(StatusCode(500, "cant get respone from other server")); } if (!response.IsSuccessStatusCode) { if (response.StatusCode == System.Net.HttpStatusCode.NotFound) { return(new NotFoundObjectResult("the extarnal server didn't find the flight plan")); } return(StatusCode(500, "problem in the respone from external server")); } var resp = await response.Content.ReadAsStringAsync(); FlightPlan flightPlan = JsonConvert.DeserializeObject <FlightPlan>(resp); if (flightPlan == null || !flightPlan.IsValid()) { return(StatusCode(500, "problem in the respone from external server")); } return(flightPlan); }
/* * delete flight plan from the server. */ public async Task <ActionResult> Delete(string id) { FlightPlan fp = await _fpDb.LoadFP(id); if (fp == null) { return(NotFound()); } if (await _flightToServerDb.IsFlightExternal(id)) { return(BadRequest()); } await _fpDb.DeleteFlight(id); await _flightToServerDb.DeleteFlightToServer(id); return(Ok()); }