Exemplo n.º 1
0
        protected virtual async Task BuildStoreProductViewsAsync(Guid storeId)
        {
            var products = await _productRepository.GetListAsync(x => x.StoreId == storeId, true);

            using var uow = UnitOfWorkManager.Begin(true, true);

            await _repository.DeleteAsync(x => x.StoreId == storeId, true);

            foreach (var product in products)
            {
                var productView = ObjectMapper.Map <Product, ProductView>(product);

                await FillPriceInfoWithRealPriceAsync(product, productView);

                await _repository.InsertAsync(productView);
            }

            await uow.SaveChangesAsync();

            await uow.CompleteAsync();

            await _cache.SetAsync(await GetCacheKeyAsync(storeId), new ProductViewCacheItem(),
                                  new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(Convert.ToInt32(
                                                                           await SettingProvider.GetOrNullAsync(ProductsSettings.ProductView.CacheDurationSeconds)))
            });
        }
Exemplo n.º 2
0
        protected virtual async Task BuildStoreProductViewsAsync(Guid storeId)
        {
            var resultDto = await _productAppService.GetListAsync(new GetProductListInput
            {
                StoreId = storeId
            });

            using var uow = UnitOfWorkManager.Begin(true, true);

            await _repository.DeleteAsync(x => x.StoreId == storeId, true);

            foreach (var product in resultDto.Items)
            {
                await _repository.InsertAsync(ObjectMapper.Map <ProductDto, ProductView>(product));
            }

            await uow.CompleteAsync();

            await _cache.SetAsync(await GetCacheKeyAsync(storeId), new ProductViewCacheItem(),
                                  new DistributedCacheEntryOptions
            {
                AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(Convert.ToInt32(
                                                                           await SettingProvider.GetOrNullAsync(ProductsSettings.ProductView.CacheDurationSeconds)))
            });
        }