public ActionResult Edit([Bind(Include = "instructorProgram_id,program_id,instructor_id")] InstructorProgram instructorProgram)
        {
            // programPrefix
            instructorProgram.programPrefix = (from p in db.Programs where p.program_id == instructorProgram.program_id select p.programPrefix).ToList().FirstOrDefault();

            // instructorWNumber
            instructorProgram.instructorWNumber = (from i in db.Instructors where i.instructor_id == instructorProgram.instructor_id select i.instructorWNumber).ToList().FirstOrDefault();

            if (ModelState.IsValid)
            {
                db.Entry(instructorProgram).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.program_id = new SelectList(
                from p in db.Programs
                orderby p.programPrefix
                select new { p.program_id, p.programPrefix, p.programName, fullName = p.programPrefix + " - " + p.programName },
                "program_id", "fullName", instructorProgram.program_id);
            ViewBag.instructor_id = new SelectList(
                from i in db.Instructors
                orderby i.instructorLastName, i.instructorFirstName
                select new { i.instructor_id, i.instructorFirstName, i.instructorLastName, fullName = i.instructorLastName + ", " + i.instructorFirstName },
                "instructor_id", "fullName", instructorProgram.instructor_id);

            return(View(instructorProgram));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            InstructorProgram instructorProgram = db.InstructorPrograms.Find(id);

            db.InstructorPrograms.Remove(instructorProgram);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: InstructorPrograms/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InstructorProgram instructorProgram = db.InstructorPrograms.Find(id);

            if (instructorProgram == null)
            {
                return(HttpNotFound());
            }
            return(View(instructorProgram));
        }
        public ActionResult Create([Bind(Include = "instructorProgram_id,program_id,instructor_id")] InstructorProgram instructorProgram)
        {
            // programPrefix
            instructorProgram.programPrefix = (from p in db.Programs where p.program_id == instructorProgram.program_id select p.programPrefix).ToList().FirstOrDefault();

            // instructorWNumber
            instructorProgram.instructorWNumber = (from i in db.Instructors where i.instructor_id == instructorProgram.instructor_id select i.instructorWNumber).ToList().FirstOrDefault();

            try
            {
                if (ModelState.IsValid)
                {
                    db.InstructorPrograms.Add(instructorProgram);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                if (e.InnerException.InnerException.Message.Contains("UNIQUE KEY constraint"))
                {
                    ModelState.AddModelError("instructor_id", "The instructor has already been assigned to that program");
                }
                else
                {
                    ModelState.AddModelError("instructor_id", e.InnerException.InnerException.Message);
                }
            }

            ViewBag.program_id = new SelectList(
                from p in db.Programs
                orderby p.programPrefix
                select new { p.program_id, p.programPrefix, p.programName, fullName = p.programPrefix + " - " + p.programName },
                "program_id", "fullName", instructorProgram.program_id);
            ViewBag.instructor_id = new SelectList(
                from i in db.Instructors
                orderby i.instructorLastName, i.instructorFirstName
                select new { i.instructor_id, i.instructorFirstName, i.instructorLastName, fullName = i.instructorLastName + ", " + i.instructorFirstName },
                "instructor_id", "fullName", instructorProgram.instructor_id);

            return(View(instructorProgram));
        }
        // GET: InstructorPrograms/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            InstructorProgram instructorProgram = db.InstructorPrograms.Find(id);

            if (instructorProgram == null)
            {
                return(HttpNotFound());
            }
            ViewBag.program_id = new SelectList(
                from p in db.Programs
                orderby p.programPrefix
                select new { p.program_id, p.programPrefix, p.programName, fullName = p.programPrefix + " - " + p.programName },
                "program_id", "fullName", instructorProgram.program_id);
            ViewBag.instructor_id = new SelectList(
                from i in db.Instructors
                orderby i.instructorLastName, i.instructorFirstName
                select new { i.instructor_id, i.instructorFirstName, i.instructorLastName, fullName = i.instructorLastName + ", " + i.instructorFirstName },
                "instructor_id", "fullName", instructorProgram.instructor_id);
            return(View(instructorProgram));
        }