Exemple #1
0
        public int Count(FilterInfo filters = null)
        {
            IQueryable<log> items = context.log;

            if (filters != null && (filters.Filters != null && filters.Filters.Count > 0))
            {
                GridHelper.ProcessFilters<log>(filters, ref items);
            }

            return items.Count();
        }
Exemple #2
0
        public FilterInfo Clone()
        {
            FilterInfo clone = new FilterInfo { Field = this.Field, Logic = this.Logic, Operator = this.Operator, Value = this.Value };

            if (Filters != null)
            {
                clone.Filters = new List<FilterInfo>();
                foreach (var f in Filters)
                {
                    clone.Filters.Add(f.Clone());
                }
            }

            return clone;
        }
Exemple #3
0
        //TODO: pull default values from config
        internal void Populate()
        {
            if (HttpContext.Current != null)
            {
                HttpRequest curRequest = HttpContext.Current.Request;
                if (curRequest["page"] != null)
                {
                    this.Page = int.Parse(curRequest["page"]);
                }
                if (curRequest["pageSize"] != null)
                {
                    this.PageSize = int.Parse(curRequest["pageSize"]);
                }
                if (curRequest["skip"] != null)
                {
                    this.Skip = int.Parse(curRequest["skip"]);
                }
                if (curRequest["take"] != null)
                {
                    this.Take = int.Parse(curRequest["take"]);
                }
                //this.FilterLogic = curRequest["filter[logic]"];

                //build sorting objects from services
                var sorts = new List <ProjectLog.Infrastructure.SortingInfo>();
                var x     = 0;
                //List<string> sortList = sort.Split(',').ToList();
                //foreach (string s in sortList)
                //{
                //    var jsonResult = JObject.Parse(s);
                //    sorts.Add(new SortingInfo { SortOn = jsonResult["field"].ToString(), SortOrder = jsonResult["dir"].ToString() });
                //}

                //while (x < 20)
                //{
                //    var sortDirection = curRequest["sort[" + x + "][dir]"];
                //    if (sortDirection == null)
                //    {
                //        break;
                //    }
                //    var sortOn = curRequest["sort[" + x + "][field]"];
                //    if (sortOn != null)
                //    {
                //        sorts.Add(new SortingInfo { SortOn = sortOn, SortOrder = sortDirection });
                //    }
                //    x++;
                //}
                //Sortings = sorts;

                //build sorting objects
                //sorts = new List<SortingInfo>();
                x = 0;
                while (x < 20)
                {
                    var sortDirection = curRequest["sort[" + x + "][dir]"];
                    if (sortDirection == null)
                    {
                        break;
                    }
                    var sortOn = curRequest["sort[" + x + "][field]"];
                    if (sortOn != null)
                    {
                        sorts.Add(new ProjectLog.Infrastructure.SortingInfo {
                            SortOn = sortOn, SortOrder = sortDirection
                        });
                    }
                    x++;
                }
                Sortings = sorts;

                //build filter objects
                var filters = new ProjectLog.Infrastructure.FilterInfo();
                var logic   = curRequest["filter[logic]"];
                filters.Logic = logic;

                bool stopLevel1 = false; int level1 = 0;
                while (!stopLevel1)
                {
                    FilterInfo fi     = new FilterInfo();
                    var        field1 = curRequest["filter[filters][" + level1 + "][field]"];
                    if (field1 == null)
                    {
                        field1 = curRequest["filter[filters][" + level1 + "][filters][0][field]"];
                        if (field1 == null)
                        {
                            stopLevel1 = true;
                        }
                        else //level 1
                        {
                            fi.Logic = curRequest["filter[filters][" + level1 + "][logic]"];

                            bool stopLevel2 = false; int level2 = 0;
                            while (!stopLevel2)
                            {
                                var field2 = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][field]"];
                                if (field2 == null)
                                {
                                    stopLevel2 = true;
                                }
                                else
                                {
                                    var fi2 = new ProjectLog.Infrastructure.FilterInfo();
                                    fi2.Field    = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][field]"];
                                    fi2.Operator = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][operator]"];
                                    fi2.Value    = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][value]"];

                                    if (fi.Filters == null)
                                    {
                                        fi.Filters = new List <ProjectLog.Infrastructure.FilterInfo>();
                                    }
                                    fi.Filters.Add(fi2);

                                    ++level2;
                                }
                            }
                        }
                    }
                    else
                    {
                        fi.Field    = field1;
                        fi.Operator = curRequest["filter[filters][" + level1 + "][operator]"];
                        fi.Value    = curRequest["filter[filters][" + level1 + "][value]"];
                    }

                    if (!stopLevel1)
                    {
                        if (filters.Filters == null)
                        {
                            filters.Filters = new List <ProjectLog.Infrastructure.FilterInfo>();
                        }
                        filters.Filters.Add(fi);

                        ++level1;
                    }
                }

                Filters = filters;
            }
        }
Exemple #4
0
        //TODO: pull default values from config
        internal void Populate()
        {
            if (HttpContext.Current != null)
            {
                HttpRequest curRequest = HttpContext.Current.Request;
                if (curRequest["page"] != null)
                    this.Page = int.Parse(curRequest["page"]);
                if (curRequest["pageSize"] != null)
                    this.PageSize = int.Parse(curRequest["pageSize"]);
                if (curRequest["skip"] != null)
                    this.Skip = int.Parse(curRequest["skip"]);
                if (curRequest["take"] != null)
                    this.Take = int.Parse(curRequest["take"]);
                //this.FilterLogic = curRequest["filter[logic]"];

                //build sorting objects from services
                var sorts = new List<ProjectLog.Infrastructure.SortingInfo>();
                var x = 0;
                //List<string> sortList = sort.Split(',').ToList();
                //foreach (string s in sortList)
                //{
                //    var jsonResult = JObject.Parse(s);
                //    sorts.Add(new SortingInfo { SortOn = jsonResult["field"].ToString(), SortOrder = jsonResult["dir"].ToString() });
                //}

                //while (x < 20)
                //{
                //    var sortDirection = curRequest["sort[" + x + "][dir]"];
                //    if (sortDirection == null)
                //    {
                //        break;
                //    }
                //    var sortOn = curRequest["sort[" + x + "][field]"];
                //    if (sortOn != null)
                //    {
                //        sorts.Add(new SortingInfo { SortOn = sortOn, SortOrder = sortDirection });
                //    }
                //    x++;
                //}
                //Sortings = sorts;

                //build sorting objects
                //sorts = new List<SortingInfo>();
                x = 0;
                while (x < 20)
                {
                    var sortDirection = curRequest["sort[" + x + "][dir]"];
                    if (sortDirection == null)
                    {
                        break;
                    }
                    var sortOn = curRequest["sort[" + x + "][field]"];
                    if (sortOn != null)
                    {
                        sorts.Add(new ProjectLog.Infrastructure.SortingInfo { SortOn = sortOn, SortOrder = sortDirection });
                    }
                    x++;
                }
                Sortings = sorts;

                //build filter objects
                var filters = new ProjectLog.Infrastructure.FilterInfo();
                var logic = curRequest["filter[logic]"];
                filters.Logic = logic;

                bool stopLevel1 = false; int level1 = 0;
                while (!stopLevel1)
                {
                    FilterInfo fi = new FilterInfo();
                    var field1 = curRequest["filter[filters][" + level1 + "][field]"];
                    if (field1 == null)
                    {
                        field1 = curRequest["filter[filters][" + level1 + "][filters][0][field]"];
                        if (field1 == null)
                            stopLevel1 = true;
                        else //level 1
                        {
                            fi.Logic = curRequest["filter[filters][" + level1 + "][logic]"];

                            bool stopLevel2 = false; int level2 = 0;
                            while (!stopLevel2)
                            {
                                var field2 = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][field]"];
                                if (field2 == null)
                                    stopLevel2 = true;
                                else
                                {
                                    var fi2 = new ProjectLog.Infrastructure.FilterInfo();
                                    fi2.Field = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][field]"];
                                    fi2.Operator = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][operator]"];
                                    fi2.Value = curRequest["filter[filters][" + level1 + "][filters][" + level2 + "][value]"];

                                    if (fi.Filters == null)
                                        fi.Filters = new List<ProjectLog.Infrastructure.FilterInfo>();
                                    fi.Filters.Add(fi2);

                                    ++level2;
                                }
                            }
                        }
                    }
                    else
                    {
                        fi.Field = field1;
                        fi.Operator = curRequest["filter[filters][" + level1 + "][operator]"];
                        fi.Value = curRequest["filter[filters][" + level1 + "][value]"];
                    }

                    if (!stopLevel1)
                    {
                        if (filters.Filters == null)
                            filters.Filters = new List<ProjectLog.Infrastructure.FilterInfo>();
                        filters.Filters.Add(fi);

                        ++level1;
                    }
                }

                Filters = filters;
            }
        }
Exemple #5
0
        public List<log> Find(int skip = 0, int? take = null, List<SortingInfo> sortings = null, FilterInfo filters = null)
        {
            IQueryable<log> atributes = context.log;

            if (filters != null && (filters.Filters != null && filters.Filters.Count > 0))
            {
                filters.FormatFieldToUnderscore();
                GridHelper.ProcessFilters<log>(filters, ref atributes);
            }

            if (sortings != null && sortings.Count > 0)
            {
                foreach (var s in sortings)
                {
                    string sortOn = this.MapSort(s.SortOn);
                    atributes = atributes.OrderBy(sortOn + " " + s.SortOrder);
                }
            }
            else
            {
                atributes = atributes.OrderBy("id desc");
            }

            var takeActions = atributes;
            if (take != null)
            {
                takeActions = atributes.Skip(skip).Take((int)take);
            }

            List<log> actionList = takeActions.ToList();

            return actionList;
        }