Exemplo n.º 1
0
 // GET: Instructor/Create
 public ActionResult Create()
 {
     var instructor = new Instructor();
     instructor.Courses = new List<Course>();
     PopulateAssignedCourseData(instructor);
     return View();
 }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var instructorID = Request.QueryString["ID"];

            if (!IsPostBack && instructorID == null)
            {
                ddlID.DataSource     = Utility.Utility.GetAllPeople();
                ddlID.DataTextField  = "ID";
                ddlID.DataValueField = "ID";
                ddlID.DataBind();
            }
            if (!IsPostBack && instructorID != null)
            {
                ddlID.DataSource     = Utility.Utility.GetAllPeople();
                ddlID.DataTextField  = "ID";
                ddlID.DataValueField = "ID";
                ddlID.DataBind();
                InstructorService         instructorService = new InstructorService();
                Contoso.Models.Instructor instructor        = instructorService.GetOneInstructor(Convert.ToInt32(instructorID));
                ddlID.SelectedValue = instructor.ID.ToString();
                txtHireDate.Text    = instructor.HireDate.ToString();
            }
        }
Exemplo n.º 3
0
 private void PopulateAssignedCourseData(Instructor instructor)
 {
     var allCourses = db.Courses;
     var instructorCourses = new HashSet<int>(instructor.Courses.Select(c => c.CourseID));
     var viewModel = new List<AssignedCourseData>();
     foreach (var course in allCourses)
     {
         viewModel.Add(new AssignedCourseData
         {
             CourseID = course.CourseID,
             Title = course.Title,
             Assigned = instructorCourses.Contains(course.CourseID)
         });
     }
     ViewBag.Courses = viewModel;
 }
Exemplo n.º 4
0
        private void UpdateInstructorCourses(string[] selectedCourses, Instructor instructorToUpdate)
        {
            if (selectedCourses == null)
            {
                instructorToUpdate.Courses = new List<Course>();
                return;
            }

            var selectedCoursesHS = new HashSet<string>(selectedCourses);
            var instructorCourses = new HashSet<int>
                (instructorToUpdate.Courses.Select(c => c.CourseID));
            foreach (var course in db.Courses)
            {
                if (selectedCoursesHS.Contains(course.CourseID.ToString()))
                {
                    if (!instructorCourses.Contains(course.CourseID))
                    {
                        instructorToUpdate.Courses.Add(course);
                    }
                }
                else
                {
                    if (instructorCourses.Contains(course.CourseID))
                    {
                        instructorToUpdate.Courses.Remove(course);
                    }
                }
            }
        }
        public ActionResult Create(Instructor instructor)
        {
            if (ModelState.IsValid)
            {
                this._db.Instructors.Add(instructor);
                this._db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.PersonID = new SelectList(this._db.OfficeAssignments, "PersonID", "Location", instructor.PersonID);
            return View(instructor);
        }