77 lines
2.4 KiB
C#
77 lines
2.4 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
|
|
{
|
|
|
|
/*
|
|
|
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
command.CommandText = $"SELECT m.name FROM awidget AS m WHERE m.id = {id} LIMIT 1";
|
|
ct.Database.OpenConnection();
|
|
using (var dr = command.ExecuteReader())
|
|
{
|
|
|
|
// do something with result
|
|
return dr.Read() ? dr.GetString(0) : "UNKNOWN";
|
|
}
|
|
}
|
|
*/
|
|
//Turn a type and ID into a displayable name
|
|
internal static class BizObjectNameFetcherDirect
|
|
{
|
|
|
|
internal static string Name(AyaTypeId tid, System.Data.Common.DbCommand cmd)
|
|
{
|
|
return Name(tid.ObjectType, tid.ObjectId, cmd);
|
|
}
|
|
|
|
|
|
//Returns existance status of object type and id specified in database
|
|
internal static string Name(AyaType aytype, long id, System.Data.Common.DbCommand cmd)
|
|
{
|
|
string TABLE = string.Empty;
|
|
switch (aytype)
|
|
{
|
|
case AyaType.User:
|
|
TABLE = "auser";
|
|
break;
|
|
case AyaType.Widget:
|
|
TABLE = "awidget";
|
|
break;
|
|
case AyaType.Tag:
|
|
TABLE = "atag";
|
|
break;
|
|
case AyaType.TagGroup:
|
|
TABLE = "ataggroup";
|
|
break;
|
|
default:
|
|
throw new System.NotSupportedException($"AyaNova.BLL.BizObjectNameFetcher::Name type {aytype.ToString()} is not supported");
|
|
}
|
|
cmd.CommandText = $"SELECT m.name FROM {TABLE} AS m WHERE m.id = {id} LIMIT 1";
|
|
using (var dr = cmd.ExecuteReader())
|
|
return dr.Read() ? dr.GetString(0) : "UNKNOWN";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
}//eoc
|
|
|
|
|
|
}//eons
|
|
|