From 4070669e7d11b145e6900865580850ea133ba9a5 Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 10 Mar 2014 16:00:53 +1100 Subject: [PATCH] Completes: U4-4335 It's Possible to Create Duplicate Data Types --- src/Umbraco.Web/Editors/DataTypeController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Web/Editors/DataTypeController.cs b/src/Umbraco.Web/Editors/DataTypeController.cs index 5b98487a8f..c4c8d6a485 100644 --- a/src/Umbraco.Web/Editors/DataTypeController.cs +++ b/src/Umbraco.Web/Editors/DataTypeController.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Data; using System.Linq; using System.Net; using System.Web.Http; @@ -12,6 +13,7 @@ using Umbraco.Core.Services; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.Models.Mapping; using Umbraco.Web.Mvc; +using Umbraco.Web.WebApi; using Umbraco.Web.WebApi.Binders; using Umbraco.Web.WebApi.Filters; using umbraco; @@ -139,8 +141,16 @@ namespace Umbraco.Web.Editors preValDictionary, currVal); - //save the data type - dtService.SaveDataTypeAndPreValues(dataType.PersistedDataType, formattedVal, (int)Security.CurrentUser.Id); + try + { + //save the data type + dtService.SaveDataTypeAndPreValues(dataType.PersistedDataType, formattedVal, (int)Security.CurrentUser.Id); + } + catch (DuplicateNameException ex) + { + ModelState.AddModelError("Name", ex.Message); + throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState)); + } var display = Mapper.Map(dataType.PersistedDataType); display.AddSuccessNotification(ui.Text("speechBubbles", "dataTypeSaved"), "");