55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using Microsoft.EntityFrameworkCore;
|
|
namespace AyaNova.Biz
|
|
{
|
|
|
|
//Turn a type and ID into a displayable name
|
|
//Used by search and eventlog processor
|
|
internal static class BizObjectNameFetcherDirect
|
|
{
|
|
internal static string Name(AyaType ayaType, long id, long translationid, System.Data.Common.DbCommand cmd)
|
|
{
|
|
try
|
|
{
|
|
string ret;
|
|
|
|
cmd.CommandText = $"select PUBLIC.AYGETNAME({id}, {(int)ayaType}, {translationid}) as m";
|
|
using (var dr = cmd.ExecuteReader())
|
|
{
|
|
if (dr.Read())
|
|
{
|
|
if (dr.IsDBNull(0))
|
|
ret = $"?? type:{ayaType},id:{id}";
|
|
else
|
|
ret = dr.GetString(0);
|
|
}
|
|
else
|
|
{
|
|
ret = "-";
|
|
}
|
|
//return dr.Read() ? dr.GetString(0) : "-";
|
|
}
|
|
return ret;
|
|
|
|
}
|
|
catch
|
|
{
|
|
((ILogger)AyaNova.Util.ApplicationLogging.CreateLogger("BizObjectNameFetcherDirect")).LogError($"### Error fetching for type {ayaType}");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
//warning: use the above in a loop, not this one
|
|
internal static string Name(AyaType ayaType, long id, long translationId, AyaNova.Models.AyContext ct)
|
|
{
|
|
using (var command = ct.Database.GetDbConnection().CreateCommand())
|
|
{
|
|
ct.Database.OpenConnection();
|
|
return Name(ayaType, id,translationId, command);
|
|
}
|
|
}
|
|
|
|
}//eoc
|
|
}//eons
|
|
|