Browse Source

Overriding `ApplySorting` methods

pull/169/head
gdlcf88 4 years ago
parent
commit
ffb017973f
  1. 19
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs
  2. 7
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs
  3. 29
      modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs

19
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/ProductCategories/ProductCategoryAppService.cs

@ -8,11 +8,12 @@ using Volo.Abp.Application.Services;
namespace EasyAbp.EShop.Products.ProductCategories
{
public class ProductCategoryAppService : ReadOnlyAppService<ProductCategory, ProductCategoryDto, Guid, GetProductCategoryListDto>,
public class ProductCategoryAppService :
ReadOnlyAppService<ProductCategory, ProductCategoryDto, Guid, GetProductCategoryListDto>,
IProductCategoryAppService
{
protected override string GetListPolicyName { get; set; } = ProductsPermissions.Products.Manage;
private readonly IProductCategoryRepository _repository;
public ProductCategoryAppService(IProductCategoryRepository repository) : base(repository)
@ -20,10 +21,11 @@ namespace EasyAbp.EShop.Products.ProductCategories
_repository = repository;
}
protected override async Task<IQueryable<ProductCategory>> CreateFilteredQueryAsync(GetProductCategoryListDto input)
protected override async Task<IQueryable<ProductCategory>> CreateFilteredQueryAsync(
GetProductCategoryListDto input)
{
var queryable = await Repository.GetQueryableAsync();
if (input.CategoryId.HasValue)
{
queryable = queryable.Where(x => x.CategoryId == input.CategoryId);
@ -34,11 +36,16 @@ namespace EasyAbp.EShop.Products.ProductCategories
queryable = queryable.Where(x => x.ProductId == input.ProductId);
}
queryable = queryable.OrderBy(x => x.DisplayOrder);
return queryable;
}
protected override IQueryable<ProductCategory> ApplySorting(IQueryable<ProductCategory> query,
GetProductCategoryListDto input)
{
return base.ApplySorting(query, input)
.OrderBy(x => x.DisplayOrder);
}
[RemoteService(false)]
public override Task<ProductCategoryDto> GetAsync(Guid id)
{

7
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductAppService.cs

@ -61,7 +61,12 @@ namespace EasyAbp.EShop.Products.Products
return query
.Where(x => x.StoreId == input.StoreId)
.WhereIf(!input.ShowHidden, x => !x.IsHidden)
.WhereIf(!input.ShowUnpublished, x => x.IsPublished)
.WhereIf(!input.ShowUnpublished, x => x.IsPublished);
}
protected override IQueryable<Product> ApplySorting(IQueryable<Product> query, GetProductListInput input)
{
return base.ApplySorting(query, input)
.OrderBy(x => x.DisplayOrder);
}

29
modules/EasyAbp.EShop.Products/src/EasyAbp.EShop.Products.Application/EasyAbp/EShop/Products/Products/ProductViewAppService.cs

@ -15,7 +15,8 @@ using Volo.Abp.Uow;
namespace EasyAbp.EShop.Products.Products
{
public class ProductViewAppService : MultiStoreReadOnlyAppService<ProductView, ProductViewDto, Guid, GetProductListInput>,
public class ProductViewAppService :
MultiStoreReadOnlyAppService<ProductView, ProductViewDto, Guid, GetProductListInput>,
IProductViewAppService
{
protected override string GetPolicyName { get; set; } = null;
@ -27,7 +28,7 @@ namespace EasyAbp.EShop.Products.Products
private readonly IProductManager _productManager;
private readonly IProductRepository _productRepository;
private readonly IProductViewRepository _repository;
public ProductViewAppService(
IProductViewCacheKeyProvider productViewCacheKeyProvider,
IDistributedCache<ProductViewCacheItem> cache,
@ -41,7 +42,7 @@ namespace EasyAbp.EShop.Products.Products
_productRepository = productRepository;
_repository = repository;
}
protected override async Task<IQueryable<ProductView>> CreateFilteredQueryAsync(GetProductListInput input)
{
var query = input.CategoryId.HasValue
@ -51,14 +52,20 @@ namespace EasyAbp.EShop.Products.Products
return query
.Where(x => x.StoreId == input.StoreId)
.WhereIf(!input.ShowHidden, x => !x.IsHidden)
.WhereIf(!input.ShowUnpublished, x => x.IsPublished)
.WhereIf(!input.ShowUnpublished, x => x.IsPublished);
}
protected override IQueryable<ProductView> ApplySorting(IQueryable<ProductView> query,
GetProductListInput input)
{
return base.ApplySorting(query, input)
.OrderBy(x => x.DisplayOrder);
}
public override async Task<PagedResultDto<ProductViewDto>> GetListAsync(GetProductListInput input)
{
await CheckGetListPolicyAsync();
if (input.ShowHidden || input.ShowUnpublished)
{
await CheckMultiStorePolicyAsync(input.StoreId, ProductsPermissions.Products.Manage);
@ -68,7 +75,7 @@ namespace EasyAbp.EShop.Products.Products
{
await BuildStoreProductViewsAsync(input.StoreId);
}
var query = await CreateFilteredQueryAsync(input);
var totalCount = await AsyncExecuter.CountAsync(query);
@ -104,7 +111,7 @@ namespace EasyAbp.EShop.Products.Products
await BuildStoreProductViewsAsync(productView.StoreId);
productView = await GetEntityByIdAsync(id);
return await MapToGetOutputDtoAsync(productView);
}
@ -121,7 +128,7 @@ namespace EasyAbp.EShop.Products.Products
var productView = ObjectMapper.Map<Product, ProductView>(product);
await FillPriceInfoWithRealPriceAsync(product, productView);
await _repository.InsertAsync(productView);
}
@ -135,7 +142,7 @@ namespace EasyAbp.EShop.Products.Products
await SettingProvider.GetOrNullAsync(ProductsSettings.ProductView.CacheDurationSeconds)))
});
}
protected virtual async Task FillPriceInfoWithRealPriceAsync(Product product, ProductView productView)
{
if (product.ProductSkus.IsNullOrEmpty())
@ -144,7 +151,7 @@ namespace EasyAbp.EShop.Products.Products
}
decimal? min = null, max = null;
foreach (var productSku in product.ProductSkus)
{
var priceDataModel = await _productManager.GetRealPriceAsync(product, productSku);
@ -163,4 +170,4 @@ namespace EasyAbp.EShop.Products.Products
productView.SetPrices(min, max);
}
}
}
}
Loading…
Cancel
Save