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

44 lines
1.7 KiB
C#

using FruitBank.Common.Entities;
using LinqToDB;
using Mango.Nop.Core.Repositories;
using Nop.Core.Caching;
using Nop.Core.Configuration;
using Nop.Core.Events;
using Nop.Data;
using Nop.Services.Logging;
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
{
public ShippingItemDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
{
}
public override IQueryable<ShippingItem> GetAll()
=> base.GetAll();
public IQueryable<ShippingItem> GetAll(bool loadRelations)
{
return loadRelations
? GetAll()
.LoadWith(sd => sd.ShippingDocument).ThenLoad(s => s.Shipping)
.LoadWith(sd => sd.ShippingDocument).ThenLoad(p => p.Partner)
: GetAll();
}
public IQueryable<ShippingItem> GetAllNotMeasured(bool loadRelations)
=> GetAll(loadRelations).Where(si => !si.IsMeasured);
public Task<ShippingItem> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(si => si.Id == id);
public IQueryable<ShippingItem> GetAllByProductIdAsync(int productid, bool loadRelations)
=> GetAll(loadRelations).Where(si => si.ProductId == productid);
public IQueryable<ShippingItem> GetAllByShippingDocumentIdAsync(int shippingDocumentId, bool loadRelations)
=> GetAll(loadRelations).Where(si => si.ShippingDocumentId == shippingDocumentId);
}