public async Task <bool> Delete(AdminLevelModel adm) { try { using (HttpClient httpClient = new HttpClient()) { var json = JsonConvert.SerializeObject(adm); using (HttpContent httpContent = new StringContent(json, Encoding.UTF8, "application/json")) { HttpResponseMessage response = null; response = await httpClient.PutAsync(ConfigurationManager.AppSettings["MySeverUrl"] + "/api/DeleteAdminLevel/", httpContent); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } } } } catch (Exception) { return(false); } }
public async Task <AdminLevelModel> UpdateGet(int id) { try { using (HttpClient client = new HttpClient()) { AdminLevelModel adm = new AdminLevelModel(); using (HttpResponseMessage response = await client.GetAsync(ConfigurationManager.AppSettings["MySeverUrl"] + "/api/UpdateLevelGet/id=" + id)) { if (response.IsSuccessStatusCode) { using (HttpContent content = response.Content) { var textresponse = await content.ReadAsStringAsync(); var json = JsonConvert.DeserializeObject <AdminLevelModel>(textresponse); adm.admID = json.admID; adm.admName = json.admName; adm.admLevel = json.admLevel; } return(adm); } else { return(null); } } } } catch (Exception) { return(null); } }
public async Task <ActionResult> Delete(int id) { AdminLevelModel tModel = new AdminLevelModel(); tModel.admID = id; await admVM.Delete(tModel); return(RedirectToAction("Admin_Details")); }
public ActionResult Add() { AdminLevelModel model = new AdminLevelModel(); var items = 9; for (int i = 1; i < items; i++) { model.Levels.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() }); } return(View(model)); }
public async Task <ActionResult> Add(AdminLevelModel adm) { if (ModelState.IsValid == false) { return(View(adm)); } else { var response = await admVM.Add(adm); if (response == true) { return(RedirectToAction("Admin_Details")); } else { return(View(adm)); } } }
public async Task <ActionResult> Update(AdminLevelModel adm) { try { if (ModelState.IsValid == false) { return(View(adm)); } else { await admVM.Update(adm); } return(RedirectToAction("Admin_Details")); } catch (Exception e) { //TempData["Message"] = "Unable to process request !"; return(View(adm)); } }
public async Task <ActionResult> Update(int id) { AdminLevelModel adm = new AdminLevelModel(); var items = 9; try { adm = await admVM.UpdateGet(id); for (int i = 1; i < items; i++) { adm.Levels.Add(new SelectListItem { Text = i.ToString(), Value = i.ToString() }); } } catch (Exception) { //TempData["Message"] = "Unable to process request !"; return(View(adm)); } return(View(adm)); }