Beispiel #1
0
        private static Type GetDaoType(ICrudResponseProvider dcp)
        {
            string daoName = dcp.DaoInfo.DaoName;
            Type   daoType = dcp.DaoProxyRegistration.ServiceProvider[daoName];

            return(daoType);
        }
Beispiel #2
0
        public CrudResponse Retrieve(ICrudResponseProvider dcp)
        {
            Type       daoType   = GetDaoType(dcp);
            Database   database  = dcp.DaoProxyRegistration.Database;
            MethodInfo daoMethod = daoType.GetMethod("GetById", new Type[] { typeof(long), typeof(Database) });
            long       id        = GetRequestBody(HttpContext.Request).FromJson <long>();

            return(new CrudResponse {
                CxName = Dao.ConnectionName(daoType), Success = true, Dao = daoMethod.Invoke(null, new object[] { id, database }).ToJsonSafe()
            });
        }
Beispiel #3
0
        public CrudResponse Update(ICrudResponseProvider dcp)
        {
            Type       daoType   = GetDaoType(dcp);
            Database   database  = dcp.DaoProxyRegistration.Database;
            MethodInfo daoMethod = daoType.GetMethod("Update", new Type[] { typeof(Database) });
            object     instance  = GetRequestBody(HttpContext.Request).FromJson(daoType);

            daoMethod.Invoke(instance, new object[] { database });
            return(new CrudResponse {
                CxName = Dao.ConnectionName(daoType), Success = true, Dao = instance.ToJsonSafe()
            });
        }
Beispiel #4
0
        public CrudResponse Query(ICrudResponseProvider dcp)
        {
            Type        daoType   = GetDaoType(dcp);
            Database    database  = dcp.DaoProxyRegistration.Database;
            MethodInfo  daoMethod = daoType.GetMethod("Where", new Type[] { typeof(QiQuery), typeof(Database) });
            QiQuery     query     = GetRequestBody(HttpContext.Request).FromJson <QiQuery>();
            IEnumerable results   = (IEnumerable)daoMethod.Invoke(null, new object[] { query, database });

            return(new CrudResponse {
                CxName = Dao.ConnectionName(daoType), Success = true, Dao = results.ToJsonSafe()
            });
        }
Beispiel #5
0
        public CrudResponse SaveCollection(ICrudResponseProvider dcp)
        {
            Type        daoType        = GetDaoType(dcp);
            Database    database       = dcp.DaoProxyRegistration.Database;
            Type        collectionType = daoType.Assembly.GetType("{0}.{1}Collection"._Format(daoType.Namespace, daoType.Name));
            IEnumerable values         = (IEnumerable)GetRequestBody(HttpContext.Request).FromJson(daoType.MakeArrayType());
            object      collection     = collectionType.Construct();

            collection.Invoke("AddRange", values);
            MethodInfo saveMethod = collectionType.GetMethod("Save", new Type[] { typeof(Database) });

            saveMethod.Invoke(collection, new object[] { database });
            return(new CrudResponse {
                CxName = Dao.ConnectionName(daoType), Success = true, Dao = collection.ToJsonSafe()
            });
        }