//Get Cities Ajax public IActionResult GetCitiesAjax() { if (!_workContext.CurrentCustomer.IsRegistered()) { return(Unauthorized()); } if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true)) { return(Forbid()); } var citiesInDb = _cityService.GetCities(); var cities = new CityOutputModel { Cities = citiesInDb.Select(c => new CityModel { Id = c.Id, Name = c.ArName, ProvinceId = c.ProvinceId }).ToList() }; return(Json(new { data = cities.Cities })); }
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"); } }
public async Task <ActionResult> Upload(string cityName) { if (cityName != null) { var outputCity = new CityOutputModel { Name = await this.citiesService.UploadCity(cityName) }; return(this.View(outputCity)); } else { return(Redirect("Index")); } }