63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using AyaNova.Util;
|
|
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> ExistsAsync(AyaTypeId tid)
|
|
{
|
|
return await ExistsAsync(tid.ObjectType, tid.ObjectId);
|
|
}
|
|
|
|
|
|
//Returns existance status of object type and id specified in database
|
|
internal static async Task<bool> ExistsAsync(AyaType aytype, long id, AyContext ct = null)
|
|
{
|
|
//new up a context??
|
|
if (ct == null)
|
|
{
|
|
ct = ServiceProviderProvider.DBContext;
|
|
}
|
|
switch (aytype)
|
|
{
|
|
//CoreBizObject add here
|
|
case AyaType.User:
|
|
return await ct.User.AnyAsync(m => m.Id == id);
|
|
case AyaType.Widget:
|
|
return await ct.Widget.AnyAsync(m => m.Id == id);
|
|
case AyaType.FileAttachment:
|
|
return await ct.FileAttachment.AnyAsync(m => m.Id == id);
|
|
case AyaType.DataListView:
|
|
return await ct.DataListView.AnyAsync(m => m.Id == id);
|
|
|
|
case AyaType.FormCustom:
|
|
return await ct.FormCustom.AnyAsync(m => m.Id == id);
|
|
|
|
default:
|
|
throw new System.NotSupportedException($"AyaNova.Biz.BizObjectExistsInDatabase::ExistsAsync type {aytype.ToString()} is not supported");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
}//eoc
|
|
|
|
|
|
}//eons
|
|
|