Exemplo n.º 1
0
 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);
 }