Mango.Nop.Plugins/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/ProductDtoDbTable.cs

29 lines
1.3 KiB
C#

using FruitBank.Common.Dtos;
using LinqToDB;
using Mango.Nop.Data.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Domain.Catalog;
using Nop.Core.Events;
using Nop.Data;
using Mango.Nop.Core.Loggers;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class ProductDtoDbTable : MgDtoDbTableBase<ProductDto, Product>
{
public ProductDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
{
}
public IQueryable<ProductDto> GetAll(bool loadRelations, bool includeDeleted = false)
{
return GetAll().Where(p => includeDeleted || !p.Deleted)
.LoadWith(p => p.GenericAttributes);
}
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, bool includeDeleted = false) => GetAll(loadRelations).Where(p => productIds.Contains(p.Id));
}