コード例 #1
0
 public AirportViewModel(AirportDto airportDto)
 {
     this.Id        = airportDto.Id;
     this.Name      = airportDto.Name;
     this.Longitude = airportDto.Longitude;
     this.Latitude  = airportDto.Latitude;
 }
コード例 #2
0
        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
     });
 }
コード例 #6
0
        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
ファイル: Program.cs プロジェクト: bytefish/DGraphSample
 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));
     }
 }
コード例 #10
0
        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
ファイル: FlightBusiness.cs プロジェクト: AbdaBob/Tui
        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);
        }
コード例 #15
0
        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)));
 }
コード例 #17
0
        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();
 }