improvements, fixes, etc...
This commit is contained in:
parent
f231fd3165
commit
c94c61e51e
|
|
@ -1,5 +1,6 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using AyCode.Services.SignalRs;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using FruitBank.Common.Dtos;
|
||||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Interfaces;
|
||||
|
|
@ -40,12 +41,6 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
throw new NotImplementedException("GetMeasuringModels");
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetMeasuringModelByShippingId)]
|
||||
public async Task<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
||||
{
|
||||
return await ctx.GetMeasuringModelByShippingId(shippingId).FirstOrDefaultAsync(c => true);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetPartners)]
|
||||
public async Task<List<Partner>> GetPartners()
|
||||
{
|
||||
|
|
@ -73,7 +68,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
_logger.Detail($"UpdatePartner invoked; id: {partner.Id}");
|
||||
|
||||
await ctx.Partners.UpdateAsync(partner);
|
||||
return partner;
|
||||
return await ctx.Partners.GetByIdAsync(partner.Id, partner.ShippingDocuments != null);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -110,7 +105,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
_logger.Detail($"UpdateShipping invoked; id: {shipping.Id}");
|
||||
|
||||
await ctx.Shippings.UpdateAsync(shipping);
|
||||
return shipping;
|
||||
return await ctx.Shippings.GetByIdAsync(shipping.Id, shipping.ShippingDocuments != null);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetShippingItems)]
|
||||
|
|
@ -137,7 +132,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
|
||||
_logger.Detail($"UpdateShippingItem invoked; id: {shippingItem.Id}");
|
||||
|
||||
if (!await ctx.UpdateShippingItemAsync(shippingItem)) return null;
|
||||
if (!await ctx.UpdateShippingItemSafeAsync(shippingItem)) return null;
|
||||
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
||||
}
|
||||
|
||||
|
|
@ -148,7 +143,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
|
||||
_logger.Detail($"UpdateMeasuredShippingItem invoked; id: {shippingItem.Id}");
|
||||
|
||||
if (!await ctx.UpdateMeasuredShippingItemAsync(shippingItem)) return null;
|
||||
if (!await ctx.UpdateMeasuredShippingItemSafeAsync(shippingItem)) return null;
|
||||
return await ctx.ShippingItems.GetByIdAsync(shippingItem.Id, shippingItem.ShippingDocument != null);
|
||||
}
|
||||
|
||||
|
|
@ -176,8 +171,7 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Controllers
|
|||
_logger.Detail($"UpdateShippingDocument invoked; id: {shippingDocument.Id}");
|
||||
|
||||
await ctx.ShippingDocuments.UpdateAsync(shippingDocument);
|
||||
return shippingDocument;
|
||||
|
||||
return await ctx.ShippingDocuments.GetByIdAsync(shippingDocument.Id, shippingDocument.Shipping != null);
|
||||
}
|
||||
|
||||
[SignalR(SignalRTags.GetMeasuringUsers)]
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
public ShippingDocumentDbTable ShippingDocuments { get; set; }
|
||||
public ShippingItemDbTable ShippingItems { get; set; }
|
||||
public ShippingItemPalletDbTable ShippingItemPallets { get; set; }
|
||||
|
||||
|
||||
public IRepository<Product> Products { get; set; }
|
||||
public IRepository<Customer> Customers { get; set; }
|
||||
public IRepository<CustomerRole> CustomerRoles { get; set; }
|
||||
|
|
@ -70,17 +70,6 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
CustomerRoleMappings = customerCustomerRoleMappingRepository;
|
||||
}
|
||||
|
||||
public IQueryable<MeasuringModel> GetMeasuringModelByShippingId(int shippingId)
|
||||
{
|
||||
var query =
|
||||
from p in Partners.Table
|
||||
join s in Shippings.Table on p.Id equals s.PartnerId
|
||||
where s.Id == shippingId
|
||||
select new MeasuringModel(p.Name);
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public IQueryable<Customer> GetCustomersBySystemRoleName(string systemRoleName)
|
||||
{
|
||||
if (systemRoleName.IsNullOrWhiteSpace()) throw new ArgumentException("systemRoleName.IsNullOrWhiteSpace()", nameof(systemRoleName));
|
||||
|
|
@ -121,15 +110,51 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
public async Task<MeasuringAttributeValues?> GetMeasuringAttributeValuesByProductIdAsync(int productId)
|
||||
=> await _fruitBankAttributeService.GetMeasuringAttributeValuesAsync<Product>(productId);
|
||||
|
||||
public Task<bool> UpdateMeasuredShippingItemAsync(ShippingItem shippingItem)
|
||||
public async Task DeleteShippingSafeAsync(Shipping shipping)
|
||||
{
|
||||
if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemAsync(shippingItem);
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await Shippings.DeleteAsync(shipping, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteShippingDocumentSafeAsync(ShippingDocument shippingDocument)
|
||||
{
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await ShippingDocuments.DeleteAsync(shippingDocument, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteShippingItemSafeAsync(ShippingItem shippingItem)
|
||||
{
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await ShippingItems.DeleteAsync(shippingItem, true);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task DeleteShippingItemPalletSafeAsync(ShippingItemPallet shippingItemPallet)
|
||||
{
|
||||
await TransactionSafeAsync(async tr =>
|
||||
{
|
||||
await ShippingItemPallets.DeleteAsync(shippingItemPallet, false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public Task<bool> UpdateMeasuredShippingItemSafeAsync(ShippingItem shippingItem)
|
||||
{
|
||||
if (shippingItem.IsValidMeasuringValues()) return UpdateShippingItemSafeAsync(shippingItem);
|
||||
|
||||
Logger.Error("shippingItem.IsMeasurable && !shippingItem.IsValidMeasuringValues()");
|
||||
return Task.FromResult(false);
|
||||
}
|
||||
|
||||
public Task<bool> UpdateShippingItemAsync(ShippingItem shippingItem)
|
||||
public Task<bool> UpdateShippingItemSafeAsync(ShippingItem shippingItem)
|
||||
{
|
||||
if (shippingItem == null)
|
||||
{
|
||||
|
|
@ -174,7 +199,7 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
shippingItem.IsMeasured == dbShippingItem.IsMeasured && shippingItem.IsMeasurable == dbShippingItem.IsMeasurable &&
|
||||
shippingItem.MeasuredQuantity == dbShippingItem.MeasuredQuantity &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
|
||||
shippingItem.MeasuredNetWeight == dbShippingItem.MeasuredNetWeight &&
|
||||
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||
shippingItem.MeasuredGrossWeight == dbShippingItem.MeasuredGrossWeight)
|
||||
{
|
||||
|
|
@ -222,13 +247,11 @@ public class FruitBankDbContext : MgDbContextBase, IPartnerDbSet<PartnerDbTable>
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"UpdateShippingItemAsync->TransactionSafeAsync error! shippingItem.Id: {shippingItem.Id}; ex: {ex.Message}", ex);
|
||||
throw new Exception($"UpdateShippingItemSafeAsync->TransactionSafeAsync error! shippingItem.Id: {shippingItem.Id}; ex: {ex.Message}", ex);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async Task<bool> UpdateProductStockQuantityAsync(int productId, bool publishEvent)
|
||||
{
|
||||
var product = await Products.GetByIdAsync(productId);
|
||||
|
|
|
|||
|
|
@ -40,5 +40,5 @@ public class ShippingDbTable : MgDbTableBase<Shipping>
|
|||
if (entity is { IsAllMeasured: true, MeasuredDate: null }) entity.MeasuredDate = DateTime.Now;
|
||||
|
||||
base.OnUpdate(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using AyCode.Core.Loggers;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using FruitBank.Common.Entities;
|
||||
using FruitBank.Common.Interfaces;
|
||||
using FruitBank.Common.Loggers;
|
||||
|
|
@ -17,7 +18,7 @@ using Nop.Services.Events;
|
|||
|
||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Domains.EventConsumers;
|
||||
|
||||
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters) :
|
||||
public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, FruitBankDbContext ctx, FruitBankAttributeService fruitBankAttributeService, IStoreContext storeContext, IEnumerable<IAcLogWriterBase> logWriters) :
|
||||
MgEventConsumer(httpContextAccessor, logWriters), IConsumer<EntityUpdatedEvent<ShippingItem>>, IConsumer<EntityUpdatedEvent<ShippingDocument>>
|
||||
{
|
||||
public override async Task HandleEventAsync(EntityUpdatedEvent<Product> eventMessage)
|
||||
|
|
@ -40,6 +41,8 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
|||
await UpdateShippingDocumentIsAllMeasuredAsync(eventMessage.Entity);
|
||||
}
|
||||
|
||||
#region Update
|
||||
|
||||
public async Task HandleEventAsync(EntityUpdatedEvent<ShippingItem> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityUpdatedEvent<ShippingItem>; id: {eventMessage.Entity.Id}");
|
||||
|
|
@ -52,7 +55,7 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
|||
shippingItem.IsMeasured = isMeasured;
|
||||
await ctx.ShippingItems.UpdateAsync(shippingItem, false);
|
||||
}
|
||||
|
||||
|
||||
await UpdateShippingDocumentIsAllMeasuredAsync(shippingItem);
|
||||
}
|
||||
|
||||
|
|
@ -95,4 +98,30 @@ public class FruitBankEventConsumer(IHttpContextAccessor httpContextAccessor, Fr
|
|||
}
|
||||
}
|
||||
|
||||
#endregion Update
|
||||
|
||||
#region Delete
|
||||
|
||||
public async Task HandleEventAsync(EntityDeletedEvent<Shipping> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityDeletedEvent<Shipping>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await ctx.ShippingDocuments.DeleteAsync(sd => sd.ShippingId == eventMessage.Entity.Id, true);
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(EntityDeletedEvent<ShippingDocument> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityDeletedEvent<ShippingDocument>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await ctx.ShippingItems.DeleteAsync(si => si.ShippingDocumentId == eventMessage.Entity.Id, true);
|
||||
}
|
||||
|
||||
public async Task HandleEventAsync(EntityDeletedEvent<ShippingItem> eventMessage)
|
||||
{
|
||||
Logger.Info($"HandleEventAsync EntityDeletedEvent<ShippingItem>; id: {eventMessage.Entity.Id}");
|
||||
|
||||
await ctx.ShippingItemPallets.DeleteAsync(sp => sp.ShippingItemId == eventMessage.Entity.Id, false);
|
||||
}
|
||||
|
||||
#endregion Delete
|
||||
}
|
||||
Loading…
Reference in New Issue