Ejemplo n.º 1
0
        public void TestJsonParse()
        {
            var dl = new DataList();
            var it = dl.AddItem();

            it.Set("firstName", "noam");
            it.Set("lastName", "honig");
            var kids = new DataList();
            var kit  = kids.AddItem();

            kit.Set("firstName", "maayan");
            kit = kids.AddItem();
            kit.Set("firstName", "itamar");
            kit = kids.AddItem();
            kit.Set("firstName", "ofri");
            it.Set("kids", kids);

            it = dl.AddItem();
            it.Set("firstName", "yael");
            it.Set("lastName", "Katri Honig");
            var x     = dl.ToJson();
            var newDl = DataList.FromJson(x);

            newDl.Count.ShouldBe(2);
            newDl[0].Get("firstName").ShouldBe("noam");
            newDl[0].GetList("kids")[2].Get("firstName").ShouldBe("ofri");
        }
Ejemplo n.º 2
0
        public static DataList ToDataList(this ENV.Data.Entity entity, FilterBase where = null, Sort orderBy = null, params ColumnBase[] columns)
        {
            var result   = new DataList();
            int pageSize = 100;
            int pageNum  = 0;
            {
                var s = System.Web.HttpContext.Current.Request["PageNum"];
                if (!string.IsNullOrEmpty(s))
                {
                    pageNum = int.Parse(s);
                }
            }

            var bp = new BusinessProcess {
                From = entity
            };

            if (where != null)
            {
                bp.Where.Add(where);
            }
            if (orderBy != null)
            {
                bp.OrderBy = orderBy;
            }
            bp.ForEachRow(() =>
            {
                int currentPage = ((int)bp.Counter - 1) / pageSize;
                if (currentPage == pageNum)
                {
                    if (columns != null)
                    {
                        result.AddItem(columns);
                    }
                    else
                    {
                        result.AddItem(entity);
                    }
                }
                else if (currentPage > pageNum)
                {
                    bp.Exit();
                }
            });
            return(result);
        }