public ActionResult <CityDetailResponseModel> GetCityDetail(Guid cityID) { CityDetailResponseModel res = new CityDetailResponseModel(); try { CityRepository repo = new CityRepository(db); var query = repo.GetCitiesDetail(cityID); var res2 = (from y in query select new CityOuputModel { ProvinceID = y.ProvinceID, CityID = y.ID, Kode = y.Kode, Kota = y.CityName }).FirstOrDefault(); res.data = res2; res.Message = "Success get data"; res.Response = true; return(res); } catch (Exception ex) { res.Message = ex.Message; res.Response = false; return(res); } }
public ActionResult Update(string id) { if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "") { HttpContext.Session.SetString(SessionKeyEdit, id); var ID = Guid.Parse(id); CityOutputModel City = new CityOutputModel(); if (TempData["CustomError"] != null) { ModelState.AddModelError(string.Empty, TempData["CustomError"].ToString()); } else { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Base/"); //HTTP POST var postTask = client.GetAsync("GetCityDetail?CityID=" + ID); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); CityDetailResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject <CityDetailResponseModel>(content.Result); City = resutl.data; } else { //log response status here.. City = null; TempData["CustomError"] = "Gagal mendapatkan data. Mohon hubungi admin."; } } } return(View(City)); } else { TempData["CustomError"] = "Silakan masuk sebelum menggunakan situs web."; //if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV") //{ // return RedirectToAction("AdminLogon", "Login"); //} //else if (HttpContext.Session.GetString(Loginfrom) == "MDO") //{ // return RedirectToAction("OwnerLogon", "Login"); //} //else //{ // return RedirectToAction("OwnerLogon", "Login"); //} return(RedirectToAction("Logon", "Login")); } }
public ActionResult Update(string id) { if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "") { HttpContext.Session.SetString(SessionKeyEdit, id); var ID = Guid.Parse(id); CityOutputModel City = new CityOutputModel(); if (TempData["CustomError"] != null) { ModelState.AddModelError(string.Empty, TempData["CustomError"].ToString()); } else { using (var client = new HttpClient()) { client.BaseAddress = new Uri(BaseAPI + "Base/"); //HTTP POST var postTask = client.GetAsync("GetCityDetail?CityID=" + ID); postTask.Wait(); var result = postTask.Result; if (result.IsSuccessStatusCode) { var content = result.Content.ReadAsStringAsync(); CityDetailResponseModel resutl = Newtonsoft.Json.JsonConvert.DeserializeObject<CityDetailResponseModel>(content.Result); City = resutl.data; } else { //log response status here.. City = null; TempData["CustomError"] = "Fail to get data. Please contact administrator."; } } } return View(City); } else { TempData["CustomError"] = "Please login before using the web."; if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV") { return RedirectToAction("AdminLogon", "Login"); } else if (HttpContext.Session.GetString(Loginfrom) == "MDO") { return RedirectToAction("OwnerLogon", "Login"); } else { return RedirectToAction("BuyerLogon", "Login"); } //return RedirectToAction("Logon", "Login"); } }