public async Task <JsonResult> GetAllCitys() { try { using (var client = new RegionClient()) { var regions = await client.GetRegionByRegionIdAsync(ProvinceId); regions.ThrowIfException(true); if (regions.Result.ChildRegions.FirstOrDefault().IsBelongMunicipality) { return(Json(regions.Result.ChildRegions.Select(s => new { id = s.DistrictId, name = s.DistrictName }).ToArray())); } else { return(Json(regions.Result.ChildRegions.Select(s => new { id = s.CityId, name = s.CityName }).ToArray())); } } } catch (Exception ex) { logger.Error($"GetAllCitys:{ex.Message}", ex); } return(Json(null)); }
/// <summary> /// 根据地区Id获取地区信息 /// </summary> /// <param name="regionId"></param> /// <returns></returns> public async Task <Region> GetRegionByRegionIdAsync(int regionId) { using (var client = new RegionClient()) { var clientResult = await client.GetRegionByRegionIdAsync(regionId); clientResult.ThrowIfException(true); return(clientResult.Result); } }
/// <summary> /// 通过regionId获取市/区 /// </summary> /// <param name="regionId"></param> /// <returns>Json格式</returns> public async Task <ActionResult> GetRegionByRegionId(int regionId) { Tuhu.Service.Shop.Models.Region.Region result = null; using (var client = new RegionClient()) { var serviceResult = await client.GetRegionByRegionIdAsync(regionId); serviceResult.ThrowIfException(true); result = serviceResult.Result; } return(Json(new { isSuccess = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// 通过regionId获取市/区 /// </summary> /// <param name="regionId"></param> /// <returns>Json格式</returns> public async Task <ActionResult> GetRegionByRegionId(int regionId) { List <Tuhu.Service.Shop.Models.Region.Region> result = null; using (var client = new RegionClient()) { var serviceResult = await client.GetRegionByRegionIdAsync(regionId); serviceResult.ThrowIfException(true); result = serviceResult?.Result?.ChildRegions.ToList().GroupBy(x => x.CityId).Select(s => s.First()).ToList(); } return(Json(new { isSuccess = result != null, Data = result }, JsonRequestBehavior.AllowGet)); }