示例#1
0
        public async Task <SaveLocationReturnValues> UpdateCountryAndVenueDetails(string lat, string lon, string venueName, string venueAddress, Guid modifiedBy, string countryName, string cityName)
        {
            try
            {
                var locationDetails = await _googleMapApi.GetLocationFromLatLong(lat, lon);

                if (locationDetails.Success)
                {
                    //check for proper required Data
                    if (!CheckValid(locationDetails))
                    {
                        var translatedVenueAddress = _toEnglishTranslator.TranslateToEnglish(venueAddress);
                        locationDetails = await _googleMapApi.GetLatLongFromAddress(translatedVenueAddress);

                        if (!CheckValid(locationDetails))
                        {
                            var translatedCityName = _toEnglishTranslator.TranslateToEnglish(cityName);
                            locationDetails = await _googleMapApi.GetLatLongFromAddress(translatedCityName);
                        }
                    }
                    var translatedResultCountryName = _toEnglishTranslator.TranslateToEnglish(locationDetails.Result.CountryName);
                    var countryCodeAndCurrency      = await _countryAlphaCode.GetCountryCodeByName(translatedResultCountryName);

                    var country = _countryRepository.GetByName(translatedResultCountryName);
                    if (country == null)
                    {
                        country = _countryRepository.Save(new Country
                        {
                            Name              = translatedResultCountryName,
                            IsoAlphaTwoCode   = countryCodeAndCurrency == null ? countryCodeAndCurrency.Result.IsoAlphaTwoCode.ToUpper() : locationDetails.Result.CountryName.Substring(0, 2).ToUpper(),
                            IsoAlphaThreeCode = countryCodeAndCurrency == null ? countryCodeAndCurrency.Result.IsoAlphaThreeCode.ToUpper() : locationDetails.Result.CountryName.Substring(0, 3).ToUpper(),
                            IsEnabled         = true,
                            CreatedUtc        = DateTime.UtcNow,
                            ModifiedBy        = modifiedBy,
                            CountryName       = translatedResultCountryName
                        });
                    }
                    var translatedResultStateName = _toEnglishTranslator.TranslateToEnglish(locationDetails.Result.StateName);
                    var state = _stateRepository.GetByNameAndCountryId(translatedResultStateName, country.Id);
                    if (state == null)
                    {
                        state = _stateRepository.Save(new State
                        {
                            Name       = translatedResultStateName,
                            CountryId  = country.Id,
                            IsEnabled  = true,
                            CreatedUtc = DateTime.UtcNow,
                            ModifiedBy = modifiedBy
                        });
                    }
                    var translatedResultCityName = _toEnglishTranslator.TranslateToEnglish(locationDetails.Result.CityName);
                    var city = _cityRepository.GetByNameAndStateId(locationDetails.Result.CityName, state.Id);
                    if (city == null)
                    {
                        city = _cityRepository.Save(new City
                        {
                            Name       = translatedResultCityName,
                            StateId    = state.Id,
                            IsEnabled  = true,
                            CreatedUtc = DateTime.UtcNow,
                            ModifiedBy = modifiedBy
                        });
                    }
                    var translatedResultVenueName = _toEnglishTranslator.TranslateToEnglish(venueName);
                    var venue = _venueRepository.GetByNameAndCityId(translatedResultVenueName, city.Id);
                    if (venue == null)
                    {
                        venue = _venueRepository.Save(new Contracts.DataModels.Venue
                        {
                            AltId          = Guid.NewGuid(),
                            Name           = translatedResultVenueName,
                            AddressLineOne = venueAddress,
                            CityId         = city.Id,
                            ModifiedBy     = modifiedBy,
                            IsEnabled      = true,
                            CreatedUtc     = DateTime.UtcNow
                        });
                    }
                    var values = new SaveLocationReturnValues
                    {
                        cityId    = city.Id,
                        venueId   = venue.Id,
                        countryId = country.Id
                    };

                    return(values);
                }
            }
            catch (Exception e)
            {
                _logger.Log(LogCategory.Error, new Exception("Failed to Update Country and Venue Details", e));
            }
            return(null);
        }
示例#2
0
        public async Task <SaveLocationReturnValues> SaveCityStateCountry(ChauffeurRoute routeDetail, ValueRetailVillage village)
        {
            var locationData = await _googleMapApi.GetLatLongFromAddress(routeDetail.LocationHeader);

            try
            {
                if (!locationData.Success)
                {
                    throw new ArgumentNullException(locationData.Result.CityName, "Failed to get Location Data");
                }

                var countryCodeAndCurrency = await _countryAlphaCode.GetCountryCodeByName(locationData.Result.CountryName);

                var country = _countryRepository.GetByName(locationData.Result.CountryName);
                if (country == null)
                {
                    country = _countryRepository.Save(new Country
                    {
                        Name              = locationData.Result.CountryName,
                        IsoAlphaTwoCode   = countryCodeAndCurrency.Result.IsoAlphaTwoCode.ToUpper(),
                        IsoAlphaThreeCode = countryCodeAndCurrency.Result.IsoAlphaThreeCode.ToUpper(),
                        IsEnabled         = true,
                    });
                }

                var state = _stateRepository.GetByNameAndCountryId(locationData.Result.StateName, country.Id);
                if (state == null)
                {
                    state = _stateRepository.Save(new State
                    {
                        Name      = locationData.Result.StateName,
                        CountryId = country.Id,
                        IsEnabled = true,
                    });
                }

                var city = _cityRepository.GetByNameAndStateId(locationData.Result.CityName, state.Id);
                if (city == null)
                {
                    city = _cityRepository.Save(new City
                    {
                        Name      = locationData.Result.CityName,
                        StateId   = state.Id,
                        IsEnabled = true,
                    });
                }

                var currencyType = _currencyTypeRepository.GetByCurrencyCode(village.CurrencyCode.ToUpper());
                if (currencyType == null)
                {
                    currencyType = _currencyTypeRepository.Save(new CurrencyType
                    {
                        Code       = village.CurrencyCode.ToUpper(),
                        Name       = village.CurrencyCode.ToUpper(),
                        CountryId  = country.Id,
                        ModifiedBy = Guid.NewGuid(),
                        IsEnabled  = true
                    });
                }
                var values = new SaveLocationReturnValues
                {
                    cityId     = city.Id,
                    currencyId = currencyType.Id,
                    lat        = locationData.Result.lat,
                    lng        = locationData.Result.lng
                };

                return(values);
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, ex);
                return(new SaveLocationReturnValues());
            }
        }