public async Task FetchAndSaveRoutes(ValueRetailVillage village) { var httpRequest = new ValueRetailCommanRequestModel { villageCode = village.VillageCode }; var responseString = await _valueRetailAPI.GetValueRetailAPIData(httpRequest, "Journeys", "ShoppingExpress"); ShoppingExpressJourney responseData = new ShoppingExpressJourney(); try { responseData = Mapper <ShoppingExpressJourney> .MapFromJson(responseString.Result); } catch (ArgumentNullException ex) { throw ex; } foreach (var journey in responseData.Journeys) { foreach (var route in journey.Routes) { try { var currentRoute = _valueRetailRouteRepository.GetByRouteIdStopIdLinkedRouteId(route.RouteId, route.StopId, route.LinkedRouteId); if (currentRoute == null) { currentRoute = _valueRetailRouteRepository.Save(new ValueRetailRoute { VillageId = village.Id, JourneyType = journey.JourneyType, RouteId = route.RouteId, DepartureTime = route.DepartureTime, LinkedRouteId = route.LinkedRouteId, ReturnTime = route.ReturnTime, Name = route.Name, LocationId = route.LocationId, LocationName = route.LocationName, LocationAddress = route.LocationAddress, StopId = route.StopId, StopOrder = route.StopOrder, Latitude = route.Latitude, Longitude = route.Longitude, AdultPrice = route.Prices.Adult == null ? 0 : Convert.ToDecimal(route.Prices.Adult.Price), ChildrenPrice = route.Prices.Children == null ? 0 : Convert.ToDecimal(route.Prices.Children.Price), FamilyPrice = route.Prices.Family == null ? 0 : Convert.ToDecimal(route.Prices.Family.Price), InfantPrice = route.Prices.Infant == null ? 0 : Convert.ToDecimal(route.Prices.Infant.Price), UnitPrice = route.Prices.Unit == null ? 0 : Convert.ToDecimal(route.Prices.Unit.Price), CreatedUtc = DateTime.UtcNow, CreatedBy = Guid.NewGuid(), }); if (route.ReturnStops != null && route.ReturnStops.Count > 0) { foreach (var returnStop in route.ReturnStops) { var currentReturnStop = _valueRetailReturnStopsRepository.Save(new ValueRetailReturnStop { ValueRetailRouteId = currentRoute.Id, RouteId = returnStop.RouteId, StopId = returnStop.StopId, StopOrder = returnStop.StopOrder, Name = returnStop.Name, LocationId = returnStop.LocationId, LocationName = returnStop.LocationName, LocationAddress = returnStop.LocationAddress, ReturnTime = returnStop.ReturnTime, Latitude = returnStop.Latitude, Longitude = returnStop.Longitude, CreatedUtc = DateTime.UtcNow, CreatedBy = Guid.NewGuid(), }); } } } } catch (TaskCanceledException ex) { _logger.Log(LogCategory.Error, ex); } catch (Exception ex) { _logger.Log(LogCategory.Error, new Exception("Failed to save Value Retail Routes in Db", ex)); } } } }
public async Task <SaveLocationReturnValues> SaveCityStateCountry(ValueRetailExpressData route, ValueRetailVillage village) { var locationData = await _googleMapApi.GetLocationFromLatLong(route.Latitude.ToString(), route.Longitude.ToString()); if (!locationData.Success) { throw new ArgumentNullException($"Failed to get Location Data in {this}"); } 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 = tempAltId, IsEnabled = true }); } var values = new SaveLocationReturnValues { cityName = city.Name, stateName = state.Name, countryName = country.Name, cityId = city.Id, currencyId = currencyType.Id, lat = locationData.Result.lat, lng = locationData.Result.lng }; return(values); }
public async Task SaveBlockedDates(ValueRetailExpressData valueRetailExpressRoute, Event @event, EventDetail eventDetail, ValueRetailVillage village) { var responseString = await _valueRetailAPI.GetValueRetailAPIData(new ValueRetailCommanRequestModel { villageCode = village.VillageCode, cultureCode = village.CultureCode, journeyType = valueRetailExpressRoute.JourneyType, routeId = valueRetailExpressRoute.RouteId, from = DateTime.UtcNow }, "Route", "ShoppingExpress"); var responseData = Mapper <ShoppingExpressRoute> .MapFromJson(responseString.Result); foreach (var date in responseData.Availability.BlockedDates) { var placeHoliDayDates = _placeHolidayDatesRepository.GetByEventandDate(@event.Id, Convert.ToDateTime(date)); placeHoliDayDates = _placeHolidayDatesRepository.Save(new PlaceHolidayDate { LeaveDateTime = Convert.ToDateTime(date), EventId = @event.Id, IsEnabled = true, EventDetailId = eventDetail.Id, ModifiedBy = tempAltId, CreatedBy = tempAltId, CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, UpdatedBy = tempAltId }); } }
public Event SaveToEvent(ValueRetailExpressData valueRetailExpressRoute, VillageDescription villageDescription, ValueRetailVillage village) { string eventName = $"Luxury Shopping Trip from {_toEnglishTranslator.TranslateToEnglish(valueRetailExpressRoute.Name)}"; var eventResult = new Event(); eventResult = _eventRepository.GetByEventName(eventName); if (eventResult == null) { eventResult = _eventRepository.Save(new Event { AltId = Guid.NewGuid(), Name = eventName, EventCategoryId = ValueRetailEventCategoryConstant.ShoppingPackageParentCategory, EventTypeId = EventType.Perennial, Description = villageDescription.desc.FirstOrDefault(x => x.name == village.VillageCode).description, ClientPointOfContactId = 2, FbEventId = null, MetaDetails = null, IsFeel = true, EventSourceId = EventSource.ValueRetail, TermsAndConditions = "", IsPublishedOnSite = true, PublishedDateTime = DateTime.Now, PublishedBy = null, TestedBy = null, Slug = valueRetailExpressRoute.Name.Replace(" ", "-"), IsEnabled = true, ModifiedBy = tempAltId, UpdatedBy = tempAltId, UpdatedUtc = DateTime.UtcNow, CreatedBy = tempAltId, CreatedUtc = DateTime.UtcNow }); var eventSiteIdMapping = _eventSiteIdMappingRepository.GetByEventId(eventResult.Id); if (eventSiteIdMapping == null) { _eventSiteIdMappingRepository.Save(new Contracts.DataModels.EventSiteIdMapping { EventId = eventResult.Id, SortOrder = 999, SiteId = Site.feelaplaceSite, ModifiedBy = tempAltId, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = tempAltId, UpdatedUtc = DateTime.UtcNow, UpdatedBy = tempAltId }); } var eventCategoryMapping = _eventCategoryMappingRepository.GetByEventId(eventResult.Id).FirstOrDefault(); if (eventCategoryMapping == null) { _eventCategoryMappingRepository.Save(new Contracts.DataModels.EventCategoryMapping { EventId = eventResult.Id, EventCategoryId = ValueRetailEventCategoryConstant.ShoppingPackageChildCategory, ModifiedBy = tempAltId, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = tempAltId, UpdatedUtc = DateTime.UtcNow, UpdatedBy = tempAltId }); } var days = _daysRepository.GetAll(); foreach (var day in days) { var placeweekOpenDays = _placeWeekOpenDaysRepository.GetByEventIdandDayId(eventResult.Id, day.Id); if (placeweekOpenDays == null) { placeweekOpenDays = _placeWeekOpenDaysRepository.Save(new PlaceWeekOpenDays { AltId = Guid.NewGuid(), EventId = eventResult.Id, DayId = day.Id, IsSameTime = false, ModifiedBy = tempAltId, IsEnabled = true, CreatedUtc = DateTime.UtcNow, CreatedBy = tempAltId, UpdatedUtc = DateTime.UtcNow, UpdatedBy = tempAltId }); } } } return(eventResult); }
public EventVenueMapping SaveToVenue(ShoppingPackageRouteDetail routeDetail, Event @event, SaveLocationReturnValues locationValues, ValueRetailVillage village) { try { var venue = _venueRepository.GetByVenueNameAndCityId(village.VillageName, locationValues.cityId); if (venue == null) { venue = _venueRepository.Save(new Venue { AltId = Guid.NewGuid(), Name = village.VillageName, AddressLineOne = "", AddressLineTwo = "", CityId = locationValues.cityId, Latitude = locationValues.lat.ToString(), Longitude = locationValues.lng.ToString(), ModifiedBy = @event.ModifiedBy, IsEnabled = true }); } var eventVenueMapping = _eventVenueMappingRepository.GetByEventIdAndVenueId(@event.Id, venue.Id); if (eventVenueMapping == null) { eventVenueMapping = _eventVenueMappingRepository.Save(new EventVenueMapping { EventId = @event.Id, VenueId = venue.Id, IsEnabled = true, CreatedUtc = DateTime.UtcNow, UpdatedUtc = null, CreatedBy = @event.ModifiedBy, UpdatedBy = null, ModifiedBy = @event.ModifiedBy }); } return(eventVenueMapping); } catch (Exception ex) { _logger.Log(Logging.Enums.LogCategory.Error, ex); return(new EventVenueMapping()); } }
public async Task <SaveLocationReturnValues> SaveCityStateCountry(ShoppingPackageRouteDetail routeDetail, ValueRetailVillage village) { var locationData = await _googleMapApi.GetLatLongFromAddress(village.VillageName); try { if (!locationData.Success) { throw new ArgumentNullException($"Failed to get Location Data in {this}"); } 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(Logging.Enums.LogCategory.Error, ex); return(new SaveLocationReturnValues()); } }
public Event SaveToEvent(ShoppingPackageRouteDetail routeDetail, ValueRetailVillage village) { string longDescription = StripText(routeDetail.RouteDetails.Package.LongDescription), redemption = StripText(routeDetail.RouteDetails.Package.Redemption), restriction = StripText(routeDetail.RouteDetails.Package.Restriction); string originalEventName = _toEnglishTranslator.TranslateToEnglish(routeDetail.RouteDetails.Package.PackageName); string customEventName = originalEventName.ToLower().Contains("village") ? originalEventName : $"{originalEventName} at {village.VillageName}"; var @event = new Event { AltId = Guid.NewGuid(), Name = customEventName, EventCategoryId = ValueRetailEventCategoryConstant.ShoppingPackageParentCategory, EventTypeId = EventType.Perennial, Description = $"<p>{ _toEnglishTranslator.TranslateToEnglish(longDescription)}</p><p>{_toEnglishTranslator.TranslateToEnglish(redemption)}</p><p>{_toEnglishTranslator.TranslateToEnglish(restriction) }</p>", ClientPointOfContactId = 2, FbEventId = null, MetaDetails = null, IsFeel = true, EventSourceId = EventSource.ValueRetail, TermsAndConditions = "", IsPublishedOnSite = true, PublishedDateTime = DateTime.Now, PublishedBy = null, TestedBy = null, Slug = $"shopping-package-{routeDetail.RouteDetails.Package.PackageID}".ToLower(), ModifiedBy = Guid.NewGuid(), IsEnabled = true, UpdatedUtc = DateTime.Now, UpdatedBy = Guid.NewGuid() }; try { var eventResult = _eventRepository.GetByEventName(@event.Name); if (eventResult == null) { eventResult = _eventRepository.Save(@event); } var eventSiteIdMapping = _eventSiteIdMappingRepository.GetByEventId(eventResult.Id); if (eventSiteIdMapping == null) { _eventSiteIdMappingRepository.Save(new Contracts.DataModels.EventSiteIdMapping { EventId = eventResult.Id, SortOrder = 999, SiteId = Site.feelaplaceSite, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } var eventCategoryMapping = _eventCategoryMappingRepository.GetByEventId(eventResult.Id).FirstOrDefault(); if (eventCategoryMapping == null) { _eventCategoryMappingRepository.Save(new Contracts.DataModels.EventCategoryMapping { EventId = eventResult.Id, EventCategoryId = ValueRetailEventCategoryConstant.ShoppingPackageChildCategory, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } var days = _daysRepository.GetAll(); //Save Open days and Timing foreach (var day in days) { var placeweekOpenDays = _placeWeekOpenDaysRepository.GetByEventIdandDayId(eventResult.Id, day.Id); if (placeweekOpenDays == null) { placeweekOpenDays = _placeWeekOpenDaysRepository.Save(new PlaceWeekOpenDays { AltId = Guid.NewGuid(), EventId = eventResult.Id, DayId = day.Id, IsSameTime = false, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } } return(eventResult); } catch (Exception ex) { _logger.Log(Logging.Enums.LogCategory.Error, ex); return(new Event()); } }
public Event SaveToEvent(ChauffeurRoute route, ValueRetailVillage valueRetailVillage) { var eventName = CheckAndTranslateLanguage(route.ServiceType); var @event = new Event { AltId = Guid.NewGuid(), Name = $"Chauffeur {eventName} from {route.LocationHeader} to {valueRetailVillage.VillageName}", EventCategoryId = ValueRetailEventCategoryConstant.ShoppingPackageParentCategory, EventTypeId = EventType.Perennial, Description = $"<p>{CheckAndTranslateLanguage(route.ServiceDescription)}</p>", ClientPointOfContactId = 2, FbEventId = null, MetaDetails = null, IsFeel = true, EventSourceId = EventSource.ValueRetail, TermsAndConditions = "", IsPublishedOnSite = true, PublishedDateTime = DateTime.Now, PublishedBy = null, TestedBy = null, Slug = $"{eventName} {route.LocationHeader}".Replace(" ", "-"), ModifiedBy = Guid.NewGuid(), IsEnabled = true }; try { var eventResult = _eventRepository.GetByEventName(@event.Name); if (eventResult == null) { eventResult = _eventRepository.Save(@event); } var eventSiteIdMapping = _eventSiteIdMappingRepository.GetByEventId(eventResult.Id); if (eventSiteIdMapping == null) { eventSiteIdMapping = _eventSiteIdMappingRepository.Save(new Contracts.DataModels.EventSiteIdMapping { EventId = eventResult.Id, SortOrder = 999, SiteId = Site.feelaplaceSite, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } var eventCategoryMapping = _eventCategoryMappingRepository.GetByEventId(eventResult.Id).FirstOrDefault(); if (eventCategoryMapping == null) { _eventCategoryMappingRepository.Save(new Contracts.DataModels.EventCategoryMapping { EventId = eventResult.Id, EventCategoryId = ValueRetailEventCategoryConstant.ChauffeurDriveChildCategory, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } var days = _daysRepository.GetAll(); foreach (var day in days) { var placeweekOpenDays = _placeWeekOpenDaysRepository.GetByEventIdandDayId(eventResult.Id, day.Id); if (placeweekOpenDays == null) { placeweekOpenDays = _placeWeekOpenDaysRepository.Save(new PlaceWeekOpenDays { AltId = Guid.NewGuid(), EventId = eventResult.Id, DayId = day.Id, IsSameTime = false, ModifiedBy = eventResult.ModifiedBy, IsEnabled = true }); } } return(eventResult); } catch (Exception ex) { _logger.Log(LogCategory.Error, ex); return(new Event()); } }