43 lines
1.5 KiB
C#
43 lines
1.5 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 PreorderItemDbTable : MgDbTableBase<PreorderItem>
|
|
{
|
|
public PreorderItemDbTable(
|
|
IEventPublisher eventPublisher,
|
|
INopDataProvider dataProvider,
|
|
IShortTermCacheManager shortTermCacheManager,
|
|
IStaticCacheManager staticCacheManager,
|
|
AppSettings appSettings)
|
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings)
|
|
{
|
|
}
|
|
|
|
public IQueryable<PreorderItem> GetAllByPreorderIdAsync(int preorderId)
|
|
=> GetAll().Where(i => i.PreorderId == preorderId);
|
|
|
|
public IQueryable<PreorderItem> GetAllByProductIdAsync(int productId)
|
|
=> GetAll().Where(i => i.ProductId == productId);
|
|
|
|
/// <summary>
|
|
/// All pending/partially-fulfilled items for a product, ordered by their parent preorder's
|
|
/// CreatedOnUtc for first-come-first-served allocation.
|
|
/// </summary>
|
|
public IQueryable<PreorderItem> GetPendingByProductIdOrderedAsync(int productId)
|
|
{
|
|
var pendingStatuses = new[] { PreorderItemStatus.Pending, PreorderItemStatus.PartiallyFulfilled };
|
|
return GetAll()
|
|
.Where(i => i.ProductId == productId && pendingStatuses.Contains(i.Status))
|
|
.OrderBy(i => i.PreorderId);
|
|
}
|
|
}
|