62 lines
2.4 KiB
C#
62 lines
2.4 KiB
C#
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;
|
|
|
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
|
|
|
public class ShippingItemDbTable : MgDbTableBase<ShippingItem>
|
|
{
|
|
public ShippingItemDbTable(IEventPublisher eventPublisher, INopDataProvider dataProvider, IShortTermCacheManager shortTermCacheManager, IStaticCacheManager staticCacheManager, AppSettings appSettings, ILogger logger)
|
|
: base(eventPublisher, dataProvider, shortTermCacheManager, staticCacheManager, appSettings, logger)
|
|
{
|
|
}
|
|
|
|
protected override void OnUpdate(ShippingItem entity)
|
|
{
|
|
RoundMeasuredValue(entity);
|
|
base.OnUpdate(entity);
|
|
}
|
|
|
|
protected override void OnInsert(ShippingItem entity)
|
|
{
|
|
RoundMeasuredValue(entity);
|
|
base.OnInsert(entity);
|
|
}
|
|
|
|
public override IQueryable<ShippingItem> GetAll() => base.GetAll();
|
|
|
|
public IQueryable<ShippingItem> GetAll(bool loadRelations)
|
|
{
|
|
return loadRelations
|
|
? GetAll()
|
|
.LoadWith(si => si.ShippingDocument).ThenLoad(s => s.Shipping)
|
|
.LoadWith(si => si.ShippingDocument).ThenLoad(p => p.Partner)
|
|
.LoadWith(si => si.Product)
|
|
: GetAll();
|
|
}
|
|
|
|
public IQueryable<ShippingItem> GetAllNotMeasured(bool loadRelations)
|
|
=> GetAll(loadRelations).Where(si => !si.IsMeasured);
|
|
|
|
|
|
public Task<ShippingItem> GetByIdAsync(int id, bool loadRelations)
|
|
=> GetAll(loadRelations).FirstOrDefaultAsync(si => si.Id == id);
|
|
|
|
public IQueryable<ShippingItem> GetAllByProductIdAsync(int productid, bool loadRelations)
|
|
=> GetAll(loadRelations).Where(si => si.ProductId == productid);
|
|
|
|
public IQueryable<ShippingItem> GetAllByShippingDocumentIdAsync(int shippingDocumentId, bool loadRelations)
|
|
=> GetAll(loadRelations).Where(si => si.ShippingDocumentId == shippingDocumentId);
|
|
|
|
private static void RoundMeasuredValue(ShippingItem shippingItem)
|
|
{
|
|
if (shippingItem.MeasuredNetWeight.HasValue) shippingItem.MeasuredNetWeight = double.Round(shippingItem.MeasuredNetWeight.Value, 1);
|
|
if (shippingItem.MeasuredGrossWeight.HasValue) shippingItem.MeasuredGrossWeight = double.Round(shippingItem.MeasuredGrossWeight.Value, 1);
|
|
|
|
}
|
|
} |