Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Minor refactoring UpdateCustomerReminderHistoryCommand

supportf4e8a70cf01f
diff --git a/src/Business/Grand.Business.Marketing/Commands/Handlers/UpdateCustomerReminderHistoryCommandHandler.cs b/src/Business/Grand.Business.Marketing/Commands/Handlers/UpdateCustomerReminderHistoryCommandHandler.cs
deleted file mode 100644
index 015386013..000000000
--- a/src/Business/Grand.Business.Marketing/Commands/Handlers/UpdateCustomerReminderHistoryCommandHandler.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using Grand.Business.Marketing.Commands.Models;
-using Grand.Domain.Customers;
-using Grand.Domain.Data;
-using MediatR;
-
-namespace Grand.Business.Marketing.Commands.Handlers
-{
- /// <summary>
- /// Update Customer Reminder History
- /// </summary>
- public class UpdateCustomerReminderHistoryCommandHandler : IRequestHandler<UpdateCustomerReminderHistoryCommand, bool>
- {
- private readonly IRepository<CustomerReminderHistory> _customerReminderHistory;
-
- public UpdateCustomerReminderHistoryCommandHandler(IRepository<CustomerReminderHistory> customerReminderHistory)
- {
- _customerReminderHistory = customerReminderHistory;
- }
-
- public Task<bool> Handle(UpdateCustomerReminderHistoryCommand request, CancellationToken cancellationToken)
- {
- var update = UpdateBuilder<CustomerReminderHistory>.Create()
- .Set(x => x.EndDate, DateTime.UtcNow)
- .Set(x => x.Status, CustomerReminderHistoryStatusEnum.CompletedOrdered)
- .Set(x => x.OrderId, request.OrderId);
-
- _customerReminderHistory.UpdateManyAsync(x => x.CustomerId == request.CustomerId && x.Status == CustomerReminderHistoryStatusEnum.Started, update);
-
- return Task.FromResult(true);
- }
- }
-}
diff --git a/src/Business/Grand.Business.Marketing/Commands/Models/UpdateCustomerReminderHistoryCommand.cs b/src/Business/Grand.Business.Marketing/Commands/Models/UpdateCustomerReminderHistoryCommand.cs
deleted file mode 100644
index 35d340927..000000000
--- a/src/Business/Grand.Business.Marketing/Commands/Models/UpdateCustomerReminderHistoryCommand.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using MediatR;
-
-namespace Grand.Business.Marketing.Commands.Models
-{
- public class UpdateCustomerReminderHistoryCommand : IRequest<bool>
- {
- public string CustomerId { get; set; }
- public string OrderId { get; set; }
- }
-}
diff --git a/src/Business/Grand.Business.Marketing/Events/OrderPlacedEventHandler.cs b/src/Business/Grand.Business.Marketing/Events/OrderPlacedEventHandler.cs
index a5f862042..01c703ee8 100644
--- a/src/Business/Grand.Business.Marketing/Events/OrderPlacedEventHandler.cs
+++ b/src/Business/Grand.Business.Marketing/Events/OrderPlacedEventHandler.cs
@@ -1,7 +1,7 @@
using Grand.Business.Checkout.Events.Orders;
-using Grand.Business.Marketing.Commands.Models;
using Grand.Business.Marketing.Interfaces.Customers;
using Grand.Domain.Customers;
+using Grand.Domain.Data;
using MediatR;
namespace Grand.Business.Marketing.Events
@@ -9,12 +9,13 @@ namespace Grand.Business.Marketing.Events
public class OrderPlacedEventHandler : INotificationHandler<OrderPlacedEvent>
{
private readonly ICustomerActionEventService _customerActionEventService;
- private readonly IMediator _mediator;
+ private readonly IRepository<CustomerReminderHistory> _customerReminderHistory;
- public OrderPlacedEventHandler(ICustomerActionEventService customerActionEventService, IMediator mediator)
+ public OrderPlacedEventHandler(ICustomerActionEventService customerActionEventService,
+ IRepository<CustomerReminderHistory> customerReminderHistory)
{
_customerActionEventService = customerActionEventService;
- _mediator = mediator;
+ _customerReminderHistory = customerReminderHistory;
}
public async Task Handle(OrderPlacedEvent notification, CancellationToken cancellationToken)
@@ -23,7 +24,13 @@ namespace Grand.Business.Marketing.Events
await _customerActionEventService.AddOrder(notification.Order, CustomerActionTypeEnum.AddOrder);
//customer reminder
- await _mediator.Send(new UpdateCustomerReminderHistoryCommand() { CustomerId = notification.Order.CustomerId, OrderId = notification.Order.Id });
+ var update = UpdateBuilder<CustomerReminderHistory>.Create()
+ .Set(x => x.EndDate, DateTime.UtcNow)
+ .Set(x => x.Status, CustomerReminderHistoryStatusEnum.CompletedOrdered)
+ .Set(x => x.OrderId, notification.Order.Id);
+
+ _ = _customerReminderHistory.UpdateManyAsync(x => x.CustomerId == notification.Order.CustomerId && x.Status == CustomerReminderHistoryStatusEnum.Started, update);
+
}
}
}