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 UpdateIntervalPropertiesCommand

support7cd2da1a9648
diff --git a/src/Business/Grand.Business.Catalog/Commands/Handlers/UpdateIntervalPropertiesCommandHandler.cs b/src/Business/Grand.Business.Catalog/Commands/Handlers/UpdateIntervalPropertiesCommandHandler.cs
index 49508e635..b0e7ad991 100644
--- a/src/Business/Grand.Business.Catalog/Commands/Handlers/UpdateIntervalPropertiesCommandHandler.cs
+++ b/src/Business/Grand.Business.Catalog/Commands/Handlers/UpdateIntervalPropertiesCommandHandler.cs
@@ -3,7 +3,6 @@ using Grand.Domain.Catalog;
using Grand.Domain.Data;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
-using Grand.Infrastructure.Extensions;
using MediatR;
namespace Grand.Business.Catalog.Commands.Handlers
@@ -11,13 +10,11 @@ namespace Grand.Business.Catalog.Commands.Handlers
public class UpdateIntervalPropertiesCommandHandler : IRequestHandler<UpdateIntervalPropertiesCommand, bool>
{
private readonly IRepository<Product> _productRepository;
- private readonly IMediator _mediator;
private readonly ICacheBase _cacheBase;
- public UpdateIntervalPropertiesCommandHandler(IRepository<Product> productRepository, IMediator mediator, ICacheBase cacheBase)
+ public UpdateIntervalPropertiesCommandHandler(IRepository<Product> productRepository, ICacheBase cacheBase)
{
_productRepository = productRepository;
- _mediator = mediator;
_cacheBase = cacheBase;
}
@@ -36,9 +33,6 @@ namespace Grand.Business.Catalog.Commands.Handlers
//cache
await _cacheBase.RemoveByPrefix(string.Format(CacheKey.PRODUCTS_BY_ID_KEY, request.Product.Id));
- //event notification
- await _mediator.EntityUpdated(request.Product);
-
return true;
}
}
diff --git a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
index 0b947ef9c..7b6a9271d 100644
--- a/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
+++ b/src/Tests/Grand.Business.Catalog.Tests/Handlers/UpdateIntervalPropertiesCommandHandlerTests.cs
@@ -14,8 +14,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
[TestClass()]
public class UpdateIntervalPropertiesCommandHandlerTests
{
- private Mock<MongoRepository<Product>> _repositoryMock;
- private Mock<IMediator> _mediatorMock;
+ private Mock<MongoRepository<Product>> _repositoryMock;
private Mock<ICacheBase> _cacheMock;
private UpdateIntervalPropertiesCommandHandler _handler;
@@ -25,9 +24,8 @@ namespace Grand.Business.Catalog.Tests.Handlers
CommonPath.BaseDirectory = "";
_repositoryMock = new Mock<MongoRepository<Product>>();
- _mediatorMock = new Mock<IMediator>();
_cacheMock = new Mock<ICacheBase>();
- _handler = new UpdateIntervalPropertiesCommandHandler(_repositoryMock.Object, _mediatorMock.Object, _cacheMock.Object);
+ _handler = new UpdateIntervalPropertiesCommandHandler(_repositoryMock.Object, _cacheMock.Object);
}
[TestMethod()]
@@ -48,7 +46,7 @@ namespace Grand.Business.Catalog.Tests.Handlers
//TODO
//collectionMock.Verify(c => c.UpdateOneAsync(x => x.Id == product.Id, It.IsAny<UpdateDefinition<Product>>(), null, default), Times.Once);
_cacheMock.Verify(c => c.RemoveByPrefix(It.IsAny<string>(), It.IsAny<bool>()), Times.Once);
- _mediatorMock.Verify(c => c.Publish(It.IsAny<EntityUpdated<Product>>(), default(CancellationToken)), Times.Once);
+
}
}
}
diff --git a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
index 5b5d6a1cc..fef9a6ffb 100644
--- a/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/ProductController.cs
@@ -15,6 +15,7 @@ using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Media;
using Grand.Infrastructure;
+using Grand.Infrastructure.Extensions;
using Grand.Web.Admin.Extensions;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Catalog;
@@ -2660,8 +2661,12 @@ namespace Grand.Web.Admin.Controllers
}
}
+ //update fields on product
await _mediator.Send(new UpdateIntervalPropertiesCommand() { Product = product, IncludeBothDates = model.IncBothDate, Interval = model.Interval, IntervalUnit = (IntervalUnit)model.IntervalUnit });
+ //event notification
+ await _mediator.EntityUpdated(product);
+
if (!ModelState.IsValid)
{
Dictionary<string, Dictionary<string, object>> error = (Dictionary<string, Dictionary<string, object>>)ModelState.SerializeErrors();