private bool toPropsDTO(DBProperties p, ref DynamicProperties result) { try { result.ID = p.ID; result.entityType = p.entityType; result.objId = p.objId; result.Vals = p.Vals; result.updated = p.updated; return(true); } catch { return(false); } }
public DynamicProperties GetPropertiesInstance(short entityType, int objId) { try { DynamicProperties newdP = new DynamicProperties(); var result = props.GetAll().Where(x => (x.entityType == entityType) && (x.objId == objId)); if (result.Any()) { if (toPropsDTO(result.FirstOrDefault(), ref newdP)) { return(newdP); } } using (ISession Session = ConnectionHelper.CreateNewSession()) { using (ITransaction Transaction = Session.BeginTransaction()) { var gvar = new DBProperties(); // gvar.ID = newdP.ID; // ID should be Autogenerated by DB gvar.entityType = (short)entityType; gvar.objId = objId; Dictionary <string, DynamicProperty> defProps = new Dictionary <string, DynamicProperty>(); defProps = DefaultProperties.fillProperties(ref defProps, (EntitiesEnum)entityType, -1, objId, ""); gvar.Vals = JsonConvert.SerializeObject(defProps); gvar.updated = DateTime.UtcNow; Session.Save(gvar); Transaction.Commit(); if (toPropsDTO(gvar, ref newdP)) { return(newdP); } } } } catch (Exception e) { log.Error("Error: GetPropertiesInstance: " + e); } return(null); }
public bool SavePropertiesInstance(DynamicProperties newdP) { try { using (ISession Session = ConnectionHelper.CreateNewSession()) { using (ITransaction Transaction = Session.BeginTransaction()) { var result = Session.Get <DBProperties>(newdP.ID); if (result != null) { result.entityType = newdP.entityType; result.objId = newdP.objId; result.Vals = newdP.Vals; result.updated = DateTime.UtcNow; Session.Update(result); } else { var gvar = new DBProperties(); // gvar.ID = newdP.ID; // ID should be Autogenerated by DB gvar.entityType = (short)newdP.entityType; gvar.objId = newdP.objId; gvar.Vals = newdP.Vals; gvar.updated = DateTime.UtcNow; Session.Save(gvar); } Transaction.Commit(); return(true); } } } catch (Exception e) { log.Error("Error: UpdateProperties: " + e); } return(false); }