// GET: State public async Task <ActionResult> ImportDataCity() { var states = _stateLogic.GetAll(); foreach (var state in states) { string apiUrl = "http://jendela.data.kemdikbud.go.id/api/index.php/CWilayah/wilayahGET?mst_kode_wilayah=" + state.AreaCode; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(apiUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(apiUrl); DikbudViewModel results = new DikbudViewModel(); if (response.IsSuccessStatusCode) { results = await response.Content.ReadAsAsync <DikbudViewModel>(); foreach (var item in results.data) { City city = new City(); city.AreaCode = item.kode_wilayah; city.Title = item.nama; city.StateId = state.Id; _cityLogic.Create(city); } } } return(null); }
public ActionResult GetStates() { var states = _stateLogic.GetAll(); List <MapViewModel> results = new List <MapViewModel>(); foreach (var item in states) { MapViewModel result = new MapViewModel(); result.Id = item.Id; result.Title = item.Title; result.Latitude = item.Latitude.HasValue ? item.Latitude.Value : 0; result.Longitude = item.Longitude.HasValue ? item.Longitude.Value : 0; results.Add(result); } return(Json(results)); }
public static void InitializeContainers() { CityLogic _cityLogic = new CityLogic(); StateLogic _stateLogic = new StateLogic(); var cities = _cityLogic.GetAll(); foreach (var city in cities) { _cityViewModels.Add(new CityViewModel() { Id = city.Id, StateId = city.StateId, Title = city.Title }); } var states = _stateLogic.GetAll(); foreach (var state in states) { _stateViewModels.Add(new StateViewModel() { Id = state.Id, Title = state.Title, Latitude = state.Latitude.HasValue ? state.Latitude.Value : 0, Longitude = state.Longitude.HasValue ? state.Longitude.Value : 0 }); } }