Files
raven/server/AyaNova/biz/BizObjectExistsInDatabase.cs
2018-11-29 01:10:29 +00:00

70 lines
1.9 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;
namespace AyaNova.Biz
{
//TODO: UNTESTED, UNUSED (SO FAR)CODE
//This was just blocked out because I know I will need it in future
internal static class BizObjectExistsInDatabase
{
internal static bool Exists(AyaTypeId tid)
{
return Exists(tid.ObjectType, tid.ObjectId);
}
//Returns existance status of object type and id specified in database
internal static bool Exists(AyaType aytype, long id, AyContext ct = null)
{
//new up a context??
if (ct == null)
{
ct = ServiceProviderProvider.DBContext;
}
switch (aytype)
{
case AyaType.User:
return ct.User.Any(m => m.Id == id);
case AyaType.Widget:
return ct.Widget.Any(m => m.Id == id);
case AyaType.Tag:
return ct.Tag.Any(m => m.Id == id);
case AyaType.TagGroup:
return ct.TagGroup.Any(m => m.Id == id);
case AyaType.FileAttachment:
return ct.FileAttachment.Any(m => m.Id == id);
case AyaType.DataFilter:
return ct.DataFilter.Any(m => m.Id == id);
default:
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectExistsInDatabase::Exists type {aytype.ToString()} is not supported");
}
}
/////////////////////////////////////////////////////////////////////
}//eoc
}//eons