public ActionResult Create(ProgramDegreeTypeList pdtl) { try { if (pdtl.File != null) { pdtl.Program.ImagePath = pdtl.File.FileName; string target = Path.Combine(Server.MapPath("~/images"), Path.GetFileName(pdtl.File.FileName)); if (!System.IO.File.Exists(target)) { pdtl.File.SaveAs(target); ViewBag.Message = "File uploaded successfully"; } else { ViewBag.Message = "File already exists"; } } pdtl.Program.Insert(); return(RedirectToAction("Index")); } catch { return(View(pdtl)); } }
// GET: Program/Edit/5 public ActionResult Edit(int id) { ProgramDegreeTypeList pdtl = new ProgramDegreeTypeList(); pdtl.Program = new Program(); pdtl.Program.Id = id; pdtl.Program.LoadById(); pdtl.DegreeTypeList = new DegreeTypeList(); pdtl.DegreeTypeList.Load(); return(View(pdtl)); }
// GET: Program/Create public ActionResult Create() { ProgramDegreeTypeList pdtl = new ProgramDegreeTypeList(); Program program = new Program(); pdtl.Program = program; DegreeTypeList degreeTypes = new DegreeTypeList(); degreeTypes.Load(); pdtl.DegreeTypeList = degreeTypes; return(View(pdtl)); }
public ActionResult Insert(ProgramDegreeTypeList pdts) { try { HttpClient client = InitializeClient(); HttpResponseMessage response = client.PostAsJsonAsync("Program", pdts.Program).Result; return(RedirectToAction("Get")); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View("Create", pdts)); } }
public ActionResult Update(int id, ProgramDegreeTypeList pdts) { try { HttpClient client = InitializeClient(); HttpResponseMessage response = client.PutAsJsonAsync("Program/" + id, pdts.Program).Result; return(RedirectToAction("Get")); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View("Edit", pdts)); } }
public ActionResult Insert() { HttpClient client = InitializeClient(); ProgramDegreeTypeList pdts = new ProgramDegreeTypeList(); pdts.DegreeTypeList = new DegreeTypeList(); HttpResponseMessage response = client.GetAsync("DegreeType").Result; string result = response.Content.ReadAsStringAsync().Result; dynamic items = (JArray)JsonConvert.DeserializeObject(result); pdts.DegreeTypeList = items.toObject <DegreeTypeList>(); // check this. exception when nav'd to http://localhost:52763/Program/Insert pdts.Program = new Program(); return(View("Create", pdts)); }
public ActionResult Update(int id) { HttpClient client = InitializeClient(); ProgramDegreeTypeList pdts = new ProgramDegreeTypeList(); pdts.DegreeTypeList = new DegreeTypeList(); HttpResponseMessage response = client.GetAsync("DegreeType").Result; string result = response.Content.ReadAsStringAsync().Result; dynamic items = (JArray)JsonConvert.DeserializeObject(result); pdts.DegreeTypeList = items.toObject <DegreeTypeList>(); //pdts.Program = new Program(); response = client.GetAsync("Program/" + id).Result; result = response.Content.ReadAsStringAsync().Result; pdts.Program = JsonConvert.DeserializeObject <Program>(result); return(View("Edit", pdts)); }