improvements

This commit is contained in:
Loretta 2025-11-21 16:29:12 +01:00
parent 139413b1ae
commit b5057b9a4d
2 changed files with 45 additions and 1 deletions

View File

@ -115,6 +115,17 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
return await ctx.Shippings.GetByIdAsync(id, true);
}
[SignalR(SignalRTags.AddShipping)]
public async Task<Shipping> AddShipping(Shipping shipping)
{
ArgumentNullException.ThrowIfNull(shipping);
_logger.Detail($"AddShipping invoked; id: {shipping.Id}");
await ctx.Shippings.InsertAsync(shipping);
return await ctx.Shippings.GetByIdAsync(shipping.Id, true);
}
[SignalR(SignalRTags.UpdateShipping)]
public async Task<Shipping> UpdateShipping(Shipping shipping)
{
@ -123,7 +134,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
_logger.Detail($"UpdateShipping invoked; id: {shipping.Id}");
await ctx.Shippings.UpdateAsync(shipping);
return await ctx.Shippings.GetByIdAsync(shipping.Id, shipping.ShippingDocuments != null);
return await ctx.Shippings.GetByIdAsync(shipping.Id, true);
}
[SignalR(SignalRTags.GetShippingItems)]
@ -261,6 +272,28 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
return await ctx.ShippingDocuments.GetByIdAsync(id, true);
}
[SignalR(SignalRTags.GetShippingDocumentsByShippingId)]
public async Task<List<ShippingDocument>> GetShippingDocumentsByShippingId(int shippingId)
{
_logger.Detail($"GetShippingDocumentsByShippingId invoked; shippingId: {shippingId}");
return await ctx.ShippingDocuments.GetAllByShippingIdAsync(shippingId, true).ToListAsync();
}
[SignalR(SignalRTags.GetShippingDocumentsByProductId)]
public async Task<List<ShippingDocument>> GetShippingDocumentsByProductId(int productId)
{
_logger.Detail($"GetShippingDocumentsByProductId invoked; productId: {productId}");
return await ctx.ShippingDocuments.GetAllByProductIdAsync(productId, true).ToListAsync();
}
[SignalR(SignalRTags.GetShippingDocumentsByPartnerId)]
public async Task<List<ShippingDocument>> GetShippingDocumentsByPartnerId(int partnerId)
{
_logger.Detail($"GetShippingDocumentsByPartnerId invoked; partnerId: {partnerId}");
return await ctx.ShippingDocuments.GetAllByPartnerIdAsync(partnerId, true).ToListAsync();
}
[SignalR(SignalRTags.AddShippingDocument)]
public async Task<ShippingDocument> AddShippingDocument(ShippingDocument shippingDocument)
{

View File

@ -38,4 +38,15 @@ public class ShippingDocumentDbTable : MgDbTableBase<ShippingDocument>
public Task<ShippingDocument> GetByIdAsync(int id, bool loadRelations)
=> GetAll(loadRelations).FirstOrDefaultAsync(sd => sd.Id == id);
public IQueryable<ShippingDocument> GetAllByShippingIdAsync(int shippingId, bool loadRelations)
=> GetAll(loadRelations).Where(sd => sd.ShippingId == shippingId);
public IQueryable<ShippingDocument> GetAllByProductIdAsync(int productId, bool loadRelations)
=> GetAll(loadRelations).Where(sd => sd.ShippingItems.Any(si => si.ProductId == productId));
public IQueryable<ShippingDocument> GetAllByPartnerIdAsync(int partnerId, bool loadRelations)
=> GetAll(loadRelations).Where(sd => sd.PartnerId == partnerId);
}