public JsonFlight FlightList() { JsonFlight jsonFlight = new JsonFlight(); List <FlightViewModel> flightlinklistObj = new List <FlightViewModel>(); try { var ListFlights = _flight.ToList(); foreach (var item in ListFlights) { var Flight = _flight.FindById(item.Id); FlightViewModel FlightlistObj = new FlightViewModel(); FlightlistObj.FlightNumber = item.Number; FlightlistObj.Airplaincode = Flight.FlightAirPlaneId; FlightlistObj.airplainid = Flight.FlightAirPlaneId; FlightlistObj.AirplainName = _airPlane.FindById(Flight.FlightAirPlaneId).Name; FlightlistObj.AirlineIcon = _airline.FindById(_airPlane.FindById(Flight.FlightAirPlaneId).AirlineId).Logo; FlightlistObj.AirlineName = _airline.FindById(_airPlane.FindById(Flight.FlightAirPlaneId).AirlineId).Name; FlightlistObj.AirlineId = _airline.FindById(_airPlane.FindById(Flight.FlightAirPlaneId).AirlineId).Id; FlightlistObj.Flightid = Flight.Id; FlightlistObj.StartAirPortId = _city.FindById(_address.FindById(_airport.FindById(Flight.StartAirPortId).AirPortAddressId).CityId).Id; FlightlistObj.startCityName = _city.FindById(_address.FindById(_airport.FindById(Flight.StartAirPortId).AirPortAddressId).CityId).Name; FlightlistObj.EndAirPortid = _city.FindById(_address.FindById(_airport.FindById(Flight.StartAirPortId).AirPortAddressId).CityId).Id; FlightlistObj.EndcityName = _city.FindById(_address.FindById(_airport.FindById(Flight.StartAirPortId).AirPortAddressId).CityId).Name; FlightlistObj.WeatherIcon = _Weatger.FindByAirportId(Flight.StartAirPortId).Icon; FlightlistObj.StartTime = Flight.EndTimeDate; FlightlistObj.EndTime = Flight.EndTimeDate; FlightlistObj.Delay = Flight.Delay; flightlinklistObj.Add(FlightlistObj); } jsonFlight.Result = flightlinklistObj; return(jsonFlight); } catch (Exception ex) { string Mes = ex.Message; return(jsonFlight); } }
public IActionResult GetFlightById(int id) { _log4net.Info(" Http GetFlightById request Initiated"); if (id == 0) { return(BadRequest("Enter valid id")); } try { var flight = repo.FindById(id); if (flight != null) { return(Ok(flight)); } return(BadRequest("No record")); } catch (Exception) { return(BadRequest("Some Error Occured Please try again")); } }