Exemplo n.º 1
0
        protected override void InternalGET(System.Web.HttpContext context, HandlerTimedCache cache)
        {
            var roles = UserHelper.GetUserRoles(context.User.Identity.Name);

            var dataHelper = new PdbTwoTableHelper(Config.GetConfig("PDP.Data"), "Properties");

            var ids = new List <string>();
            var id  = WebUtil.GetParam(context, "id", true);

            if (id != null)
            {
                ids.Add(id);
            }
            else
            {
                var idList = WebUtil.GetParam(context, "ids", false);
                ids.AddRange(idList.Split(','));
            }
            var list = dataHelper.Query(ids, roles);

            context.Response.Write(WebUtil.ObjectToJson(list));
        }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
0
        public void TestQueryNoExprsForEveryone()
        {
            // Should be number of cols in the DB attributes tables, but also one for the primary key.
            PdbResultsWithMetadata results = _helper.Query(null, new SecurityRole[] { SecurityRole.@public });

            Assert.AreEqual(612, results.Values.Count,
                            "Wrong number of results for primary + secondary query for all users.");
            Assert.AreEqual(results.Values.Count, results.TotalResults,
                            "Total results did not match the number of results returned.");
        }