public FlightModel CreateFlight(int departureAirportId, int arrivalAirportId) { var flight = new FlightModel(); var arrivalAirport = _airportBusiness.GetAirportById(arrivalAirportId); var departureAirport = _airportBusiness.GetAirportById(departureAirportId); flight.ArrivalAirport = arrivalAirport ?? new AirportModel(); flight.DepartureAirport = departureAirport ?? new AirportModel(); if (arrivalAirport != null && departureAirport != null) { flight.Distance = _flightService.CalculateDistanceWithHaversineFormulae(arrivalAirport.Coordinates, departureAirport.Coordinates); flight.Duration = _flightService.CalculateTimeOfFlight(flight.Distance, _speed); flight.Carburant = _flightService.CalculateFuelVolumeForFlight(flight.Distance, _fuelConsumption, departureAirport.TakeOffEffort); } flight.Creation = DateTime.Today; var flightEntity = SetFlightEntity(flight); _TUIAssessmentDAL.SaveFlightEntity(flightEntity); return(flight); }