Adding in server side validation - but need to clarify that this is the 'right' way to do it that wires up correctly/magically back to the UI components
This commit is contained in:
@@ -6,8 +6,10 @@ using System.Web.Http;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Constants = Umbraco.Core.Constants;
|
||||
|
||||
@@ -86,6 +88,17 @@ namespace Umbraco.Web.Editors
|
||||
/// <returns></returns>
|
||||
public TemplateDisplay PostSave(TemplateDisplay display)
|
||||
{
|
||||
|
||||
//Checking the submitted is valid with the Required attributes decorated on the ViewModel
|
||||
if (ModelState.IsValid == false)
|
||||
{
|
||||
//Unsure of the standard or set way to do this?!
|
||||
//throw new HttpResponseException(Request.CreateNotificationValidationErrorResponse("MISSING NAME"));
|
||||
|
||||
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
|
||||
}
|
||||
|
||||
|
||||
if (display.Id > 0)
|
||||
{
|
||||
// update
|
||||
|
||||
@@ -1,21 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Models.Validation;
|
||||
|
||||
namespace Umbraco.Web.Models.ContentEditing
|
||||
{
|
||||
[DataContract(Name = "template", Namespace = "")]
|
||||
public class TemplateDisplay
|
||||
{
|
||||
|
||||
[DataMember(Name = "id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[DataMember(Name = "name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[RequiredForPersistence]
|
||||
[DataMember(Name = "alias")]
|
||||
public string Alias { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user