예제 #1
0
        public ActionResult Index(Models.TreeQueryModel q)
        {
            var user = GetUser();

            if (user != null)
            {
                if (q.Jump.HasValue)
                {
                    q.Current = q.Jump.Value;
                    q.Jump    = null;
                }
                var models = TreeService.Query(user.ID).ToList();
                var result = DoQuery(q, models);
                ViewBag.q = q;
                int pageSize  = 50;
                int count     = result.Count() % pageSize == 0 ? result.Count() / pageSize : result.Count() / pageSize + 1;
                int pageStart = q.Current - pageSize < 1 ? 1 : q.Current - pageSize;
                int pageEnd   = q.Current + 2 > count ? count : q.Current + 2;

                List <int> pages = new List <int>();
                for (int i = pageStart; i <= pageEnd; i++)
                {
                    pages.Add(i);
                }
                ViewBag.page = pages;

                result = result.Skip(q.Current * pageSize - pageSize).Take(pageSize).ToList();
                return(View(result));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
예제 #2
0
        IEnumerable <Tree> DoQuery(Models.TreeQueryModel q, IEnumerable <Tree> source)
        {
            IEnumerable <Tree> r = source.Select(t => ConvertViewModel(t));

            if (!string.IsNullOrEmpty(q.Area))
            {
                r = r.Where(s => s.County.Contains(q.Area) || s.City.Contains(q.Area) || s.Address.Contains(q.Area));
            }


            if (!string.IsNullOrEmpty(q.IDName))
            {
                r = r.Where(s => s.Number.Contains(q.IDName) || s.Name.Contains(q.IDName));
            }

            if (q.Age_Start.HasValue)
            {
                r = r.Where(s => s.Age >= q.Age_Start);
            }

            if (q.Age_End.HasValue)
            {
                r = r.Where(s => s.Age <= q.Age_End);
            }

            return(r);
        }