mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Added some validation to content type creation
--HG-- branch : dev
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
using Orchard.ContentManagement.MetaData.Models;
|
using Orchard.ContentManagement.MetaData.Models;
|
||||||
@@ -43,6 +44,14 @@ namespace Orchard.ContentTypes.Controllers {
|
|||||||
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type.")))
|
if (!Services.Authorizer.Authorize(Permissions.CreateContentTypes, T("Not allowed to create a content type.")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
|
if(String.IsNullOrWhiteSpace(viewModel.DisplayName)) {
|
||||||
|
ModelState.AddModelError("DisplayName", T("The Content Type name can't be empty.").ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_contentDefinitionService.GetTypes().Any(t => t.DisplayName == viewModel.DisplayName)) {
|
||||||
|
ModelState.AddModelError("DisplayName", T("A type with the same name already exists.").ToString());
|
||||||
|
}
|
||||||
|
|
||||||
var typeViewModel = _contentDefinitionService.AddType(viewModel);
|
var typeViewModel = _contentDefinitionService.AddType(viewModel);
|
||||||
|
|
||||||
if (!ModelState.IsValid) {
|
if (!ModelState.IsValid) {
|
||||||
|
|||||||
Reference in New Issue
Block a user