protected override async Task <ICommandResult> Handle(SaveVenueCommand command) { Country savedCountry = new Country(); var countryinfo = new Country(); if (command.Country == "United Kingdom" || command.Country == "U.K.") { countryinfo = _countryRepository.Get(231); } else if (command.Country == "United States" || command.Country == "U.S.A.") { countryinfo = _countryRepository.Get(230); } else { countryinfo = _countryRepository.GetByName(command.Country); } if (countryinfo == null) { var country = new Country { AltId = Guid.NewGuid(), Name = command.Country, IsoAlphaThreeCode = "NA", IsoAlphaTwoCode = "NA", ModifiedBy = command.ModifiedBy, CreatedUtc = DateTime.UtcNow, IsEnabled = true }; savedCountry = _countryRepository.Save(country); } else { savedCountry.AltId = countryinfo.AltId; savedCountry.Id = countryinfo.Id; } //-------------------------------------------------------------------- var stateinfo = _stateRepository.GetByNameAndCountryId(command.State, savedCountry.Id); State state = new State(); if (stateinfo == null) { state = _stateRepository.Save(new State() { AltId = Guid.NewGuid(), CountryId = savedCountry.Id, IsEnabled = true, Abbreviation = "NA", CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.Now, Name = command.State, UpdatedBy = command.ModifiedBy, ModifiedBy = command.ModifiedBy, UpdatedUtc = DateTime.Now }); } else { state.Id = stateinfo.Id; state.AltId = stateinfo.AltId; } //-------------------------------------------------------------------- var cityinfo = _cityRepository.GetByNameAndStateId(command.City, state.Id); City city = new City(); if (cityinfo == null) { city = _cityRepository.Save(new City() { AltId = Guid.NewGuid(), Name = command.City, StateId = state.Id, IsEnabled = true, CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.Now, UpdatedBy = command.ModifiedBy, ModifiedBy = command.ModifiedBy, UpdatedUtc = DateTime.Now }); } else { city.Id = cityinfo.Id; city.AltId = cityinfo.AltId; } //-------------------------------------------------------------------- var venueinfo = _venueRepository.GetByNameAndCityId(command.VenueName, city.Id); Venue venue = new Venue(); if (venueinfo == null) { venue = _venueRepository.Save(new Venue() { AltId = Guid.NewGuid(), Name = command.VenueName, CityId = city.Id, AddressLineOne = command.AddressLineOne, AddressLineTwo = command.AddressLineTwo, Latitude = command.Latitude, Longitude = command.Longitude, IsEnabled = true, CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.Now, UpdatedBy = command.ModifiedBy, ModifiedBy = command.ModifiedBy, UpdatedUtc = DateTime.Now }); } else { venue.Id = venueinfo.Id; venue.AltId = venueinfo.AltId; } //----------------------------------------------------- var mastervenuelayoutinfo = _masterVenueLayoutRepository.GetByName(command.VenueName); MasterVenueLayout masterVenueLayout = new MasterVenueLayout(); if (mastervenuelayoutinfo == null) { masterVenueLayout = _masterVenueLayoutRepository.Save(new MasterVenueLayout() { AltId = Guid.NewGuid(), LayoutName = command.VenueName, VenueId = venue.Id, IsEnabled = true, CreatedBy = command.ModifiedBy, CreatedUtc = DateTime.Now, UpdatedBy = command.ModifiedBy, ModifiedBy = command.ModifiedBy, UpdatedUtc = DateTime.Now }); return(new SaveSaveVenueCommandResult { Success = true, LayoutAltId = masterVenueLayout.AltId.ToString(), IsExisting = false }); } return(new SaveSaveVenueCommandResult { Success = false, LayoutAltId = masterVenueLayout.AltId.ToString(), IsExisting = true }); }
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); }