using FruitBank.Common.Entities; using FruitBank.Common.Enums; using LinqToDB; using Mango.Nop.Core.Loggers; using Mango.Nop.Data.Repositories; using Nop.Core.Caching; using Nop.Core.Configuration; using Nop.Core.Events; using Nop.Data; namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer; public class PreOrderDbTable : MgDbTableBase { public PreOrderDbTable( IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings) : base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings) { } public IQueryable GetAll(bool loadRelations) { return loadRelations ? GetAll() .LoadWith(p => p.PreOrderItems) : GetAll(); } public Task GetByIdAsync(int id, bool loadRelations) => GetAll(loadRelations).FirstOrDefaultAsync(p => p.Id == id); public IQueryable GetAllByCustomerIdAsync(int customerId, bool loadRelations) => GetAll(loadRelations).Where(p => p.CustomerId == customerId); public IQueryable GetAllPendingAsync(bool loadRelations) { // Filter on the mapped StatusId column — Status is [NotColumn] and not SQL-translatable. var pendingStatusIds = new[] { (int)PreOrderStatus.Pending, (int)PreOrderStatus.PartiallyFulfilled }; return GetAll(loadRelations).Where(p => pendingStatusIds.Contains(p.StatusId)); } }