Implement OrderItemMeasuringReset to MeasurementService
This commit is contained in:
parent
f048b999cf
commit
5fad900897
|
|
@ -460,6 +460,22 @@ public class FruitBankDbContext : MgDbContextBase,
|
||||||
return orderDto;
|
return orderDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SetOrderStatusToPendingSafeAsync(Order order)
|
||||||
|
=> await TransactionSafeAsync(async _ => await SetOrderStatusToPendingAsync(order));
|
||||||
|
|
||||||
|
public async Task<bool> SetOrderStatusToPendingAsync(Order order)
|
||||||
|
{
|
||||||
|
if (order.OrderStatus == OrderStatus.Pending) return true;
|
||||||
|
|
||||||
|
var prevOrderStatus = order.OrderStatus;
|
||||||
|
order.OrderStatus = OrderStatus.Pending;
|
||||||
|
|
||||||
|
await Orders.UpdateAsync(order, false);
|
||||||
|
await _eventPublisher.PublishAsync(new OrderStatusChangedEvent(order, prevOrderStatus));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public Task DeleteOrderItemConstraintsSafeAsync(OrderItem orderItem, bool publishEvent = false)
|
public Task DeleteOrderItemConstraintsSafeAsync(OrderItem orderItem, bool publishEvent = false)
|
||||||
{
|
{
|
||||||
return TransactionSafeAsync(async _ =>
|
return TransactionSafeAsync(async _ =>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
using AyCode.Core.Loggers;
|
using AyCode.Core.Loggers;
|
||||||
|
using AyCode.Services.Server.SignalRs;
|
||||||
using FruitBank.Common.Dtos;
|
using FruitBank.Common.Dtos;
|
||||||
|
using FruitBank.Common.Entities;
|
||||||
using FruitBank.Common.Interfaces;
|
using FruitBank.Common.Interfaces;
|
||||||
using FruitBank.Common.Server.Services.SignalRs;
|
using FruitBank.Common.Server.Services.SignalRs;
|
||||||
using FruitBank.Common.Services;
|
using FruitBank.Common.Services;
|
||||||
|
|
@ -7,8 +9,10 @@ using Mango.Nop.Core.Extensions;
|
||||||
using Mango.Nop.Core.Loggers;
|
using Mango.Nop.Core.Loggers;
|
||||||
using Nop.Core.Domain.Catalog;
|
using Nop.Core.Domain.Catalog;
|
||||||
using Nop.Core.Domain.Orders;
|
using Nop.Core.Domain.Orders;
|
||||||
|
using Nop.Core.Events;
|
||||||
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
using Nop.Plugin.Misc.FruitBankPlugin.Domains.DataLayer;
|
||||||
using Nop.Services.Catalog;
|
using Nop.Services.Catalog;
|
||||||
|
using Nop.Services.Events;
|
||||||
|
|
||||||
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
|
|
||||||
|
|
@ -16,18 +20,20 @@ namespace Nop.Plugin.Misc.FruitBankPlugin.Services;
|
||||||
public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementService
|
public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementService
|
||||||
{
|
{
|
||||||
private readonly FruitBankDbContext _dbContext;
|
private readonly FruitBankDbContext _dbContext;
|
||||||
|
private readonly IEventPublisher _eventPublisher;
|
||||||
private readonly SignalRSendToClientService _signalRSendToClientService;
|
private readonly SignalRSendToClientService _signalRSendToClientService;
|
||||||
private readonly CustomPriceCalculationService _customPriceCalculationService;
|
private readonly CustomPriceCalculationService _customPriceCalculationService;
|
||||||
|
|
||||||
public MeasurementService(FruitBankDbContext dbContext, SignalRSendToClientService signalRSendToClientService, FruitBankAttributeService fruitBankAttributeService,
|
public MeasurementService(FruitBankDbContext dbContext, SignalRSendToClientService signalRSendToClientService, FruitBankAttributeService fruitBankAttributeService,
|
||||||
IPriceCalculationService customPriceCalculationService, IEnumerable<IAcLogWriterBase> logWriters) : base(new Logger<MeasurementService>(logWriters.ToArray()))
|
IPriceCalculationService customPriceCalculationService, IEventPublisher eventPublisher, IEnumerable<IAcLogWriterBase> logWriters) : base(new Logger<MeasurementService>(logWriters.ToArray()))
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
_eventPublisher = eventPublisher;
|
||||||
_signalRSendToClientService = signalRSendToClientService;
|
_signalRSendToClientService = signalRSendToClientService;
|
||||||
_customPriceCalculationService = (CustomPriceCalculationService)customPriceCalculationService;
|
_customPriceCalculationService = (CustomPriceCalculationService)customPriceCalculationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public async Task DeleteOrderItemConstraintsAsync(int orderItemId) => await DeleteOrderItemConstraintsAsync(await _dbContext.OrderItems.GetByIdAsync(orderItemId));
|
public async Task DeleteOrderItemConstraintsAsync(int orderItemId) => await DeleteOrderItemConstraintsAsync(await _dbContext.OrderItems.GetByIdAsync(orderItemId));
|
||||||
|
|
||||||
public async Task DeleteOrderItemConstraintsAsync(OrderItem orderItem)
|
public async Task DeleteOrderItemConstraintsAsync(OrderItem orderItem)
|
||||||
|
|
@ -56,4 +62,35 @@ public class MeasurementService : MeasurementServiceBase<Logger>, IMeasurementSe
|
||||||
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
|
await _customPriceCalculationService.CheckAndUpdateOrderTotalPrice(order);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> OrderItemMeasuringReset(int orderItemId)
|
||||||
|
=> await OrderItemMeasuringReset(await _dbContext.OrderItems.GetByIdAsync(orderItemId));
|
||||||
|
|
||||||
|
public async Task<bool> OrderItemMeasuringReset(OrderItem orderItem)
|
||||||
|
{
|
||||||
|
var order = await _dbContext.Orders.GetByIdAsync(orderItem.OrderId);
|
||||||
|
var orderItemPallets = await _dbContext.OrderItemPallets.GetAllByOrderItemId(orderItem.Id, false).ToListAsync();
|
||||||
|
|
||||||
|
var result = await _dbContext.TransactionSafeAsync(async _ =>
|
||||||
|
{
|
||||||
|
foreach (var orderItemPallet in orderItemPallets)
|
||||||
|
{
|
||||||
|
orderItemPallet.RevisorId = 0;
|
||||||
|
await _dbContext.OrderItemPallets.UpdateAsync(orderItemPallet);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (order.OrderStatus == OrderStatus.Complete)
|
||||||
|
await _dbContext.SetOrderStatusToPendingAsync(order);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) return result;
|
||||||
|
|
||||||
|
foreach (var orderItemPallet in orderItemPallets)
|
||||||
|
await _signalRSendToClientService.SendOrderItemPalletChanged(orderItemPallet);
|
||||||
|
|
||||||
|
await _signalRSendToClientService.SendOrderChanged(await _dbContext.OrderDtos.GetByIdAsync(orderItem.OrderId, true));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue