62 lines
1.8 KiB
C#
62 lines
1.8 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
|
|
{
|
|
|
|
//Turn a type and ID into a displayable name
|
|
internal static class BizObjectNameFetcher
|
|
{
|
|
|
|
internal static string Name(AyaTypeId tid, AyContext ct = null)
|
|
{
|
|
return Name(tid.ObjectType, tid.ObjectId, ct);
|
|
}
|
|
|
|
|
|
//Returns existance status of object type and id specified in database
|
|
internal static string Name(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.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
|
case AyaType.Widget:
|
|
return ct.Widget.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
|
case AyaType.Tag:
|
|
return ct.Tag.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
|
case AyaType.TagGroup:
|
|
return ct.TagGroup.Where(m => m.Id == id).Select(m => m.Name).FirstOrDefault();
|
|
|
|
default:
|
|
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
}//eoc
|
|
|
|
|
|
}//eons
|
|
|