#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();
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.",
@Html.Link(T("exporting").Text, Url.Action("Export", "Admin", new { area = "Orchard.ImportExport" })))</p>
<fieldset>

View File

@@ -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();
<fieldset>
<label for="ModulePackage">@T("Module Package")</label>
<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(); }
@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>
<label for="ModulePackage">@T("Theme Package")</label>
<input type="file" id="ThemePackage" size="64" name="ThemePackage" />

View File

@@ -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<string> rolePermissions = new List<string>();
foreach (string key in Request.Form.Keys) {

View File

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

View File

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

View File

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