Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Marketing.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Customers;
using Grand.Infrastructure;
Expand Down Expand Up @@ -59,6 +60,7 @@ private CustomerController BuildController(bool perStoreEnabled)
_customerServiceMock.Object,
_customerViewModelServiceMock.Object,
_customerManagerServiceMock.Object,
new Mock<ICustomerProductService>().Object,
new Mock<IProductReviewService>().Object,
new Mock<IProductReviewViewModelService>().Object,
new Mock<IProductViewModelService>().Object,
Expand Down
30 changes: 28 additions & 2 deletions src/Web/Grand.Web.Store/Controllers/CustomerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Business.Core.Interfaces.Customers;
using Grand.Business.Core.Interfaces.Marketing.Customers;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Business.Core.Utilities.Customers;
using Grand.Domain.Catalog;
Expand Down Expand Up @@ -45,6 +46,7 @@ public CustomerController(
ICustomerService customerService,
ICustomerViewModelService customerViewModelService,
ICustomerManagerService customerManagerService,
ICustomerProductService customerProductService,
IProductReviewService productReviewService,
IProductReviewViewModelService productReviewViewModelService,
IProductViewModelService productViewModelService,
Expand All @@ -62,6 +64,7 @@ public CustomerController(
_customerService = customerService;
_customerViewModelService = customerViewModelService;
_customerManagerService = customerManagerService;
_customerProductService = customerProductService;
_productReviewService = productReviewService;
_productReviewViewModelService = productReviewViewModelService;
_productViewModelService = productViewModelService;
Expand All @@ -84,6 +87,7 @@ public CustomerController(
private readonly ICustomerService _customerService;
private readonly ICustomerViewModelService _customerViewModelService;
private readonly ICustomerManagerService _customerManagerService;
private readonly ICustomerProductService _customerProductService;
private readonly IProductReviewService _productReviewService;
private readonly IProductReviewViewModelService _productReviewViewModelService;
private readonly IProductViewModelService _productViewModelService;
Expand Down Expand Up @@ -827,30 +831,52 @@ public async Task<IActionResult> ProductAddPopup(string customerId, bool persona
}

[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> UpdateProductPrice(CustomerModel.ProductPriceModel model)
{
var productPrice = await _customerProductService.GetCustomerProductPriceById(model.Id);
Comment thread
Copilot marked this conversation as resolved.
if (productPrice == null || await GetStoreCustomer(productPrice.CustomerId) == null)
return new JsonResult("");

await _customerViewModelService.UpdateProductPrice(model);
return new JsonResult("");
}

[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> DeleteProductPrice(string id)
{
await _customerViewModelService.DeleteProductPrice(id);
var productPrice = await _customerProductService.GetCustomerProductPriceById(id);
Comment thread
Copilot marked this conversation as resolved.
if (productPrice == null || await GetStoreCustomer(productPrice.CustomerId) == null)
return new JsonResult("");

//delete the already-resolved entity to avoid a redundant reload / TOCTOU throw
await _customerProductService.DeleteCustomerProductPrice(productPrice);
return new JsonResult("");
}

[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> UpdatePersonalizedProduct(CustomerModel.ProductModel model)
{
var customerProduct = await _customerProductService.GetCustomerProduct(model.Id);
Comment thread
Copilot marked this conversation as resolved.
if (customerProduct == null || await GetStoreCustomer(customerProduct.CustomerId) == null)
return new JsonResult("");

await _customerViewModelService.UpdatePersonalizedProduct(model);
return new JsonResult("");
}

[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
public async Task<IActionResult> DeletePersonalizedProduct(string id)
{
await _customerViewModelService.DeletePersonalizedProduct(id);
var customerProduct = await _customerProductService.GetCustomerProduct(id);
Comment thread
Copilot marked this conversation as resolved.
if (customerProduct == null || await GetStoreCustomer(customerProduct.CustomerId) == null)
return new JsonResult("");

//delete the already-resolved entity to avoid a redundant reload / TOCTOU throw
await _customerProductService.DeleteCustomerProduct(customerProduct);
return new JsonResult("");
}

Expand Down
Loading