예제 #1
0
        public List <T> all(List <QueryParam> queryParams, bool withIncludes = true)
        {
            if (!policy.checkList(typeof(T)))
            {
                throw new UnauthorizedException("You do not have permission to list requested resources.");
            }

            // transform queryParams to DbParams
            var dbParams = new DbParams();

            foreach (var param in queryParams)
            {
                dbParams.add(new DbParam(param.Name, param.Value, this.transformer.getParamType(param.Name), param.Operator, param.BooleanOpr));
            }

            // read data
            var reader = DB.all(this.tableName, manipulateParams(dbParams));
            var result = new List <T>();

            while (reader.Read())
            {
                var transformed = this.transformer.transform(reader);
                transformed = withIncludes ? this.addIncludes(transformed) : transformed;
                result.Add(transformed);
            }

            reader.Close();
            return(result);
        }