示例#1
0
 public AirportViewModel(AirportDto airportDto)
 {
     this.Id        = airportDto.Id;
     this.Name      = airportDto.Name;
     this.Longitude = airportDto.Longitude;
     this.Latitude  = airportDto.Latitude;
 }
        private IEnumerable <domain.City> Translate(AirportDto airports)
        {
            var res = new List <domain.City>();

            if (airports != null && airports.Continents.Any())
            {
                foreach (var continent in airports.Continents)
                {
                    foreach (var country in continent.Countries)
                    {
                        foreach (var city in country.Cities)
                        {
                            var newCity = new domain.City(city.Name);

                            foreach (var airport in city.Airports)
                            {
                                var location = airport.Location.Split(',');

                                newCity.AddAirport(id: airport.Id, name: airport.Name, latitude: location[1], longitude: location[0], cityName: city.Name);
                            }

                            res.Add(newCity);
                        }
                    }
                }
            }

            return(res);
        }
示例#3
0
        public AirportDto toDto(AirportEntity airport)
        {
            AirportDto airportDto = new AirportDto();

            airportDto.AirportId = airport.AirportId;
            airportDto.City      = airport.City;
            return(airportDto);
        }
示例#4
0
        public AirportEntity toEntity(AirportDto airportDto)
        {
            AirportEntity airport = new AirportEntity();

            airport.AirportId = airportDto.AirportId;
            airport.City      = airportDto.City;
            return(airport);
        }
示例#5
0
 public static AirportModel FromDto(AirportDto airportDto)
 {
     return(new AirportModel
     {
         Country = airportDto.Country,
         City = airportDto.City,
         Iata = airportDto.Iata
     });
 }
        public async Task <IActionResult> GetAirport([FromRoute] string airportId)
        {
            var airport = await _flightService.GetAirport(airportId);

            if (airport == null)
            {
                return(NotFound());
            }
            return(Ok(AirportDto.Map(airport)));
        }
示例#7
0
 private static List <Triple> ConvertAirport(AirportDto airport)
 {
     return(new TripleBuilder(nodeFactory.AsBlankNode(airport.NodeId))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.Type), nodeFactory.AsValueNode(Constants.Types.Airport))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportId), nodeFactory.AsValueNode(airport.AirportId))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportIata), nodeFactory.AsValueNode(airport.IATA))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportName), nodeFactory.AsValueNode(airport.Name))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportCity), nodeFactory.AsValueNode(airport.City))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportState), nodeFactory.AsValueNode(airport.State))
            .Add(nodeFactory.AsUriNode(Constants.Predicates.AirportCountry), nodeFactory.AsValueNode(airport.Country))
            .Build());
 }
示例#8
0
 public int AddAirport(AirportDto airport)
 {
     try
     {
         var airportTask = airportsRepository.AddAirport(airport);
         Task.WhenAll(airportTask);
         return(airportTask.Result);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#9
0
 public ActionResult <int> AddAirport([FromBody] AirportDto airport)
 {
     if (airport == null)
     {
         return(UnprocessableEntity());
     }
     try
     {
         var result = _airportService.AddAirport(airport);
         return(Ok(result));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
        private int FindPriorityIdx(List <AirportDto> relatedAirports, AirportDto destinationAirport)
        {
            if (destinationAirport.NumberOfPassengers == default)
            {
                return(-1);
            }
            var allValues       = relatedAirports.Where(a => a.NumberOfPassengers != default).Select(a => a.NumberOfPassengers);
            var minValue        = allValues.Min();
            var localPercentage = 100.0 * (destinationAirport.NumberOfPassengers - minValue) / allValues.Max() - minValue;

            var min = FlightDestinationResponse.LowestPriorityIdx;
            var max = FlightDestinationResponse.MaxPriorityIdx;

            var priority = (localPercentage * (max - min) / 100.0) - min;

            return((int)Math.Round(priority));
        }
示例#11
0
        private double DistanceBetweenPlaces(AirportDto departure, AirportDto destination)
        {
            var R = 6371; // km

            var latDepartureSinus      = Math.Sin(Radians(departure.Latitude));
            var latDestinationSinus    = Math.Sin(Radians(destination.Latitude));
            var latDepartureCosinus    = Math.Cos(Radians(departure.Latitude));
            var latDestiniationCosinus = Math.Cos(Radians(destination.Latitude));
            var longitudeCosinus       = Math.Cos(Radians(departure.Longitude) - Radians(destination.Longitude));

            var cosD = latDepartureSinus * latDestinationSinus + latDepartureCosinus * latDestiniationCosinus * longitudeCosinus;

            var d = Math.Acos(cosD);

            var dist = R * d;

            return(dist);
        }
示例#12
0
        public async Task <int> AddAirport(AirportDto airport)
        {
            int recordsAffected = 0;
            var newAirport      = new Airport()
            {
                Iata      = airport.Iata,
                Lon       = airport.Lon,
                Lat       = airport.Lat,
                Iso       = airport.Iso,
                Status    = airport.Status,
                Name      = airport.Name,
                Continent = airport.Continent,
                Type      = airport.Type,
                Size      = airport.Size,
            };

            context.Airports.Add(newAirport);
            recordsAffected = await context.SaveChangesAsync();

            return(recordsAffected);
        }
示例#13
0
        public AirportDto AssignOptimalRunwayToAirportDto(AirportDto SubjectAirport)
        {
            if (SubjectAirport.Runways == null || SubjectAirport.Runways.Count == 0)  //no runway information
            {
                foreach (WeatherReportDto weather_report in SubjectAirport.WeatherForecast[0].WeatherReports)
                {
                    weather_report.AirplaneTakeoffDescription = "Insufficient runway information to calculate takeoff direction.";
                }
                return(SubjectAirport); //no runways, do nothing
            }
            else
            {
                if (SubjectAirport.WeatherForecast[0] == null)
                {
                    throw new System.ArgumentException("WeatherForecast required before optimal runway can be assigned");
                }

                List <int> converted_runways = ConvertRunways(SubjectAirport.Runways);

                foreach (WeatherReportDto weather_report in SubjectAirport.WeatherForecast[0].WeatherReports)
                {
                    if (converted_runways == null || converted_runways.Count == 0)
                    {
                        //single helicopter/balloon pads return null/0
                        weather_report.AirplaneTakeoffDescription = "Planes do not take off from this airport.";
                    }
                    else
                    {
                        //assign plane takeoff data per weather day
                        int wind_direction           = weather_report.WindDirectionDeg;
                        int optimal_runway_direction = SelectOptimalRunwayDirection(converted_runways, wind_direction);
                        int airplane_takeoff_angle   = optimal_runway_direction;
                        weather_report.AirplaneTakeoffAngle       = airplane_takeoff_angle;
                        weather_report.AirplaneTakeoffDescription = ProvideAirplaneTakeoffDescription(airplane_takeoff_angle);
                    }
                }
            }
            return(SubjectAirport);
        }
        public async Task ExecuteAsync_ShouldCallCalculateDistanceCommand()
        {
            // arrange
            var from = new AirportDto {
                Iata = "LED", Location = new LocationDto()
            };
            var to = new AirportDto {
                Iata = "AMS", Location = new LocationDto()
            };
            var command = new CalculateDistanceBetweenAirportsCommand(from, to);

            // act
            var result = await _sut.ExecuteAsync(command);

            // assert
            Assert.That(result, Is.Not.Null);

            // verify
            _mediatorMock.Verify(
                x => x.ExecuteAsync(It.Is <IPipeline <double> >(r => r is CalculateDistanceBetweenLocationsCommand)),
                Times.Once);
        }
        public IHttpActionResult PutAirport(AirportDto airportDto)
        {
            var airport = db.Airports.Find(airportDto.AirportId);

            if (airport == null)
            {
                return(BadRequest());
            }

            airport.Name = airport.Name != airportDto.Name ? airportDto.Name : airport.Name;

            airport.Address.Country      = airport.Address.Country != airportDto.Country ? airportDto.Country : airport.Address.Country;
            airport.Address.Street       = airport.Address.Street != airportDto.Street ? airportDto.Street : airport.Address.Street;
            airport.Address.StreetNumber = airport.Address.StreetNumber != Convert.ToInt32(airportDto.StreetNumber) ? Convert.ToInt32(airportDto.StreetNumber) : airport.Address.StreetNumber;
            airport.Address.City         = airport.Address.City != airportDto.City ? airportDto.City : airport.Address.City;

            db.Entry(airport).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AirportExists(airportDto.AirportId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
示例#16
0
 public AirportDto FindAirport(AirportDto airportDto)
 {
     return(AirportMapper.toDto(AirportRepository.GetAirportByID(airportDto.AirportId)));
 }
        public async Task <IActionResult> GetAirports([FromQuery] string cityName)
        {
            var airports = await _flightService.GetAirports(cityName);

            return(Ok(AirportDto.Map(airports)));
        }
 public CalculateDistanceBetweenAirportsCommand(AirportDto from, AirportDto to)
 {
     From = from;
     To = to;
 }
示例#19
0
 public int UpdateAirport(AirportDto airport)
 {
     throw new NotImplementedException();
 }
示例#20
0
        public AirportDto AddAirport(AirportDto airportDto)
        {
            AirportEntity airportEntity = AirportRepository.InsertAirportEntity(AirportMapper.toEntity(airportDto));

            return(AirportMapper.toDto(airportEntity));
        }
示例#21
0
 public ActionResult <int> UpdateAirport([FromBody] AirportDto airport)
 {
     throw new NotImplementedException();
 }