71 lines
2.1 KiB
C#
71 lines
2.1 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
|
|
{
|
|
|
|
|
|
//THIS IS USED BY THE ATTACHMENT CONTROLLER
|
|
//IN THEORY WE ONLY NEED TO CHECK FOR ATTACHABLE TYPES, BUT I CAN SEE IT'S POTENTIAL USEFULNESS DOWN THE ROAD FOR OTHER THINGS
|
|
internal static class BizObjectExistsInDatabase
|
|
{
|
|
|
|
//THIS IS THE METHOD CALLED BY THE ATTACHMENT CONTROLLER
|
|
internal static async Task<bool> Exists(AyaTypeId tid)
|
|
{
|
|
return await 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.FileAttachment:
|
|
return ct.FileAttachment.Any(m => m.Id == id);
|
|
case AyaType.DataListFilter:
|
|
return ct.DataListFilter.Any(m => m.Id == id);
|
|
case AyaType.DataListTemplate:
|
|
return ct.DataListTemplate.Any(m => m.Id == id);
|
|
case AyaType.FormCustom:
|
|
return ct.FormCustom.Any(m => m.Id == id);
|
|
|
|
|
|
|
|
default:
|
|
throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::Exists type {aytype.ToString()} is not supported");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
}//eoc
|
|
|
|
|
|
}//eons
|
|
|