37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using FruitBank.Common.Entities;
|
|
using FruitBank.Common.Enums;
|
|
using LinqToDB;
|
|
using Mango.Nop.Data.Repositories;
|
|
using Nop.Core.Caching;
|
|
using Nop.Core.Configuration;
|
|
using Nop.Core.Events;
|
|
using Nop.Data;
|
|
using Mango.Nop.Core.Loggers;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
|
|
|
public class OrderDraftDbTable : MgDbTableBase<OrderDraft>
|
|
{
|
|
public OrderDraftDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings)
|
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
|
{
|
|
}
|
|
|
|
public IQueryable<OrderDraft> GetAll(bool loadRelations)
|
|
{
|
|
return loadRelations
|
|
? GetAll().LoadWith(d => d.Items)
|
|
: GetAll();
|
|
}
|
|
|
|
public Task<OrderDraft?> GetByIdAsync(int id, bool loadRelations)
|
|
=> GetAll(loadRelations).FirstOrDefaultAsync(d => d.Id == id);
|
|
|
|
public IQueryable<OrderDraft> GetPending()
|
|
=> GetAll().Where(d => d.Status == OrderDraftStatus.Pending);
|
|
|
|
public IQueryable<OrderDraft> GetExpiredCandidates()
|
|
=> GetAll().Where(d => d.Status == OrderDraftStatus.Pending
|
|
&& d.CreatedOnUtc <= DateTime.UtcNow.AddDays(-14));
|
|
}
|