/// <summary>
        /// Create DataSource Request
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static DataSourceRequest CreateDataSourceRequest(this DataSourceRequestOptions req)
        {
            var request = new DataSourceRequest();

            if (req.Sort != null)
            {
                request.Sorts = DataSourceDescriptorSerializer.Deserialize <SortDescriptor>(req.Sort);
            }


            request.Page = req.Page;

            request.PageSize = req.PageSize;

            if (req.Filter != null)
            {
                request.Filters = FilterDescriptorFactory.Create(req.Filter);
            }

            if (req.Group != null)
            {
                request.Groups = DataSourceDescriptorSerializer.Deserialize <GroupDescriptor>(req.Group);
            }

            if (req.Aggregate != null)
            {
                request.Aggregates = DataSourceDescriptorSerializer.Deserialize <AggregateDescriptor>(req.Aggregate);
            }

            return(request);
        }
Exemple #2
0
        public static DataSourceRequest Parse(dynamic param)
        {
            dynamic objParamInfo = param.gridState;
            string  page         = objParamInfo.page;
            string  pageSize     = objParamInfo.pageSize;
            string  sort         = objParamInfo.sort;
            string  group        = objParamInfo.group;
            string  filter       = objParamInfo.filter;
            string  aggregates   = objParamInfo.aggregate;

            DataSourceRequest request = new DataSourceRequest();

            try
            {
                if (!string.IsNullOrEmpty(page))
                {
                    int p = 0;
                    Int32.TryParse(page, out p);
                    request.Page = p;
                }

                if (!string.IsNullOrEmpty(pageSize))
                {
                    int psize = 0;
                    Int32.TryParse(pageSize, out psize);
                    request.PageSize = psize;
                }

                if (!string.IsNullOrEmpty(sort))
                {
                    request.Sorts = DataSourceDescriptorSerializer.Deserialize <SortDescriptor>(sort);
                }

                if (!string.IsNullOrEmpty(filter))
                {
                    request.Filters = FilterDescriptorFactory.Create(filter);
                }

                if (!string.IsNullOrEmpty(group))
                {
                    request.Groups = DataSourceDescriptorSerializer.Deserialize <GroupDescriptor>(group);
                }

                if (!string.IsNullOrEmpty(aggregates))
                {
                    request.Aggregates = DataSourceDescriptorSerializer.Deserialize <AggregateDescriptor>(group);
                }
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }
            return(request);
        }
Exemple #3
0
        private static IList <SortDescriptor> ParseSorts(string body)
        {
            dynamic json = JsonConvert.DeserializeObject <dynamic>(body);
            IList <SortDescriptor> sortDescriptors = new List <SortDescriptor>();

            if (json != null && json.sort != null)
            {
                IList <CustomDataSourceRequestSort> sortsParser = JsonConvert.DeserializeObject <IList <CustomDataSourceRequestSort> >(json.sort.ToString());

                ////if (sortsParser != null && sortsParser.Count > 0)
                ////{
                ////    foreach (var item in sortsParser)
                ////    {
                ////        sortDescriptors.Add(new SortDescriptor(item.Field, item.Dir == "asc" ? ListSortDirection.Ascending : ListSortDirection.Descending));
                ////    }
                ////}

                var sortResult = new StringBuilder();
                if (sortsParser != null && sortsParser.Count > 0)
                {
                    var balance = sortsParser.Count;
                    foreach (var item in sortsParser)
                    {
                        sortResult.Append($"{item.Field}-{item.Dir}");

                        balance--;
                        if (balance > 0)
                        {
                            sortResult.Append("~");
                        }
                    }
                }

                sortDescriptors = DataSourceDescriptorSerializer.Deserialize <SortDescriptor>(sortResult.ToString());
            }

            return(sortDescriptors);
        }