Files
sockeye/server/biz/BizObjectExistsInDatabase.cs
2023-01-23 00:59:38 +00:00

91 lines
3.5 KiB
C#

using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Sockeye.Models;
namespace Sockeye.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
{
//Returns existance status of object type and id specified in database
internal static async Task<bool> ExistsAsync(SockType aType, long id, AyContext ct)
{
//new up a context??
switch (aType)
{
//CoreBizObject add here
case SockType.NoType://no type always exists and this is used by orphaned attachments
return true;
case SockType.FileAttachment:
return await ct.FileAttachment.AnyAsync(z => z.Id == id);
case SockType.DataListSavedFilter:
return await ct.DataListSavedFilter.AnyAsync(z => z.Id == id);
case SockType.FormCustom:
return await ct.FormCustom.AnyAsync(z => z.Id == id);
case SockType.User:
return await ct.User.AnyAsync(z => z.Id == id);
case SockType.Customer:
return await ct.Customer.AnyAsync(z => z.Id == id);
case SockType.CustomerNote:
return await ct.CustomerNote.AnyAsync(z => z.Id == id);
case SockType.HeadOffice:
return await ct.HeadOffice.AnyAsync(z => z.Id == id);
case SockType.Memo:
return await ct.Memo.AnyAsync(z => z.Id == id);
case SockType.Report:
return await ct.Report.AnyAsync(z => z.Id == id);
case SockType.Reminder:
return await ct.Reminder.AnyAsync(z => z.Id == id);
case SockType.Review:
return await ct.Review.AnyAsync(z => z.Id == id);
case SockType.License:
return await ct.License.AnyAsync(z => z.Id == id);
case SockType.TrialLicenseRequest:
return await ct.TrialLicenseRequest.AnyAsync(z => z.Id == id);
case SockType.SubscriptionServer:
return await ct.SubscriptionServer.AnyAsync(z => z.Id == id);
case SockType.Purchase:
return await ct.Purchase.AnyAsync(z => z.Id == id);
case SockType.VendorNotification:
return await ct.VendorNotification.AnyAsync(z => z.Id == id);
case SockType.Product:
return await ct.Product.AnyAsync(z => z.Id == id);
case SockType.GZCase:
return await ct.GZCase.AnyAsync(z => z.Id == id);
case SockType.CustomerNotifySubscription:
return await ct.CustomerNotifySubscription.AnyAsync(z => z.Id == id);
case SockType.Integration:
return await ct.Integration.AnyAsync(z => z.Id == id);
default:
throw new System.NotSupportedException($"Sockeye.Biz.BizObjectExistsInDatabase::ExistsAsync type {aType.ToString()} is not supported");
}
}
/////////////////////////////////////////////////////////////////////
}//eoc
}//eons