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 - MerchandiseReturnController.cs - create validator for MerchandiseReturnModel
support54e3b91d7cf7
diff --git a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.csindex 312fd91e5..b86041e55 100644--- a/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/MerchandiseReturnController.cs@@ -168,19 +168,14 @@ namespace Grand.Web.Admin.Controllers//a vendor should have access only to his merchandise returnif (_workContext.CurrentVendor != null && merchandiseReturn.VendorId != _workContext.CurrentVendor.Id)return RedirectToAction("List", "MerchandiseReturn");-- var customAddressAttributes = new List<CustomAttribute>();- if (orderSettings.MerchandiseReturns_AllowToSpecifyPickupAddress)++ if (ModelState.IsValid){- customAddressAttributes = await model.PickupAddress.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);- var customAddressAttributeWarnings = await addressAttributeParser.GetAttributeWarnings(customAddressAttributes);- foreach (var error in customAddressAttributeWarnings)+ var customAddressAttributes = new List<CustomAttribute>();+ if (orderSettings.MerchandiseReturns_AllowToSpecifyPickupAddress){- ModelState.AddModelError("", error);+ customAddressAttributes = await model.PickupAddress.ParseCustomAddressAttributes(addressAttributeParser, addressAttributeService);}- }- if (ModelState.IsValid)- {merchandiseReturn = await _merchandiseReturnViewModelService.UpdateMerchandiseReturnModel(merchandiseReturn, model, customAddressAttributes);Success(_translationService.GetResource("Admin.Orders.MerchandiseReturns.Updated"));diff --git a/src/Web/Grand.Web.Admin/Validators/Orders/MerchandiseReturnValidator.cs b/src/Web/Grand.Web.Admin/Validators/Orders/MerchandiseReturnValidator.csnew file mode 100644index 000000000..a4a3b04bc--- /dev/null+++ b/src/Web/Grand.Web.Admin/Validators/Orders/MerchandiseReturnValidator.cs@@ -0,0 +1,35 @@+using FluentValidation;+using Grand.Business.Core.Interfaces.Common.Addresses;+using Grand.Infrastructure.Validators;+using Grand.Domain.Orders;+using Grand.Web.Admin.Extensions;+using Grand.Web.Admin.Models.Orders;++namespace Grand.Web.Admin.Validators.Orders+{+ public class MerchandiseReturnValidator : BaseGrandValidator<MerchandiseReturnModel>+ {+ public MerchandiseReturnValidator(+ IEnumerable<IValidatorConsumer<MerchandiseReturnModel>> validators,+ OrderSettings orderSettings, IAddressAttributeParser addressAttributeParser,+ IAddressAttributeService addressAttributeService)+ : base(validators)+ {+ RuleFor(x => x).CustomAsync(async (x, context, _) =>+ {+ if (orderSettings.MerchandiseReturns_AllowToSpecifyPickupAddress)+ {+ var customAddressAttributes =+ await x.PickupAddress.ParseCustomAddressAttributes(addressAttributeParser,+ addressAttributeService);+ var customAddressAttributeWarnings =+ await addressAttributeParser.GetAttributeWarnings(customAddressAttributes);+ foreach (var error in customAddressAttributeWarnings)+ {+ context.AddFailure(error);+ }+ }+ });+ }+ }+}\ No newline at end of file