Ejemplo n.º 1
0
        public PagedListParameters(NameValueCollection flexGridPagingFormCollection)
        {
            PageIndex         = 1;
            PageSize          = 10;
            ReturnColumns     = new List <Column>();
            SortColumns       = new List <Column>();
            FilterColumns     = new List <Column>();
            FilterExpressions = new List <Expression <Func <object, bool> > >();
            GroupColumns      = new List <Column>();
            AggregateColumns  = new List <AggregateColumn>();

            //Generic Filter
            foreach (var key in flexGridPagingFormCollection.AllKeys) // <-- No duplicates returned.
            {
                //if (key == "page" || key == "size" || key == "orderBy") { continue; }
                switch (key)
                {
                case "page":
                    PageIndex = int.Parse(flexGridPagingFormCollection[key], CultureInfo.InvariantCulture);
                    break;

                case "size":
                    PageSize = int.Parse(flexGridPagingFormCollection[key], CultureInfo.InvariantCulture);
                    break;

                case "orderBy":
                    var sortItems = flexGridPagingFormCollection["orderBy"].Split('-');
                    SortColumn    = sortItems[0];
                    SortDirection = sortItems[1];
                    break;

                default:
                    var column = new Column {
                        Member = key, Value = flexGridPagingFormCollection[key]
                    };
                    FilterColumns.Add(column);
                    break;
                }
            }



            SkipCount = (PageIndex - 1) * PageSize;
            TakeCount = PageSize;



            if (String.IsNullOrEmpty(SortColumn) == true)
            {
                SortColumn = Constants.IdColumn;
            }
            if (String.IsNullOrEmpty(SortDirection) == true)
            {
                SortDirection = "asc";
            }
            SortAssending = (SortDirection.ToUpperInvariant() == "ASC");
            var sortColumn = new Column {
                Member = SortColumn, SortAssending = SortAssending
            };

            SortColumns.Add(sortColumn);
        }