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.

Admin panel - PageController.cs - changes with validator

supportabd7527167f2
diff --git a/src/Web/Grand.Web.Admin/Controllers/PageController.cs b/src/Web/Grand.Web.Admin/Controllers/PageController.cs
index 1cdca85b8..73bf9a9ce 100644
--- a/src/Web/Grand.Web.Admin/Controllers/PageController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/PageController.cs
@@ -150,10 +150,6 @@ namespace Grand.Web.Admin.Controllers
[HttpPost, ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
public async Task<IActionResult> Edit(PageModel model, bool continueEditing)
{
- if (model.StartDateUtc.HasValue && model.EndDateUtc.HasValue && model.StartDateUtc >= model.EndDateUtc)
- {
- ModelState.AddModelError(nameof(model.StartDateUtc), "Start Date cannot be later than End Date");
- }
var page = await _pageService.GetPageById(model.Id);
if (page == null)
//No page found with the specified id
@@ -167,7 +163,6 @@ namespace Grand.Web.Admin.Controllers
{
//selected tab
await SaveSelectedTabIndex();
-
return RedirectToAction("Edit", new { id = page.Id });
}
return RedirectToAction("List");
diff --git a/src/Web/Grand.Web.Admin/Validators/Pages/PageValidator.cs b/src/Web/Grand.Web.Admin/Validators/Pages/PageValidator.cs
index 0471c0ca0..3bc9174bf 100644
--- a/src/Web/Grand.Web.Admin/Validators/Pages/PageValidator.cs
+++ b/src/Web/Grand.Web.Admin/Validators/Pages/PageValidator.cs
@@ -13,6 +13,13 @@ namespace Grand.Web.Admin.Validators.Pages
: base(validators)
{
RuleFor(x => x.SystemName).NotEmpty().WithMessage(translationService.GetResource("Admin.Content.Pages.Fields.SystemName.Required"));
+ RuleFor(x => x).Custom((model, context)=>
+ {
+ if (model.StartDateUtc.HasValue && model.EndDateUtc.HasValue && model.StartDateUtc >= model.EndDateUtc)
+ {
+ context.AddFailure(nameof(model.StartDateUtc), "Start Date cannot be later than End Date");
+ }
+ });
}
}
}
\ No newline at end of file