示例#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
        public String MapData(string query, decimal slon = 1000, decimal slat = 1000, decimal elon = 0, decimal elat = 0)
        {
            var user = GetUser();

            if (user != null)
            {
                IEnumerable <Tree> data; decimal x = 0m, y = 0m;
                if (!string.IsNullOrEmpty(query))
                {
                    data = TreeService.Query(user.ID).Where(t => t.Number.Contains(query)).Take(100);
                }
                else
                {
                    data = TreeService.Query(user.ID).Where(d => d.Longtitude <slon && d.Longtitude> elon && d.Latitude <slat && d.Latitude> elat);

                    if (data.Any())
                    {
                        x = data.Average(t => t.Longtitude);
                        y = data.Average(t => t.Latitude);
                    }
                }
                dynamic result;
                if (data.Count() > 100)
                {
                    result = new { x = x, y = y, data = new string[0] };
                }
                else
                {
                    result = new
                    {
                        x    = x,
                        y    = y,
                        data = data.Select(d => ConvertViewModel(d)).Select(m => new
                        {
                            Longtitude = m.Longtitude,
                            Latitude   = m.Latitude,
                            Age        = m.Age,
                            Height     = m.Height,
                            Name       = m.Name,
                            NameLatin  = m.NameLatin,
                            ChestSize  = m.ChestSize,
                            IsBooked   = m.IsBooked,
                            IsFamous   = m.IsFamous,
                            Health     = m.Health,
                            RootSize   = m.RootSize,
                            ID         = m.ID,
                            Number     = m.Number,
                            City       = m.City,
                            Photo      = m.Photo
                        })
                    };
                }

                var js = new JavaScriptSerializer();
                js.MaxJsonLength = int.MaxValue;
                var sb = new StringBuilder();
                js.Serialize(result, sb);
                return(sb.ToString());

                // return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return(null);
            }
        }