Пример #1
0
        private async Task StartProcessingProvidersData(List <PEntity> providers, string networkName, string fileName)
        {
            try
            {
                providerCategories = _importService.GetAllProviderCategories().Result;
                loggers.Debug($"Successfully got the List of Provider categories from DB.");

                specialities = _importService.GetAllSpecialities().Result;
                loggers.Debug($"Successfully got the List of Specialities from DB.");

                for (int i = 0; i < providers.Count; i++)
                {
                    try
                    {
                        DoesProviderHasAllMandatoryFields(providers[i]);
                    }
                    catch (Exception ex)
                    {
                        throw;
                    }
                }
                loggers.Debug($"The file has all mandatory fields data.");
                int counter = 1;
                foreach (var provider in providers)
                {
                    counter = counter + 1;
                    var address = provider.ServiceAddress1 + " " + (string.IsNullOrEmpty(provider.ServiceAddress2) ? " " : provider.ServiceAddress2) +
                                  " " + provider.ServiceCity + " " + provider.ServiceState + " " + provider.ServiceZip.Substring(0, 5);
                    var locationEntity = GeoCoordinateTool.GetLocation(address, System.Configuration.ConfigurationManager.AppSettings["Google_Map_Api_Url"], System.Configuration.ConfigurationManager.AppSettings["Google_Map_Api_Key"]).Result;
                    if (locationEntity != null && string.IsNullOrEmpty(locationEntity.ErrorMessage_GoogleMapAPI) && string.IsNullOrEmpty(locationEntity.Status_GoogleMapAPI))
                    {
                        provider.Latitude  = locationEntity.Latitude.ToString();
                        provider.Longitude = locationEntity.Longitude.ToString();
                    }
                    else
                    {
                        provider.Latitude  = "0";
                        provider.Longitude = "0";
                        loggers.Debug($"Latitude: 0 Longitude: 0 Address:{address} for the ProviderFullName: {provider.ProviderFullName} ProviderFirstName: {provider.ProviderFirstName} ProviderLastName:{provider.ProviderLastName} API_ErrorMessage:{locationEntity.ErrorMessage_GoogleMapAPI} API_Status:{locationEntity.Status_GoogleMapAPI} ");
                    }
                }
                loggers.Debug($"Succesfully updated the latitude and longitude for each provider.");

                int bulkInsertRecordsCount = 0;
                if (System.Configuration.ConfigurationManager.AppSettings["BulkInsertRecordsCount"] != null)
                {
                    bulkInsertRecordsCount = Convert.ToInt16(System.Configuration.ConfigurationManager.AppSettings["BulkInsertRecordsCount"]);
                }

                await _importService.SaveProviderCollection(providers, networkName, fileName, bulkInsertRecordsCount);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        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));
        }
Пример #3
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);
            }
        }
        public async Task <List <ProviderResultDetails> > GetFilteredOrganizationDetails(string networkCode, string zipCode, int miles, int pageNumber, string specialization, string facility, string providerOrFacilityName, int providerId)
        {
            try
            {
                string collectionName = await _organizationRepository.GetCollectionName(networkCode);

                if (collectionName != null)
                {
                    List <PEntity> providerList = await _providerRepository.GetAllOrganizationDetails(false, collectionName);

                    if (!string.IsNullOrEmpty(facility))
                    {
                        providerList = providerList.Where(provider => provider.ProviderCategory != null && provider.ProviderCategory.ToLower().Equals(facility.ToLower())).ToList();
                    }

                    if (!string.IsNullOrEmpty(specialization))
                    {
                        providerList = providerList.Where(provider => provider.ProviderSpecialityCode != null && provider.ProviderSpecialityCode.ToLower().Equals(specialization.ToLower())).ToList();
                    }

                    if (!string.IsNullOrEmpty(providerOrFacilityName))
                    {
                        providerList = providerList.Where(provider => (provider.ProviderFirstName.ToLower().Contains(providerOrFacilityName.ToLower()) || provider.ProviderLastName.ToLower().Contains(providerOrFacilityName.ToLower()) || provider.ProviderFullName.ToLower().Contains(providerOrFacilityName.ToLower()))).ToList();
                    }

                    List <ProviderResultDetails> ProviderTopSliceList = (from pl in providerList
                                                                         select(new ProviderResultDetails
                    {
                        Id = pl.IdGeneratedNumber,
                        ProviderFirstName = pl.ProviderFirstName,
                        ProviderLastName = pl.ProviderLastName,
                        ProviderFullName = pl.ProviderFullName,
                        LocationPracticeAddress = pl.ServiceAddress1 + " " + (string.IsNullOrEmpty(pl.ServiceAddress2) ? " " : pl.ServiceAddress2) +
                                                  " " + pl.ServiceCity + " " + pl.ServiceState + " " + pl.ServiceZip.Substring(0, 5),
                        ServiceAddress1 = pl.ServiceAddress1,
                        ServiceAddress2 = pl.ServiceAddress2,
                        ServiceCity = pl.ServiceCity,
                        ServiceState = pl.ServiceState,
                        ServiceZip = pl.ServiceZip,
                        Specialization = _providerRepository.GetSpecialityById(pl.ProviderSpecialityCode).Speciality,
                        Facility = string.IsNullOrEmpty(pl.ProviderCategory) ? string.Empty : _providerRepository.GetFacilityById(pl.ProviderCategory).ProviderCategory,
                        PhoneAreaCode = string.IsNullOrEmpty(pl.PhoneAreaCode) ? string.Empty : pl.PhoneAreaCode,
                        PhoneNumber = string.IsNullOrEmpty(pl.PhoneNumber) ? string.Empty : pl.PhoneNumber,
                        PhoneExtension = string.IsNullOrEmpty(pl.PhoneExtension) ? string.Empty : "(" + pl.PhoneExtension + ")",
                        Latitude = string.IsNullOrEmpty(pl.Latitude) ? 0 : Convert.ToDouble(pl.Latitude),
                        Longitude = string.IsNullOrEmpty(pl.Longitude) ? 0 : Convert.ToDouble(pl.Longitude),
                        ProviderType = string.IsNullOrEmpty(pl.ProviderCategory) ? Constants.Ind : _providerRepository.GetFacilityById(pl.ProviderCategory).Type,
                        ProviderCategory = pl.ProviderCategory
                    })).ToList().Where(item => item.Id > providerId).OrderBy(item => item.Id).ToList();

                    var sourceLocation = (dynamic)null;
                    if (!string.IsNullOrEmpty(zipCode))
                    {
                        //Request the Google API when the zipcode has value
                        sourceLocation = await GeoCoordinateTool.GetLocation(zipCode, _configurationKeys.Value.Google_Map_Api_Url, _configurationKeys.Value.Google_Map_Api_Key);
                    }
                    List <ProviderResultDetails> providerResults = new List <ProviderResultDetails>();

                    int counter = 0;
                    foreach (var location in ProviderTopSliceList)
                    {
                        if (counter == _configurationKeys.Value.PaginationLimit)
                        {
                            break;
                        }

                        if (!string.IsNullOrEmpty(zipCode))
                        {
                            Tuple <bool, string> getLocationValues = IsLocationWithInRange(miles, sourceLocation, new LocationEntity()
                            {
                                Latitude = Convert.ToDouble(location.Latitude), Longitude = Convert.ToDouble(location.Longitude)
                            });
                            if (getLocationValues.Item1 == true && getLocationValues != null)
                            {
                                location.RadiusDistance = getLocationValues.Item2;
                                providerResults.Add(location);
                                counter++;
                            }
                        }
                        else
                        {
                            providerResults.Add(location);
                            counter++;
                        }
                    }

                    return(providerResults);
                }
                return(null);
            }
            catch (Exception ex)
            {
                loggers.Error($"{Constants.PWeb} failed to get all filtered organization details.");
                return(null);
            }
        }