Mango.Nop.Plugins/Nop.Plugin.Misc.AIPlugin/Domains/DataLayer/StockQuantityHistoryDtoDbTa...

37 lines
1.5 KiB
C#

using FruitBank.Common.Dtos;
using FruitBank.Common.Entities;
using LinqToDB;
using Mango.Nop.Core.Entities;
using Mango.Nop.Core.Loggers;
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 System.Linq.Expressions;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class StockQuantityHistoryDtoDbTable : MgDtoDbTableBase<StockQuantityHistoryDto, StockQuantityHistory>
{
public StockQuantityHistoryDtoDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
{
}
public override IQueryable<StockQuantityHistoryDto> GetAll() => base.GetAll().LoadWith(sqh => sqh.StockQuantityHistoryExt);
public IQueryable<StockQuantityHistoryDto> GetAll(bool loadProductRelation)
{
return loadProductRelation
? GetAll().LoadWith(sqh => sqh.ProductDto).ThenLoad(p => p.GenericAttributes)
: GetAll();
}
public Task<StockQuantityHistoryDto> GetByIdAsync(int id, bool loadProductRelation)
=> GetAll(loadProductRelation).FirstOrDefaultAsync(p => p.Id == id);
public IQueryable<StockQuantityHistoryDto> GetByProductIdAsync(int productId, bool loadProductRelation)
=> GetAll(loadProductRelation).Where(p => p.ProductId == productId);
}