Example #1
0
        protected override void InternalGET(HttpContext context, HandlerTimedCache cache)
        {
            IList <SecurityRole> roles = UserHelper.GetUserRoles(context.User.Identity.Name);

            //Get the paging parameters...
            int page     = WebUtil.ParseIntParam(context, "page");
            int pageSize = WebUtil.ParseIntParam(context, "pageSize");


            // Check to see if this is a csv export request.  Runs the normal query (with no paging).
            bool csv = false;

            WebUtil.ParseOptionalBoolParam(context, "csv", ref csv);

            // If this is csv, we want all data - override any paging
            if (csv)
            {
                page     = -1;
                pageSize = -1;
            }
            IList <IExpression> expressions = ParseExpressions(context);

            // Now get the ordering parameters, if specified.
            int sortCol = -1;

            WebUtil.ParseOptionalIntParam(context, "sortBy", ref sortCol);
            SortType?sortDir = null;

            if (sortCol >= 0)
            {
                // Default is ascending sort, passing false means descending.
                bool ascending = true;
                WebUtil.ParseOptionalBoolParam(context, "sortasc", ref ascending);
                sortDir = ascending ? SortType.Asc : SortType.Desc;
            }
            PdbTwoTableHelper dataHelper = new PdbTwoTableHelper(Config.GetConfig("PDP.Data"), "Properties", PdbEntityType.Properties);

            // Now get the grouping parameters, if specified.
            IList <string>         groupBys = WebUtil.GetJsonStringArrayParam(context, "groupby", true);
            PdbResultsWithMetadata list;

            if ((groupBys != null) && (groupBys.Count > 0))
            {
                list = dataHelper.GroupedQuery(expressions, groupBys, sortCol, sortDir, roles, pageSize, page);
            }
            else
            {
                list = dataHelper.Query(expressions, sortCol, sortDir, roles, pageSize, page);
            }

            // If this was a csv request, format it and return it instead
            if (csv)
            {
                // Generate actual csv data, determine if this is groupby'd or not
                string export = dataHelper.ResultsAsCsv(list, ((groupBys != null) && (groupBys.Count > 0)));

                // Setup the response to handle this type of request
                context.Response.AddHeader("Content-Disposition", "attachment;filename=Furman_Center_SHIP_Properties.csv");
                context.Response.ContentType = "text/csv";
                context.Response.Write(export);
                return;
            }
            context.Response.Write(WebUtil.ObjectToJson(list));
        }
Example #2
0
        public void TestSingleGroupBy()
        {
            IExpression[] exprs = new IExpression[] {
                // This is a secondary table attribute.
                new EqualExpression("Agency", "Housing Development Corporation")
            };
            PdbResultsWithMetadata result = _helper.GroupedQuery(exprs,
                                                                 new string[] { "OwnerProfitStatus" },
                                                                 -1, null, _publicRoles, 0, 0);

            DumpAggregateResults(result);
            Assert.AreEqual(3, result.Values.Count, "Wrong number of grouped results.");
            Assert.AreEqual(result.Values.Count, result.TotalResults, "Total results should be the same as number received when no paging specified.");
        }