public object PostUpdate(ExpandoObject objectToUpdate)
{
var typeOfObject = objectToUpdate.FirstOrDefault(x => x.Key == "typeOfObject").Value.ToString();
objectToUpdate = (ExpandoObject)objectToUpdate.FirstOrDefault(x => x.Key == "objectToUpdate").Value;
var ar = typeOfObject.Split(',');
var currentType = Type.GetType(ar[0] + ", " + ar[1]);
var ob = Activator.CreateInstance(currentType,null);
foreach (var prop in objectToUpdate)
{
var propKey = prop.Key;
var propI = currentType.GetProperty(propKey);
if (propI != null)
{
Helper.SetValue(ob, propI.Name, prop.Value);
}
}
var uioMaticAttri = (UIOMaticAttribute)Attribute.GetCustomAttribute(currentType, typeof(UIOMaticAttribute));
var db = (Database)DatabaseContext.Database;
if (!string.IsNullOrEmpty(uioMaticAttri.ConnectionStringName))
db = new Database(uioMaticAttri.ConnectionStringName);
var tableName = ((TableNameAttribute)Attribute.GetCustomAttribute(currentType, typeof(TableNameAttribute))).Value;
var primaryKeyColum = string.Empty;
var primKeyAttri = currentType.GetCustomAttributes().Where(x => x.GetType() == typeof(PrimaryKeyAttribute));
if (primKeyAttri.Any())
primaryKeyColum = ((PrimaryKeyAttribute)primKeyAttri.First()).Value;
foreach (var prop in currentType.GetProperties())
{
foreach (var attri in prop.GetCustomAttributes(true))
{
if (attri.GetType() == typeof(PrimaryKeyColumnAttribute))
primaryKeyColum = ((PrimaryKeyColumnAttribute)attri).Name ?? prop.Name;
}
}
var tmp = UpdatingObject;
if (tmp != null)
tmp(this, new ObjectEventArgs(ob));
db.Update(ob);
var temp = UpdatedObject;
if (temp != null)
temp(this, new ObjectEventArgs(ob));
return ob;
}