コード例 #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;
            }
        }