Esempio n. 1
0
        public List <Model> read(string tquery, bool api = false)
        {
            TSRequest request = new TSRequest(tquery);
            TSFactory factory = new TSFactory(this, request);

            return(factory.instances(request.model, request.filter, request.level, request.order, "", request.page, 1, ""));
        }
Esempio n. 2
0
        /// <summary>
        /// Devuelve una instancia de un modelo
        /// </summary>
        /// <param name="modelname">Nombre del modelo</param>
        /// <param name="id">Identificador de la instancia</param>
        /// <param name="level">Nivel de intanciación</param>
        /// <param name="workspace"></param>
        /// <returns></returns>
        public Model instance(string modelname,
                              int id,
                              int level        = 1,
                              string workspace = "")
        {
            TSRequest tsr = new TSRequest(modelname + "/" + id + "/_" + this._request.dto);

            Object[] args           = { tsr };
            Model    TrivialIntance = (Model)Activator.CreateInstance(Type.GetType("TSTrivialAPI.Domain." + modelname), args);

            // -- si el nivel de subinstanciacion es cero solo debolvemos un modelo en blanco
            if (level == 0)
            {
                return(TrivialIntance);
            }

            var nombre_key = TrivialIntance.getKeyName();

            if (nombre_key == "")
            {
                nombre_key = TrivialIntance.getDefaultKeyName();
            }

            Dictionary <string, object> filter = new Dictionary <string, object>()
            {
            };

            if (id > 0)
            {
                filter = new Dictionary <string, object>()
                {
                    { nombre_key, id }
                };
            }

            // -- se recupera la instancia y se identifican las subentidades
            var           instance    = TrivialIntance.select(filter)[0];
            List <string> subentities = instance.subinstances();

            // -- se inyecta cada una de las subinstancias
            foreach (string propname in subentities)
            {
                PropertyInfo piInstance = instance.GetType().GetProperty(propname);
                var          newtype    = piInstance.PropertyType.FullName;
                piInstance.SetValue(instance, this.instance(newtype.Split(".")[2], instance.getInstanceId(), level - 1));
            }
            return(instance);
        }
Esempio n. 3
0
 public TSContext(string name, TSRequest request = null)
 {
     this._request = request;
 }
Esempio n. 4
0
 public TSFactory(TSContext context, TSRequest request)
 {
     this._context = context;
     this._request = request;
 }