Files
raven/server/AyaNova/biz/ValidateJsonPatch.cs
2018-09-06 15:28:41 +00:00

58 lines
1.5 KiB
C#

using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.JsonPatch;
using EnumsNET;
using AyaNova.Util;
using AyaNova.Api.ControllerHelpers;
using AyaNova.Biz;
using AyaNova.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
namespace AyaNova.Biz
{
internal static class ValidateJsonPatch<T> where T : class
{
internal static bool Validate(BizObject biz, JsonPatchDocument<T> objectPatch)
{
bool IsValid = true;
//check for in-valid patches
if (objectPatch.Operations.Any(m => m.path == "/id"))
{
biz.AddError(ValidationErrorType.NotChangeable, "Id");
IsValid = false;
}
if (objectPatch.Operations.Any(m => m.path == "/ownerid"))
{
biz.AddError(ValidationErrorType.NotChangeable, "OwnerId");
IsValid = false;
}
if (objectPatch.Operations.Any(m => m.op == "add"))
{
biz.AddError(ValidationErrorType.InvalidOperation, "add");
IsValid = false;
}
if (objectPatch.Operations.Any(m => m.op == "remove"))
{
biz.AddError(ValidationErrorType.InvalidOperation, "remove");
IsValid = false;
}
return IsValid;
}
}//eoc
}//eons