diff --git a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs index 605ea48..4a32beb 100644 --- a/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs +++ b/Nop.Plugin.Misc.AIPlugin/Controllers/FruitBankDataController.cs @@ -249,21 +249,21 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers public async Task> GetProductDtos() { _logger.Detail($"GetProductDtos invoked"); - return await ctx.GetAllProductDtos(false).ToListAsync(); + return await ctx.ProductDtos.GetAll(false).ToListAsync(); } - [SignalR(SignalRTags.GetAllMeasuringProductDtos)] - public async Task> GetAllMeasuringProductDtos() - { - _logger.Detail($"GetAllMeasuringProductDtos invoked"); - return await ctx.GetAllMeasuringProductDtos(false).ToListAsync(); - } + //[SignalR(SignalRTags.GetAllMeasuringProductDtos)] + //public async Task> GetAllMeasuringProductDtos() + //{ + // _logger.Detail($"GetAllMeasuringProductDtos invoked"); + // return await ctx.GetAllMeasuringProductDtos(false).ToListAsync(); + //} [SignalR(SignalRTags.GetMeasuringProductDtoById)] - public async Task GetMeasuringProductDtoById(int productId) + public async Task GetProductDtoById(int productId) { - _logger.Detail($"GetMeasuringProductDtoById invoked; productId: {productId}"); - return await ctx.GetMeasuringProductDtoByIdAsync(productId); + _logger.Detail($"GetProductDtoById invoked; productId: {productId}"); + return await ctx.ProductDtos.GetByIdAsync(productId, true); } [SignalR(SignalRTags.AuthenticateUser)] diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs index e2486e2..fecb101 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/FruitBankDbContext.cs @@ -119,20 +119,20 @@ public class FruitBankDbContext : MgDbContextBase, return query.Distinct(); } - public IQueryable GetAllProducts(bool includeDeleted) - => Products.Table.Where(p => includeDeleted || !p.Deleted).OrderBy(o => o.Name); + //public IQueryable GetAllProducts(bool includeDeleted) + // => Products.Table.Where(p => includeDeleted || !p.Deleted).OrderBy(o => o.Name); - public IQueryable GetAllProductDtos(bool includeDeleted) - => GetAllProducts(includeDeleted).Select(product => new ProductDto(product)); + //public IQueryable GetAllProductDtos(bool includeDeleted) + // => GetAllProducts(includeDeleted).Select(product => new ProductDto(product)); - public IAsyncEnumerable GetAllMeasuringProductDtos(bool includeDeleted) - => GetAllProducts(includeDeleted).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))); + //public IAsyncEnumerable GetAllMeasuringProductDtos(bool includeDeleted) + // => GetAllProducts(includeDeleted).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))); - public async Task GetMeasuringProductDtoByIdAsync(int productId) - => await Products.Table.Where(product => product.Id == productId).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync(); + //public async Task GetMeasuringProductDtoByIdAsync(int productId) + // => await Products.Table.Where(product => product.Id == productId).AsEnumerable().SelectAwait(async product => new MeasuringProductDto(product, await GetMeasuringAttributeValuesByProductIdAsync(product.Id))).FirstOrDefaultAsync(); - public async Task GetMeasuringAttributeValuesByProductIdAsync(int productId) - => await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync(productId); + //public async Task GetMeasuringAttributeValuesByProductIdAsync(int productId) + // => await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync(productId); public async Task DeleteShippingSafeAsync(Shipping shipping) { diff --git a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/ProductDtoDbTable.cs b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/ProductDtoDbTable.cs index ad69ff8..a48afe3 100644 --- a/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/ProductDtoDbTable.cs +++ b/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/ProductDtoDbTable.cs @@ -17,12 +17,13 @@ public class ProductDtoDbTable : MgDtoDbTableBase { } - public IQueryable GetAll(bool loadRelations) + public IQueryable 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 GetByIdAsync(int productId, bool loadRelations) => GetAll(loadRelations).Where(x => x.Id == productId).FirstOrDefaultAsync(null); + public Task GetByIdAsync(int productId, bool loadRelations, bool includeDeleted = false) => GetAll(loadRelations).Where(x => x.Id == productId).FirstOrDefaultAsync(null); - public IQueryable GetAllByIds(IEnumerable productIds, bool loadRelations = true) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id)); + public IQueryable GetAllByIds(IEnumerable productIds, bool loadRelations = true, bool includeDeleted = false) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id)); } \ No newline at end of file