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.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Adin panel - GiftVoucherController.cs - further changes
support91e30f320c17
diff --git a/src/Web/Grand.Web.Admin/Controllers/GiftVoucherController.cs b/src/Web/Grand.Web.Admin/Controllers/GiftVoucherController.csindex 3f2fc0673..0706c8382 100644--- a/src/Web/Grand.Web.Admin/Controllers/GiftVoucherController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/GiftVoucherController.cs@@ -1,7 +1,6 @@using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Business.Core.Utilities.Common.Security;-using Grand.SharedKernel.Extensions;using Grand.Web.Admin.Interfaces;using Grand.Web.Admin.Models.Orders;using Grand.Web.Common.DataSource;@@ -155,16 +154,13 @@ namespace Grand.Web.Admin.Controllers[PermissionAuthorizeAction(PermissionActionName.Delete)][HttpPost]- public async Task<IActionResult> Delete(string id)+ public async Task<IActionResult> Delete(GiftVoucherDeleteModel model){- var giftVoucher = await _giftVoucherService.GetGiftVoucherById(id);+ var giftVoucher = await _giftVoucherService.GetGiftVoucherById(model.Id);if (giftVoucher == null)//No gift voucher found with the specified idreturn RedirectToAction("List");-- if (giftVoucher.GiftVoucherUsageHistory.Any())- ModelState.AddModelError("", _translationService.GetResource("Admin.GiftVouchers.PreventDeleted"));-+if (ModelState.IsValid){await _giftVoucherViewModelService.DeleteGiftVoucher(giftVoucher);diff --git a/src/Web/Grand.Web.Admin/Models/Orders/GiftVoucherDeleteModel.cs b/src/Web/Grand.Web.Admin/Models/Orders/GiftVoucherDeleteModel.csnew file mode 100644index 000000000..5ea34fc72--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Orders/GiftVoucherDeleteModel.cs@@ -0,0 +1,3 @@+namespace Grand.Web.Admin.Models.Orders;++public record GiftVoucherDeleteModel(string Id);\ No newline at end of filediff --git a/src/Web/Grand.Web.Admin/Validators/Orders/GiftVoucherDeleteModelValidator.cs b/src/Web/Grand.Web.Admin/Validators/Orders/GiftVoucherDeleteModelValidator.csnew file mode 100644index 000000000..1ace29d7b--- /dev/null+++ b/src/Web/Grand.Web.Admin/Validators/Orders/GiftVoucherDeleteModelValidator.cs@@ -0,0 +1,21 @@+using FluentValidation;+using Grand.Business.Core.Interfaces.Checkout.GiftVouchers;+using Grand.Business.Core.Interfaces.Common.Localization;+using Grand.Infrastructure.Validators;+using Grand.Web.Admin.Models.Orders;++public class GiftVoucherDeleteModelValidator : BaseGrandValidator<GiftVoucherDeleteModel>+{+ public GiftVoucherDeleteModelValidator(+ IEnumerable<IValidatorConsumer<GiftVoucherDeleteModel>> validators,+ IGiftVoucherService giftVoucherService, ITranslationService translationService)+ : base(validators)+ {+ RuleFor(x => x).CustomAsync(async (x, context, _) =>+ {+ var giftVoucher = await giftVoucherService.GetGiftVoucherById(x.Id);+ if (giftVoucher.GiftVoucherUsageHistory.Any())+ context.AddFailure(translationService.GetResource("Admin.GiftVouchers.PreventDeleted"));+ });+ }+}\ No newline at end of file