public ActionResult index() { CommitteeLibRepository committee_rep = new CommitteeLibRepository(); ViewData["all_committees"] = committee_rep.getAll(); return(View()); }
public ActionResult edit(FormCollection collection) { //Generate new Committee object for form if error CommitteeLibRepository committee_rep = new CommitteeLibRepository(); CommitteeLib committee = new CommitteeLib(); //GET Committee try { committee = committee_rep.getCommittee(Int32.Parse(collection["committee_id"])); TempData["committee"] = committee; } catch (Exception exception) { //IF THERE IS A MESS UP, RETURN ERROR TO FRONT TempData["flash"] = "Unable to retrieve committee: " + exception.Message; return(RedirectToAction("edit", new { controller = "Committees", id = collection["committee_id"] })); } //UPDATE Committee try { return(committeeFormProcess(committee, committee_rep, collection)); } catch (Exception exception) { //IF THERE IS A MESS UP, RETURN ERROR TO FRONT TempData["flash"] = "Unable to update committee: " + exception.Message; return(RedirectToAction("edit", new { controller = "Committees", id = collection["committee_id"] })); } }
public ActionResult delete(int id) { CommitteeLibRepository committee_rep = new CommitteeLibRepository(); CommitteeLib committee = new CommitteeLib(); //GET Committee try { committee = committee_rep.getCommittee(id); } catch (Exception exception) { //IF THERE IS A MESS UP, RETURN ERROR TO FRONT TempData["flash"] = "Unable to retrieve committee: " + exception.Message; return(RedirectToAction("Index")); } //DELETE Committee try { committee_rep.delete(committee); TempData["flash"] = "Deleted committee."; return(RedirectToAction("Index")); } catch (Exception exception) { TempData["flash"] = "Unable to delete committee: " + exception.Message; return(RedirectToAction("Index")); } }
public ActionResult edit(int id) { CommitteeLibRepository committee_rep = new CommitteeLibRepository(); ViewData["committee_id"] = id.ToString(); ViewData["committee"] = committee_rep.getCommittee(id); ViewData["edit"] = true; return(View()); }
public ActionResult create() { //Generate new Committee object CommitteeLibRepository committee_rep = new CommitteeLibRepository(); CommitteeLib committee = new CommitteeLib(); ViewData["edit"] = false; ViewData["committee"] = committee; return(View()); }
//PROCESS EDIT AND CREATE FORMS private ActionResult committeeFormProcess(CommitteeLib committee, CommitteeLibRepository committee_rep, FormCollection collection) { try { committee.Description = collection["committee_description"]; committee_rep.save(committee); TempData["flash"] = "Committee: " + committee.Description; return(RedirectToAction("Index")); } catch (Exception exception) { throw new Exception("A data entry problem has occurred."); } }
public ActionResult create(FormCollection collection) { //Generate new Committee object CommitteeLibRepository committee_rep = new CommitteeLibRepository(); CommitteeLib committee = new CommitteeLib(); ViewData["edit"] = false; ViewData["committee"] = committee; try { return(committeeFormProcess(committee, committee_rep, collection)); } catch (Exception exception) { //IF THERE IS A MESS UP, RETURN ERROR TO FRONT TempData["flash"] = "Unable to create committee: " + exception.Message; return(RedirectToAction("create")); } }