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
Admin panel - ContactFormController.cs - move validator
support3bd4fe0a0dc2
diff --git a/src/Web/Grand.Web.Admin/Controllers/ContactFormController.cs b/src/Web/Grand.Web.Admin/Controllers/ContactFormController.csindex 347a5e78f..f267bc39b 100644--- a/src/Web/Grand.Web.Admin/Controllers/ContactFormController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/ContactFormController.cs@@ -68,28 +68,18 @@ namespace Grand.Web.Admin.Controllers[HttpPost][PermissionAuthorizeAction(PermissionActionName.Delete)]- public async Task<IActionResult> Delete(string id)+ public async Task<IActionResult> Delete(ContactFormDeleteModel model){- var contactform = await _contactUsService.GetContactUsById(id);- if (contactform == null)- //No email found with the specified id- return RedirectToAction("List");-- if (_workContext.CurrentVendor != null)- {- if (contactform.VendorId != _workContext.CurrentVendor.Id)- ModelState.AddModelError("", "This is not your contact us form");- }-+ var contactForm = await _contactUsService.GetContactUsById(model.Id);if (ModelState.IsValid){- await _contactUsService.DeleteContactUs(contactform);+ await _contactUsService.DeleteContactUs(contactForm);Success(_translationService.GetResource("Admin.System.ContactForm.Deleted"));return RedirectToAction("List");}Error(ModelState);- return RedirectToAction("Details", new { id });+ return RedirectToAction("Details", new { model.Id });}[HttpPost]diff --git a/src/Web/Grand.Web.Admin/Models/Messages/ContactFormDeleteModel.cs b/src/Web/Grand.Web.Admin/Models/Messages/ContactFormDeleteModel.csnew file mode 100644index 000000000..6df6fd4c5--- /dev/null+++ b/src/Web/Grand.Web.Admin/Models/Messages/ContactFormDeleteModel.cs@@ -0,0 +1,3 @@+namespace Grand.Web.Admin.Models.Messages;++public record ContactFormDeleteModel(string Id);diff --git a/src/Web/Grand.Web.Admin/Validators/Messages/ContactFormDeleteValidator.cs b/src/Web/Grand.Web.Admin/Validators/Messages/ContactFormDeleteValidator.csnew file mode 100644index 000000000..255bb97e7--- /dev/null+++ b/src/Web/Grand.Web.Admin/Validators/Messages/ContactFormDeleteValidator.cs@@ -0,0 +1,29 @@+using FluentValidation;+using Grand.Business.Core.Interfaces.Marketing.Contacts;+using Grand.Infrastructure;+using Grand.Infrastructure.Validators;+using Grand.Web.Admin.Models.Messages;++namespace Grand.Web.Admin.Validators.Messages+{+ public class ContactFormDeleteValidator : BaseGrandValidator<ContactFormDeleteModel>+ {+ public ContactFormDeleteValidator(IEnumerable<IValidatorConsumer<ContactFormDeleteModel>> validators,+ IContactUsService contactUsService, IWorkContext workContext)+ : base(validators)+ {+ RuleFor(x => x).CustomAsync(async (x, context, _) =>+ {+ var contact = await contactUsService.GetContactUsById(x.Id);+ if (contact == null)+ context.AddFailure("Not found with the specified id");++ if (workContext.CurrentVendor != null)+ {+ if (contact!.VendorId != workContext.CurrentVendor.Id)+ context.AddFailure("This is not your contact us form");+ }+ });+ }+ }+}\ No newline at end of file