public JsonResult LoadDistrict(string provinceName, string amphurName) { var jsonResponse = new JsonResponse { status = false, total = 0 }; try { Thailand thailand = new Thailand(db); var entity = thailand.GetAllDistricts(provinceName, amphurName).Select(p => new DropdownEntity() { Id = p.DistrictName, Name = p.DistrictName }).ToList(); jsonResponse = new JsonResponse() { status = true, message = "Ok", data = entity }; } catch (Exception ex) { jsonResponse = new JsonResponse() { status = false, message = ex.Message }; Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } return(Json(jsonResponse)); }
public ActionResult Index() { try { var permission = UserPermission; using (var db = new InternetAccountEntities()) { var area = db.Areas.Where(r => permission.Province.Contains(r.AreaCode)).ToList(); ViewBag.Area = area; var thailand = new Thailand(db); var province = thailand.GetAllProvince(); string selectProvince = (area != null ? area[0].AreaName : province[0].ProvinceName); if (!province.Exists(p => p.ProvinceName == selectProvince)) { selectProvince = province[0].ProvinceName; } if (province.Count > 0) { var amphur = thailand.GetAllAmphurs(selectProvince); var district = thailand.GetAllDistricts(selectProvince, amphur[0].AmphurName); ViewData["_Province"] = province.Select(p => new DropdownEntity { Id = p.ProvinceCode.ToString(), Name = p.ProvinceName, Selected = (p.ProvinceName == selectProvince ? true : false) }).ToList(); ViewData["_Amphur"] = amphur.Select(p => new DropdownEntity { Id = p.AmphurName, Name = p.AmphurName }).ToList(); ViewData["_District"] = district.Select(p => new DropdownEntity { Id = p.DistrictName, Name = p.DistrictName }).ToList(); ViewData["_Zipcode"] = thailand.GetZipcode(selectProvince, amphur[0].AmphurName, district[0].DistrictName) .ToString(); } } } catch (Exception ex) { Log.Error(this.GetType().FullName + "." + System.Reflection.MethodBase.GetCurrentMethod().Name + " Error -> " + ex.Message); } return(View()); }