Added some validation to content type creation

--HG--
branch : dev
This commit is contained in:
Sebastien Ros
2010-07-16 16:18:16 -07:00
parent 97c5439d30
commit 416ca95395

View File

@@ -1,4 +1,5 @@
using System.Linq;
using System;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement;
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.")))
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);
if (!ModelState.IsValid) {