public ActionResult Create(ElectiveList electivelist)
        {
            if (ModelState.IsValid)
            {
                int anid = Request<ElectiveList>.Add(electivelist, "A", "B");

                return RedirectToAction("Edit", new { id = anid });
            }

            return View(electivelist);
        }
        public ActionResult Edit(ElectiveList electivelist, IEnumerable<ElectiveListCourse> ElectiveListCourses)
        {
            if (ModelState.IsValid)
            {
                ElectiveList elistAttached = Request<ElectiveList>.GetItemByID(electivelist.ID, "A", "B");

                electivelist.courses = elistAttached.courses;

                if (ElectiveListCourses == null)
                {
                    ElectiveListCourses = new List<ElectiveListCourse>();
                }

                //figure out the courses that were removed from the list
                LinkedList<ElectiveListCourse> toRemove = new LinkedList<ElectiveListCourse>();
                foreach (ElectiveListCourse course in elistAttached.courses)
                {
                    if (course.ID > 0)
                    {
                        if (!ElectiveListCourses.Contains(course))
                        {
                            ElectiveListCourse elcourseAttached = Request<ElectiveListCourse>.GetItemByID(course.ID, "A", "B");
                            toRemove.AddFirst(elcourseAttached);
                        }
                    }
                }
                //remove those courses from the database
                while (toRemove.Count > 0)
                {
                    ElectiveListCourse removeme = toRemove.First();
                    toRemove.RemoveFirst();
                    Request<ElectiveListCourse>.Delete(removeme.ID, "A", "B");
                }
                //clear the list
                electivelist.courses = new List<ElectiveListCourse>();
                //add the existing courses to the database
                foreach (ElectiveListCourse elcourse in ElectiveListCourses)
                {
                    ElectiveListCourse elcourseAttached = null; ;
                    if (elcourse.ID > 0)
                    {
                        elcourseAttached = Request<ElectiveListCourse>.GetItemByID(elcourse.ID, "A", "B");
                        Request<ElectiveListCourse>.Update(elcourseAttached, elcourse, "A", "B");
                    }
                    else
                    {
                        if (courses.Find(elcourse.courseID) != null)
                        {
                            int id = Request<ElectiveListCourse>.Add(elcourse, "A", "B");
                            elcourseAttached = Request<ElectiveListCourse>.GetItemByID(id, "A", "B");
                        }
                    }
                    if (elcourseAttached != null)
                    {
                        electivelist.courses.Add(elcourseAttached);
                    }
                }
                Request<ElectiveList>.Update(elistAttached, electivelist, "A", "B");
                return RedirectToAction("Index");
            }
            if (ElectiveListCourses != null)
            {
                foreach (ElectiveListCourse course in ElectiveListCourses)
                {
                    if (course.courseID > 0)
                    {
                        course.course = Request<Course>.GetItemByID(course.courseID, "A", "B");
                    }
                }
            }
            electivelist.courses = ElectiveListCourses.ToList();
            return View(electivelist);
        }
 private ElectiveList createTempElectiveList()
 {
     ElectiveList temp = new ElectiveList()
     {
         ID = 3,
         electiveListName = "Elective List 3",
         courses = new Collection<ElectiveListCourse>(),
     };
     return temp;
 }