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

45 lines
1.4 KiB
C#

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<Preorder>
{
public PreorderDbTable(
IEventPublisher eventPublisher,
INopDataProvider dataProvider,
IShortTermCacheManager shortTermCacheManager,
IStaticCacheManager staticCacheManager,
AppSettings appSettings)
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
{
}
public IQueryable<Preorder> GetAll(bool loadRelations)
{
return loadRelations
? GetAll()
.LoadWith(p => p.PreorderItems)
: GetAll();
}
public Task<Preorder?> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(p => p.Id == id);
public IQueryable<Preorder> GetAllByCustomerIdAsync(int customerId, bool loadRelations)
=> GetAll(loadRelations).Where(p => p.CustomerId == customerId);
public IQueryable<Preorder> GetAllPendingAsync(bool loadRelations)
{
var pendingStatuses = new[] { PreorderStatus.Pending, PreorderStatus.PartiallyFulfilled };
return GetAll(loadRelations).Where(p => pendingStatuses.Contains(p.Status));
}
}