This commit is contained in:
Loretta 2025-10-19 13:56:36 +02:00
parent 254211459f
commit a8a84def54
3 changed files with 25 additions and 24 deletions

View File

@ -249,21 +249,21 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
public async Task<List<ProductDto>> GetProductDtos() public async Task<List<ProductDto>> GetProductDtos()
{ {
_logger.Detail($"GetProductDtos invoked"); _logger.Detail($"GetProductDtos invoked");
return await ctx.GetAllProductDtos(false).ToListAsync(); return await ctx.ProductDtos.GetAll(false).ToListAsync();
} }
[SignalR(SignalRTags.GetAllMeasuringProductDtos)] //[SignalR(SignalRTags.GetAllMeasuringProductDtos)]
public async Task<List<MeasuringProductDto>> GetAllMeasuringProductDtos() //public async Task<List<MeasuringProductDto>> GetAllMeasuringProductDtos()
{ //{
_logger.Detail($"GetAllMeasuringProductDtos invoked"); // _logger.Detail($"GetAllMeasuringProductDtos invoked");
return await ctx.GetAllMeasuringProductDtos(false).ToListAsync(); // return await ctx.GetAllMeasuringProductDtos(false).ToListAsync();
} //}
[SignalR(SignalRTags.GetMeasuringProductDtoById)] [SignalR(SignalRTags.GetMeasuringProductDtoById)]
public async Task<MeasuringProductDto?> GetMeasuringProductDtoById(int productId) public async Task<ProductDto?> GetProductDtoById(int productId)
{ {
_logger.Detail($"GetMeasuringProductDtoById invoked; productId: {productId}"); _logger.Detail($"GetProductDtoById invoked; productId: {productId}");
return await ctx.GetMeasuringProductDtoByIdAsync(productId); return await ctx.ProductDtos.GetByIdAsync(productId, true);
} }
[SignalR(SignalRTags.AuthenticateUser)] [SignalR(SignalRTags.AuthenticateUser)]

View File

@ -119,20 +119,20 @@ public class FruitBankDbContext : MgDbContextBase,
return query.Distinct(); return query.Distinct();
} }
public IQueryable<Product> GetAllProducts(bool includeDeleted) //public IQueryable<Product> GetAllProducts(bool includeDeleted)
=> Products.Table.Where(p => includeDeleted || !p.Deleted).OrderBy(o => o.Name); // => Products.Table.Where(p => includeDeleted || !p.Deleted).OrderBy(o => o.Name);
public IQueryable<ProductDto> GetAllProductDtos(bool includeDeleted) //public IQueryable<ProductDto> GetAllProductDtos(bool includeDeleted)
=> GetAllProducts(includeDeleted).Select(product => new ProductDto(product)); // => GetAllProducts(includeDeleted).Select(product => new ProductDto(product));
public IAsyncEnumerable<MeasuringProductDto> GetAllMeasuringProductDtos(bool includeDeleted) //public IAsyncEnumerable<MeasuringProductDto> GetAllMeasuringProductDtos(bool includeDeleted)
=> GetAllProducts(includeDeleted).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))); // => GetAllProducts(includeDeleted).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id)));
public async Task<MeasuringProductDto?> GetMeasuringProductDtoByIdAsync(int productId) //public async Task<MeasuringProductDto?> GetMeasuringProductDtoByIdAsync(int productId)
=> await Products.Table.Where(product => product.Id == productId).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync(); // => await Products.Table.Where(product => product.Id == productId).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync();
public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesByProductIdAsync(int productId) //public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesByProductIdAsync(int productId)
=> await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync<Product>(productId); // => await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync<Product>(productId);
public async Task DeleteShippingSafeAsync(Shipping shipping) public async Task DeleteShippingSafeAsync(Shipping shipping)
{ {

View File

@ -17,12 +17,13 @@ public class ProductDtoDbTable : MgDtoDbTableBase<ProductDto, Product>
{ {
} }
public IQueryable<ProductDto> GetAll(bool loadRelations) public IQueryable<ProductDto> GetAll(bool loadRelations, bool includeDeleted = false)
{ {
return GetAll().LoadWith(p => p.GenericAttributes); return GetAll().Where(p => includeDeleted || !p.Deleted)
.LoadWith(p => p.GenericAttributes);
} }
public Task<ProductDto> GetByIdAsync(int productId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == productId).FirstOrDefaultAsync(null); public Task<ProductDto> GetByIdAsync(int productId, bool loadRelations, bool includeDeleted = false) => GetAll(loadRelations).Where(x => x.Id == productId).FirstOrDefaultAsync(null);
public IQueryable<ProductDto> GetAllByIds(IEnumerable<int> productIds, bool loadRelations = true) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id)); public IQueryable<ProductDto> GetAllByIds(IEnumerable<int> productIds, bool loadRelations = true, bool includeDeleted = false) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id));
} }