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:
Warren Buckley
2017-01-04 14:12:45 +00:00
parent 42841824bf
commit 1300764770
2 changed files with 18 additions and 0 deletions

View File

@@ -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

View File

@@ -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; }