private Tuple <bool, string> IsLocationWithInRange(int rangeInMiles, LocationEntity source, LocationEntity target)
        {
            if (source == null || target == null)
            {
                return(null);
            }

            var    sourceCoordinates   = new GeoCoordinate(source.Latitude, source.Longitude);
            var    targetCoordinates   = new GeoCoordinate(target.Latitude, target.Longitude);
            var    distance            = (GeoCoordinateTool.Distance(sourceCoordinates, targetCoordinates, 1)); //1 - For MILES, 2 - For KM
            string distanceInSubstring = distance.ToString().Substring(0, 4);

            return(Tuple.Create(distance <= (rangeInMiles) ? true : false, distanceInSubstring));
        }
예제 #2
0
        public IHttpActionResult GetNearbyParties(FindPartyRequestModel findPartyRequestModel)
        {
            var partyResult = this.partyService
                .GetNearbyParties(findPartyRequestModel.Latitude, findPartyRequestModel.Longitude)
                .ProjectTo<ListedPartyResponseModel>()
                .ToList();

            var geotool = new GeoCoordinateTool();
            GeoCoordinate userCoordinates = new GeoCoordinate(findPartyRequestModel.Latitude, findPartyRequestModel.Longitude);

            for (int i = 0; i < partyResult.Count; i++)
            {
                GeoCoordinate partyCoordinates = new GeoCoordinate(partyResult[i].Latitude, partyResult[i].Longitude);
                partyResult[i].Distance = Math.Round(geotool.Distance(userCoordinates, partyCoordinates), 2);
            }

            return this.Ok<List<ListedPartyResponseModel>>(partyResult);
        }
        public void AddOrUpdate(Flight flight)
        {
            var departureAirport = _airportRepository.GetById(flight.DepartureAirportId);
            var arrivalAirport   = _airportRepository.GetById(flight.ArrivalAirportId);
            var airPlane         = _airPlaneRepository.GetById(flight.AirPlaneId);



            GeoCoordinate gd = new GeoCoordinate();
            GeoCoordinate ga = new GeoCoordinate();

            gd.Latitude  = departureAirport.Latitude;
            gd.Longitude = departureAirport.Longitude;

            ga.Latitude  = arrivalAirport.Latitude;
            ga.Longitude = arrivalAirport.Longitude;

            var geotool  = new GeoCoordinateTool();
            var distance = geotool.Distance(gd, ga, 1);

            flight.Distance = Math.Round(distance, 2);

            flight.Duration = Math.Round((Math.Round(distance, 2) / airPlane.Speed) / 60, 2);
            var consumption = (airPlane.Consumption * airPlane.TakeOffEffort * 60) / flight.Duration;

            flight.FuelConsumption = Math.Round(consumption, 2);
            flight.ModifiedDate    = System.DateTime.Now;
            if (flight.Id != 0)
            {
                _flightRepository.Update(flight);
            }
            else
            {
                flight.AddedDate = System.DateTime.Now;

                _flightRepository.Insert(flight);
            }
        }