public ActionResult Create(ProgDecProgramsStudents pps) { try { ProgDecManager.Insert(pps.ProgDec); pps.AdvisorIds.ToList().ForEach(a => ProgDecAdvisorManager.Add(pps.ProgDec.Id, a)); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, ProgDecProgramsStudents pps) { try { // Deal with the Advisors IEnumerable <int> oldadvisorids = new List <int>(); if (Session["advisorids"] != null) { oldadvisorids = (IEnumerable <int>)Session["advisorids"]; } IEnumerable <int> newadvisorids = new List <int>(); if (pps.AdvisorIds != null) { newadvisorids = pps.AdvisorIds; } //Identify the deletes IEnumerable <int> deletes = oldadvisorids.Except(newadvisorids); //Identify the adds IEnumerable <int> adds = newadvisorids.Except(oldadvisorids); deletes.ToList().ForEach(d => ProgDecAdvisorManager.Delete(id, d)); adds.ToList().ForEach(a => ProgDecAdvisorManager.Add(id, a)); // TODO: Add update logic here ProgDecManager.Update(pps.ProgDec); return(RedirectToAction("Index")); } catch { return(View()); } }