Пример #1
0
        public object GetAll(long?parentRegionId = null)
        {
            var regions = RegionApplication.GetSubRegion(0, true);
            var models  = regions.Select(p => new
            {
                id   = p.Id,
                name = p.Name,
                city = (p.Sub != null ? p.Sub.Select(c => new
                {
                    id = c.Id,
                    name = c.Name,
                    area = (c.Sub != null ? c.Sub.Select(a => new
                    {
                        id = a.Id,
                        name = a.Name,
                        country = (a.Sub != null ? a.Sub.Select(v => new
                        {
                            id = v.Id,
                            name = v.Name
                        }) : null)
                    }) : null)
                }) : null)
            });

            return(Json(models));
        }
Пример #2
0
        /// <summary>
        /// 获取市级的所有子区域
        /// </summary>
        /// <param name="regionId"></param>
        /// <returns></returns>
        public JsonResult GetCitySubRegions(int regionId)
        {
            var region    = RegionApplication.GetRegion(regionId, CommonModel.Region.RegionLevel.County);
            var subRegion = RegionApplication.GetSubRegion(region.ParentId);

            return(Json(new
            {
                regions = subRegion,
                selectId = region.Id
            }, true));
        }
Пример #3
0
        public JsonResult GetRegionTree(int id)
        {
            var region = RegionApplication.GetRegion(id);

            if (region == null)
            {
                var rid = RegionApplication.GetDefaultRegionId();
                region = RegionApplication.GetRegion(rid);
            }


            Dictionary <string, object> map = new Dictionary <string, object>();

            //[
            //{ level:1,list:[{id,name,shortname}]},
            //{ level:2,list:[{id,name,shortname}]},
            //{ level:3,list:[{id,name,shortname}]},
            //]

            //添加子集
            if (region.Sub != null)
            {
                map.Add(
                    ((int)region.Level + 1).ToString(),
                    region.Sub.Select(p => new
                {
                    Id        = p.Id,
                    Name      = p.Name,
                    ShortName = p.ShortName,
                    option    = "",
                }).ToList());
            }
            var parent = 0;

            do
            {
                parent = region.ParentId; //上级节点
                var cur     = region.Id;  //当前节点
                var level   = (int)region.Level;
                var regions = RegionApplication.GetSubRegion(parent);
                var list    = regions.Select(p => new
                {
                    Id        = p.Id,
                    Name      = p.Name,
                    ShortName = p.ShortName,
                    option    = p.Id == cur ? "true" : ""
                }).ToList();
                map.Add(level.ToString(), list);
                region = region.Parent;
            } while (parent > 0);
            return(Json(map, JsonRequestBehavior.AllowGet));
        }
Пример #4
0
        /// <summary>
        /// 获取 下级区域数据
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public JsonResult GetSubRegion(int parent)
        {
            var regions = RegionApplication.GetSubRegion(parent);
            var models  = regions.Select(p => new
            {
                p.Id,
                p.Name,
                p.ShortName,
                p.Level
            }).ToList();

            return(Json(models, JsonRequestBehavior.AllowGet));
        }
Пример #5
0
        /// <summary>
        /// 获取 下级区域数据
        /// </summary>
        /// <param name="parent"></param>
        /// <returns></returns>
        public JsonResult GetSubRegion(int parent, bool bAddAll = false)
        {
            var regions = RegionApplication.GetSubRegion(parent);
            var models  = regions.Select(p => new
            {
                p.Id,
                p.Name,
                p.ShortName,
                p.Level
            }).ToList();

            if (bAddAll && models.Any(n => n.Level == CommonModel.Region.RegionLevel.Town))
            {
                models.Insert(0, new { Id = 0, Name = "其它", ShortName = "其它", Level = CommonModel.Region.RegionLevel.Town });
            }
            return(Json(models));
        }
Пример #6
0
        public JsonResult GetAllRegion()
        {
            var region = RegionApplication.GetAllRegions().ToList();
            //region = region.Where(p => p.ParentId == 1944).ToList();

            List <Himall.CommonModel.Region> regions = new List <CommonModel.Region>();
            var province = region.Where(a => a.Level == CommonModel.Region.RegionLevel.Province).ToList();

            foreach (var r in province)
            {
                var model = new CommonModel.Region();
                model.Id        = r.Id;
                model.Level     = r.Level;
                model.Name      = r.Name;
                model.ShortName = r.ShortName;
                var sub  = RegionApplication.GetSubRegion(r.Id);
                var city = sub.Select(a => new Himall.CommonModel.Region()
                {
                    Id   = a.Id,
                    Name = a.Name,
                    Sub  = new List <CommonModel.Region>()
                }
                                      ).ToList();
                model.Sub = city;
                foreach (var m in model.Sub)
                {
                    var citySub = RegionApplication.GetSubRegion(m.Id);
                    var county  = citySub.Select(a => new Himall.CommonModel.Region()
                    {
                        Id   = a.Id,
                        Name = a.Name,
                    }).ToList();
                    m.Sub = county;
                }
                regions.Add(model);
            }
            // string json = Newtonsoft.Json.JsonConvert.SerializeObject(regions);

            // return json;
            return(Json(regions, JsonRequestBehavior.AllowGet));
        }