47 lines
2.0 KiB
C#
47 lines
2.0 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 ShippingDbTable : MgDbTableBase<Shipping>
|
|
{
|
|
public ShippingDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
|
{
|
|
}
|
|
|
|
public override IOrderedQueryable<Shipping> GetAll()
|
|
=> base.GetAll().OrderBy(s => s.ShippingDate);
|
|
|
|
public IQueryable<Shipping> GetAll(bool loadRelations)
|
|
{
|
|
return loadRelations
|
|
? GetAll()
|
|
.LoadWith(s => s.ShippingDocuments).ThenLoad(sd => sd.ShippingItems).ThenLoad(si => si.ShippingItemPallets)
|
|
.LoadWith(s => s.ShippingDocuments).ThenLoad(sd => sd.ShippingItems).ThenLoad(si => si.Pallet)
|
|
.LoadWith(s => s.ShippingDocuments).ThenLoad(sd => sd.ShippingItems).ThenLoad(si => si.Product)
|
|
.LoadWith(s => s.ShippingDocuments).ThenLoad(sd => sd.ShippingDocumentToFiles).ThenLoad(sdtof => sdtof.ShippingDocumentFile)
|
|
.LoadWith(s => s.ShippingDocuments).ThenLoad(sd => sd.Partner)
|
|
: GetAll();
|
|
}
|
|
|
|
public IQueryable<Shipping> GetAllNotMeasured(bool loadRelations)
|
|
=> GetAll(loadRelations).Where(s => !s.IsAllMeasured || s.MeasuredDate == null || s.MeasuredDate < DateTime.Now.AddDays(1000));
|
|
|
|
|
|
public Task<Shipping> GetByIdAsync(int id, bool loadRelations)
|
|
=> GetAll(loadRelations).FirstOrDefaultAsync(s => s.Id == id);
|
|
|
|
protected override void OnUpdate(Shipping entity)
|
|
{
|
|
if (entity is { IsAllMeasured: true, MeasuredDate: null }) entity.MeasuredDate = DateTime.Now;
|
|
|
|
base.OnUpdate(entity);
|
|
}
|
|
} |