public async Task FetchAndStore() { Expression <Func <HotTourView, HotTourViewDto> > projection = hotTourView => new HotTourViewDto { Name = hotTourView.Name, PriceAmount = hotTourView.PriceAmount, DepartureLocationId = hotTourView.DepartureLocationId, DepartureDate = hotTourView.DepartureDate }; var projectedQueryParams = new ProjectedQueryParams <HotTourView, HotTourViewDto> { Projection = projection }; var providerQuery = new HotToursProviderQuery { DurationFrom = 1, DurationTo = 21, PriceFrom = 1, PriceTo = 200000, Count = 1000 }; var newTours = await _toursProvider.GetHotToursAsync(providerQuery); var existingTours = await _repository.GetAllAsync(projectedQueryParams); var uniqueTours = newTours .Where(n => existingTours.All(e => e.Name != n.Info.Name || e.Name == n.Info.Name && e.PriceAmount != n.Price.Amount || e.Name == n.Info.Name && e.DepartureLocationId != n.DepartureLocation.Id || e.Name == n.Info.Name && e.DepartureDate != n.DepartureDate)) .ToList(); _unitOfWork.HotToursWriteRepository.SaveRange(uniqueTours); var deleteResult = await _cache.CleanAsync(); if (deleteResult.IsFailure) { _logger.LogCritical(deleteResult.Error); } await _unitOfWork.CommitAsync(); _logger.LogInformation($"Fetched {newTours.Count} and stored {uniqueTours.Count} tours."); }
public HotToursRequest(HotToursProviderQuery providerQuery) { CountryIds = string.Empty; ResortIds = string.Empty; DepartureIds = string.Empty; HotelCategoryIds = string.Empty; BoardIds = string.Empty; RestTypeIds = string.Empty; DateFrom = DateTime.Now.ToString("dd-MM-yyyy"); DateTo = DateTime.Now.AddYears(1).ToString("dd-MM-yyyy"); DurationQtyDayFrom = providerQuery.DurationFrom; DurationQtyDayTo = providerQuery.DurationTo; PriceFrom = providerQuery.PriceFrom; PriceTo = providerQuery.PriceTo; LanguageId = 2; CurrentPage = 1; PageSize = providerQuery.Count; SortId = 0; }