Exemple #1
0
        public void delete(ActiveRecord item)
        {
            DeleteQuery query = new DeleteQuery(item.GetType());

            query.addWhere("id", item.id.ToString());
            Console.WriteLine(query.build());
            query.exec();
        }
Exemple #2
0
        public void logicalDelete(ActiveRecord item)
        {
            UpdateQuery query = new UpdateQuery(item.GetType());

            query.addKeyValue("estado", "0");

            query.addWhere("id", item.id.ToString());
            Console.WriteLine(query.build());
            query.exec();
        }
Exemple #3
0
        public int insert(ActiveRecord item)
        {
            item.preInsert();
            InsertQuery query = new InsertQuery(item.GetType());

            foreach (KeyValuePair <string, string> properties in getProperties(item))
            {
                query.addKeyValue(properties.Key, properties.Value);
            }
            return(query.exec());
        }
Exemple #4
0
        public int update(ActiveRecord item)
        {
            UpdateQuery query = new UpdateQuery(item.GetType());

            foreach (KeyValuePair <string, string> properties in getProperties(item))
            {
                query.addKeyValue(properties.Key, properties.Value);
            }
            query.addWhere("id", item.id.ToString());
            Console.WriteLine(query.build());
            return(query.exec());
        }
Exemple #5
0
        public static Dictionary<string, object> GetData(ActiveRecord inst)
        {
            var t = inst.GetType();
            if (!rowCreators.ContainsKey(t))
                throw new Exception("No creator has been added for Type [" + t.FullName + "]");

            var rc = rowCreators[t];

            if( rc.GetDataFunction == null )
                throw new Exception( "No {GetData} Delegate has been added for Type [" + t.FullName + "]" );

            return rowCreators[t].GetDataFunction(inst);
        }
Exemple #6
0
        private Dictionary <String, String> getProperties(ActiveRecord item)
        {
            Dictionary <String, String> properties = new Dictionary <string, string>();

            foreach (PropertyInfo property in getProperties(item.GetType()))
            {
                if (property.PropertyType == typeof(List <>))
                {
                    //Si hay un 1 a muchos no deberia guardarlo
                }
                else if (property.Name == "table")
                {
                    //Ignorar
                }
                else if (property.PropertyType.IsPrimitive || property.PropertyType == typeof(Decimal) || property.PropertyType == typeof(String))
                {
                    try
                    {
                        properties.Add(property.Name, property.GetGetMethod().Invoke(item, null).ToString());
                    }
                    catch (NullReferenceException e)
                    {
                    }
                }
                else if (property.PropertyType == typeof(DateTime))
                {
                    //TODO
                    DateTime fecha = (DateTime)property.GetGetMethod().Invoke(item, null);
                    properties.Add(property.Name, fecha.ToShortDateString());
                }
                else
                {
                    //Aca obtengo el id del objeto relacionado
                    MethodInfo getPropAnidada = property.GetGetMethod();                                // Obtengo el getter de la propiedad
                    Object     objetoAnidado  = getPropAnidada.Invoke(item, null);                      // Obtengo el valor (el otro objeto)

                    //Capaz el objeto anidado no esta seado y es null, probablemente haya un problema con las FK
                    if (objetoAnidado != null)
                    {
                        Type       claseAnidada = objetoAnidado.GetType();                                          // Consigo la clase del objeto
                        MethodInfo getIdAnidado = claseAnidada.GetProperty("id").GetGetMethod();                    // Consigo el getter del id del objeto
                        properties.Add(property.Name + "_id", getIdAnidado.Invoke(objetoAnidado, null).ToString()); //Consigo el id y lo guardo en el diccionario
                    }
                }
            }
            return(properties);
        }
        public ActionResult SEOEditPanel(ActiveRecord record, bool showHeader, string cssTablerowClass)
        {
            if (!record.FieldExists("PageTitleTag"))
            {
                return(null);
            }

            CheckForNoShowHeader(record, ref showHeader);

            var data = new SEOViewData();

            data.DataRecord       = record;
            data.ShowHeader       = showHeader;
            data.CssTablerowClass = cssTablerowClass;
            // AF20140926: Invoke GetFullUrl method by reflection to get the overriden method inside each model rather than the ActiveRecord generic one
            data.Url = record.GetType().GetMethod("GetFullUrl", new Type[] { }).Invoke(record, new object[] { }).ToString();
            return(View(data));
        }
Exemple #8
0
 public static List<Person> GetContacts(ActiveRecord obj)
 {
     return ActiveRecord.Find<Person>("AssociatedKey", obj.GetType().Name + " " + obj.Id);
 }
Exemple #9
0
 public bool SetAssociatedKey(ActiveRecord obj)
 {
     return obj != null ? (AssociatedKey = obj.GetType().Name + " " + obj.Id) != null : false;
 }
Exemple #10
0
 private static string GetCacheKey(ActiveRecord record)
 {
     return record.GetType().Name + " " + record.Id;
 }