This commit is contained in:
2019-05-16 22:28:28 +00:00
parent acc40671a0
commit 8fe776a3ac
21 changed files with 137 additions and 149 deletions

View File

@@ -1,48 +1,48 @@
using AyaNova.Models;
using AyaNova.Biz;
// using AyaNova.Models;
// using AyaNova.Biz;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;
using System.Reflection;
using System;
// using Microsoft.EntityFrameworkCore;
// using Microsoft.EntityFrameworkCore.Metadata;
// using System.Reflection;
// using System;
namespace AyaNova.Biz
{
// namespace AyaNova.Biz
// {
/// <summary>
/// Returns owner Id if the object exists or 0 if exists but there is no owner ID property or -1 if the object doesn't exist
/// </summary>
internal static class AyaObjectOwnerId
{
internal static long Get(AyaTypeId o, AyContext ct)
{
if (o.IsEmpty) return -1;
// /// <summary>
// /// Returns owner Id if the object exists or 0 if exists but there is no owner ID property or -1 if the object doesn't exist
// /// </summary>
// internal static class AyaObjectOwnerId
// {
// internal static long Get(AyaTypeId o, AyContext ct)
// {
// if (o.IsEmpty) return -1;
//Get the type of the model of AyaObject
Type t = Type.GetType("AyaNova.Models." + o.ObjectType.ToString());
// //Get the type of the model of AyaObject
// Type t = Type.GetType("AyaNova.Models." + o.ObjectType.ToString());
//Run a find query on the db context based on the model's type
object record = ct.Find(t, o.ObjectId);
if (record == null)
{
return -1;
}
// //Run a find query on the db context based on the model's type
// object record = ct.Find(t, o.ObjectId);
// if (record == null)
// {
// return -1;
// }
PropertyInfo ownerIdPropertyInfo = record.GetType().GetProperty("OwnerId");
// PropertyInfo ownerIdPropertyInfo = record.GetType().GetProperty("OwnerId");
if (ownerIdPropertyInfo == null)
return 0;//object exists and it doesn't have an ownerID property
// if (ownerIdPropertyInfo == null)
// return 0;//object exists and it doesn't have an ownerID property
long ret = (long)ownerIdPropertyInfo.GetValue(record, null);
// long ret = (long)ownerIdPropertyInfo.GetValue(record, null);
return ret;
// return ret;
}
// }
}
// }
}//eons
// }//eons