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; using static LinqToDB.Reflection.Methods.LinqToDB.Insert; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; public class ShippingDbTable : MgDbTableBase { public ShippingDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger) { } public override IOrderedQueryable GetAll() => base.GetAll().OrderBy(s => s.ShippingDate); public IQueryable 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 GetAllNotMeasured(bool loadRelations) => GetAll(loadRelations).Where(s => !s.IsAllMeasured || s.MeasuredDate == null || s.MeasuredDate < DateTime.Now.AddDays(1000)); public Task 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); } }