From 664bfe0550d8698741d68221a333733d10079c34 Mon Sep 17 00:00:00 2001 From: Sebastien Ros Date: Fri, 13 Jan 2012 16:11:22 -0800 Subject: [PATCH] #18335: Fixing validation messages Work Item: 18335 --HG-- branch : 1.x --- .../Views/Admin/Import.cshtml | 2 +- .../Views/PackagingServices/AddModule.cshtml | 2 +- .../Views/PackagingServices/AddTheme.cshtml | 2 +- .../Controllers/AdminController.cs | 34 +++++++++++++++---- .../Orchard.Roles/Views/Admin/Create.cshtml | 2 +- .../Orchard.Roles/Views/Admin/Edit.cshtml | 2 +- .../Orchard.Roles/Views/Admin/Index.cshtml | 2 +- 7 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Import.cshtml b/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Import.cshtml index 4988015ef..4480600fc 100644 --- a/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Import.cshtml +++ b/src/Orchard.Web/Modules/Orchard.ImportExport/Views/Admin/Import.cshtml @@ -4,7 +4,7 @@ Layout.Title = T("Import").ToString(); using (Html.BeginFormAntiForgeryPost(Url.Action("Import", new { area = "Orchard.ImportExport" }), FormMethod.Post, new { enctype = "multipart/form-data" })) { - Html.ValidationSummary(); + @Html.ValidationSummary();

@T("Choose a recipe file to import. Please consider {0} or backing up your data first.", @Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" })))

diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml index 42549d455..dd0a86129 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml @@ -1,7 +1,7 @@ @{ Layout.Title = T("Install a module from your computer").ToString(); } @using (Html.BeginFormAntiForgeryPost(Url.Action("InstallLocally", "PackagingServices", new { redirectUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) { - Html.ValidationSummary(); + @Html.ValidationSummary();
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml index ca4063fc4..84f92445f 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml @@ -1,7 +1,7 @@ @{ Layout.Title = T("Install a theme from your computer").ToString(); } @using (Html.BeginFormAntiForgeryPost(Url.Action("InstallLocally", "PackagingServices", new { redirectUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) { - Html.ValidationSummary(); + @Html.ValidationSummary();
diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs index e68154111..49e087ba1 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Roles/Controllers/AdminController.cs @@ -73,12 +73,20 @@ namespace Orchard.Roles.Controllers { return new HttpUnauthorizedResult(); var viewModel = new RoleCreateViewModel(); - UpdateModel(viewModel); + TryUpdateModel(viewModel); - //check if the role name already exists - if (!_roleService.VerifyRoleUnicity(viewModel.Name)) { - Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name)); - return RedirectToAction("Create"); + if(String.IsNullOrEmpty(viewModel.Name)) { + ModelState.AddModelError("Name", T("Role name can't be empty")); + } + + var role = _roleService.GetRoleByName(viewModel.Name); + if (role != null) { + ModelState.AddModelError("Name", T("Role with same name already exists")); + } + + if (!ModelState.IsValid) { + viewModel.FeaturePermissions = _roleService.GetInstalledPermissions(); + return View(viewModel); } _roleService.CreateRole(viewModel.Name); @@ -123,7 +131,21 @@ namespace Orchard.Roles.Controllers { return new HttpUnauthorizedResult(); var viewModel = new RoleEditViewModel(); - UpdateModel(viewModel); + TryUpdateModel(viewModel); + + if (String.IsNullOrEmpty(viewModel.Name)) { + ModelState.AddModelError("Name", T("Role name can't be empty")); + } + + var role = _roleService.GetRoleByName(viewModel.Name); + if (role != null && role.Id != id) { + ModelState.AddModelError("Name", T("Role with same name already exists")); + } + + if (!ModelState.IsValid) { + return Edit(id); + } + // Save List rolePermissions = new List(); foreach (string key in Request.Form.Keys) { diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Create.cshtml b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Create.cshtml index af1adcb1b..d8cd66ed6 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Create.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Create.cshtml @@ -4,7 +4,7 @@ @{ Layout.Title = T("Add Role").ToString(); } @using (Html.BeginFormAntiForgeryPost()) { - Html.ValidationSummary(); + @Html.ValidationSummary();
@T("Information") diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Edit.cshtml b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Edit.cshtml index 034ad6cd3..85b48697b 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Edit.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Edit.cshtml @@ -4,7 +4,7 @@ @{ Layout.Title = T("Edit Role").ToString(); } @using(Html.BeginFormAntiForgeryPost()) { - Html.ValidationSummary(); + @Html.ValidationSummary();
@T("Information") diff --git a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Index.cshtml index 0b4461c05..129fdec4d 100644 --- a/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Roles/Views/Admin/Index.cshtml @@ -8,7 +8,7 @@ } @using(Html.BeginFormAntiForgeryPost()) { - Html.ValidationSummary(); + @Html.ValidationSummary();