Ejemplo n.º 1
0
 private static object CreateResponse(string table, QueryModel query, IEnumerable<dynamic> results, string columns, int page, int pageSize, int total)
 {
     return new
                {
                    page,
                    pageSize,
                    total,
                    query = new
                                {
                                    table,
                                    columns,
                                    where = query.Where ?? string.Empty,
                                    orderby = query.OrderBy ?? string.Empty
                                },
                    results
                };
 }
Ejemplo n.º 2
0
        public ContentResult Table(string table, QueryModel query)
        {
            if (string.IsNullOrWhiteSpace(table))
                throw new HttpException(404, "Table name: " + table + " not found.");

            var page = query.Page ?? 1;
            var pageSize = query.PageSize ?? 25;
            var columns = query.GetColumns();

            var model = CreateDynamicModel(table);

            var everything = model.All(query.Where, query.OrderBy, columns: columns);
            // ReSharper disable PossibleMultipleEnumeration
            var total = everything.Count();
            var results = everything.Skip((page - 1) * pageSize).Take(pageSize);
            // ReSharper restore PossibleMultipleEnumeration

            var response = CreateResponse(table, query, results, columns, page, pageSize, total);
            return JsonContent(response);
        }