예제 #1
0
        //   [OutputCache(Duration = 1000)]
        public JsonResult GetAllRegion()
        {
            var region = RegionApplication.GetAllRegions().ToList();
            //region = region.Where(p => p.ParentId == 1944).ToList();

            List <Mall.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 Mall.CommonModel.Region()
                //{
                //    Id = a.Id,
                //    Name = a.Name,
                //    ShortName = a.ShortName,
                //    Level = CommonModel.Region.RegionLevel.City,
                //    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 Mall.CommonModel.Region()
                //    {
                //        Id = a.Id,
                //        Name = a.Name,
                //        Sub = new List<CommonModel.Region>()
                //    }).ToList();
                //    m.Sub = county;
                //    foreach (var v in m.Sub)
                //    {
                //        var villageSub = RegionApplication.GetSubRegion(v.Id);
                //        var village = villageSub.Select(a => new Mall.CommonModel.Region()
                //        {
                //            Id = a.Id,
                //            Name = a.Name
                //        }).ToList();
                //        v.Sub = village;
                //    }
                //}
                regions.Add(model);
            }
            // string json = Newtonsoft.Json.JsonConvert.SerializeObject(regions);

            // return json;
            return(Json(regions));
        }
예제 #2
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));
        }