#18335: Fixing validation messages

Work Item: 18335

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-01-13 16:11:22 -08:00
parent 3907ab4de6
commit 664bfe0550
7 changed files with 34 additions and 12 deletions

View File

@@ -4,7 +4,7 @@
Layout.Title = T("Import").ToString(); Layout.Title = T("Import").ToString();
using (Html.BeginFormAntiForgeryPost(Url.Action("Import", new { area = "Orchard.ImportExport" }), FormMethod.Post, new { enctype = "multipart/form-data" })) { using (Html.BeginFormAntiForgeryPost(Url.Action("Import", new { area = "Orchard.ImportExport" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary(); @Html.ValidationSummary();
<p>@T("Choose a recipe file to import. Please consider {0} or backing up your data first.", <p>@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" })))</p> @Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" })))</p>
<fieldset> <fieldset>

View File

@@ -1,7 +1,7 @@
@{ Layout.Title = T("Install a module from your computer").ToString(); } @{ 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" })) { @using (Html.BeginFormAntiForgeryPost(Url.Action("InstallLocally", "PackagingServices", new { redirectUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary(); @Html.ValidationSummary();
<fieldset> <fieldset>
<label for="ModulePackage">@T("Module Package")</label> <label for="ModulePackage">@T("Module Package")</label>
<input type="file" id="ModulePackage" size="64" name="ModulePackage" /> <input type="file" id="ModulePackage" size="64" name="ModulePackage" />

View File

@@ -1,7 +1,7 @@
@{ Layout.Title = T("Install a theme from your computer").ToString(); } @{ 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" })) { @using (Html.BeginFormAntiForgeryPost(Url.Action("InstallLocally", "PackagingServices", new { redirectUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary(); @Html.ValidationSummary();
<fieldset> <fieldset>
<label for="ModulePackage">@T("Theme Package")</label> <label for="ModulePackage">@T("Theme Package")</label>
<input type="file" id="ThemePackage" size="64" name="ThemePackage" /> <input type="file" id="ThemePackage" size="64" name="ThemePackage" />

View File

@@ -73,12 +73,20 @@ namespace Orchard.Roles.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var viewModel = new RoleCreateViewModel(); var viewModel = new RoleCreateViewModel();
UpdateModel(viewModel); TryUpdateModel(viewModel);
//check if the role name already exists if(String.IsNullOrEmpty(viewModel.Name)) {
if (!_roleService.VerifyRoleUnicity(viewModel.Name)) { ModelState.AddModelError("Name", T("Role name can't be empty"));
Services.Notifier.Error(T("Creating Role {0} failed: Role with same name already exists", viewModel.Name)); }
return RedirectToAction("Create");
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); _roleService.CreateRole(viewModel.Name);
@@ -123,7 +131,21 @@ namespace Orchard.Roles.Controllers {
return new HttpUnauthorizedResult(); return new HttpUnauthorizedResult();
var viewModel = new RoleEditViewModel(); 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 // Save
List<string> rolePermissions = new List<string>(); List<string> rolePermissions = new List<string>();
foreach (string key in Request.Form.Keys) { foreach (string key in Request.Form.Keys) {

View File

@@ -4,7 +4,7 @@
@{ Layout.Title = T("Add Role").ToString(); } @{ Layout.Title = T("Add Role").ToString(); }
@using (Html.BeginFormAntiForgeryPost()) { @using (Html.BeginFormAntiForgeryPost()) {
Html.ValidationSummary(); @Html.ValidationSummary();
<fieldset> <fieldset>
<legend>@T("Information")</legend> <legend>@T("Information")</legend>
<label for="pageTitle">@T("Role Name:")</label> <label for="pageTitle">@T("Role Name:")</label>

View File

@@ -4,7 +4,7 @@
@{ Layout.Title = T("Edit Role").ToString(); } @{ Layout.Title = T("Edit Role").ToString(); }
@using(Html.BeginFormAntiForgeryPost()) { @using(Html.BeginFormAntiForgeryPost()) {
Html.ValidationSummary(); @Html.ValidationSummary();
<fieldset> <fieldset>
<legend>@T("Information")</legend> <legend>@T("Information")</legend>
<label for="pageTitle">@T("Role Name:")</label> <label for="pageTitle">@T("Role Name:")</label>

View File

@@ -8,7 +8,7 @@
} }
@using(Html.BeginFormAntiForgeryPost()) { @using(Html.BeginFormAntiForgeryPost()) {
Html.ValidationSummary(); @Html.ValidationSummary();
<fieldset class="bulk-actions"> <fieldset class="bulk-actions">
<label for="publishActions">@T("Actions:")</label> <label for="publishActions">@T("Actions:")</label>
<select id="Select1" name="roleActions"> <select id="Select1" name="roleActions">