ElectiveListCourse _electiveListCourseQueue_Get(ElectiveListCourse data) { ElectiveListCourse elc = _context.ElectiveListCourses.Where(i => i.ID == data.ID) .Include(el => el.course) .Include(el => el.electiveList) .First(); return(elc); }
public void ElectiveListCourseEquality() { ElectiveListCourse course1 = new ElectiveListCourse() { ID = 1, electiveListID = 1 }; ElectiveListCourse course2 = new ElectiveListCourse() { ID = 1, electiveListID = 2 }; Assert.AreEqual(course1, course2); }
/// <summary> /// @russfeld /// This uses AJAX to return the HTML code for a new course row on the form /// Mad props to http://ivanz.com/2011/06/16/editing-variable-length-reorderable-collections-in-asp-net-mvc-part-1/ /// </summary> /// <returns></returns> public ActionResult ElectiveListCourseRow(int id = 0) { if (id > 0) { ElectiveListCourse reqcourse = new ElectiveListCourse() { electiveListID = id, courseID = -1, }; return(PartialView("ElectiveListCourseFormPartial", reqcourse)); } else { return(PartialView("ElectiveListCourseFormPartial")); } }
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)); }
public ActionResult Edit(ElectiveList electivelist, IEnumerable <ElectiveListCourse> ElectiveListCourses) { if (ModelState.IsValid) { //ElectiveList elistAttached = electiveLists.Where(elist => elist.ID == electivelist.ID).First(); ElectiveList elistAttached = _electiveListProducer.Get(new ElectiveList() { ID = electivelist.ID }); 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 = electiveListCourses.Where(reqc => reqc.ID == course.ID).First(); ElectiveListCourse elcourseAttached = _electiveListCourseProducer.Get(new ElectiveListCourse() { ID = course.ID }); toRemove.AddFirst(elcourseAttached); } } } //remove those courses from the database while (toRemove.Count > 0) { ElectiveListCourse removeme = toRemove.First(); toRemove.RemoveFirst(); //electiveListCourses.Remove(removeme); _electiveListCourseProducer.Remove(removeme); } //clear the list electivelist.courses.Clear(); //add the existing courses to the database foreach (ElectiveListCourse elcourse in ElectiveListCourses) { ElectiveListCourse elcourseAttached = null;; if (elcourse.ID > 0) { //elcourseAttached = electiveListCourses.Where(reqc => reqc.ID == elcourse.ID).First(); elcourseAttached = _electiveListCourseProducer.Get(new ElectiveListCourse() { ID = elcourse.ID }); //electiveListCourses.UpdateValues(elcourseAttached, elcourse); _electiveListCourseProducer.Update(elcourse); } else { //if (courses.Find(elcourse.courseID) != null) if (_courseProducer.Get(new Course() { ID = elcourse.courseID }) != null) { //electiveListCourses.Add(elcourse); //electiveListCourses.SaveChanges(); _electiveListCourseProducer.Create(elcourse); //elcourseAttached = electiveListCourses.Where(reqc => reqc.ID == elcourse.ID).First(); elcourseAttached = _electiveListCourseProducer.Get(new ElectiveListCourse() { ID = elcourse.ID }); } } if (elcourseAttached != null) { electivelist.courses.Add(elcourseAttached); } } //electiveLists.UpdateValues(elistAttached, electivelist); //electiveLists.SaveChanges(); _electiveListProducer.Update(electivelist); return(RedirectToAction("Index")); } if (ElectiveListCourses != null) { foreach (ElectiveListCourse course in ElectiveListCourses) { if (course.courseID > 0) { //course.course = courses.Find(course.courseID); course.course = _courseProducer.Get(new Course() { ID = course.courseID }); } } } electivelist.courses = ElectiveListCourses.ToList(); return(View(electivelist)); }
ElectiveListCourse _electiveListCourseQueue_Create(ElectiveListCourse data) { return(Create(data)); }
void _electiveListCourseQueue_Update(ElectiveListCourse data) { Update(data); }
void _electiveListCourseQueue_Remove(ElectiveListCourse data) { Remove(data); }
protected override void Seed(MessageParser.Models.CourseDBContext context) { bool seedAll = true; if (seedAll) { string[] semesterTitles = { "January", "Spring", "May", "Summer", "August", "Fall" }; int semCount = 1; for (int i = 2013; i < 2025; i++) { for (int k = 0; k < semesterTitles.Length; k++) { if (semesterTitles[k].Equals("Spring") || semesterTitles[k].Equals("Fall")) { context.Semesters.AddOrUpdate(c => c.ID, new Semester() { ID = semCount++, semesterYear = i, semesterTitle = semesterTitles[k], standard = true }); } else { context.Semesters.AddOrUpdate(c => c.ID, new Semester() { ID = semCount++, semesterYear = i, semesterTitle = semesterTitles[k], standard = false }); } } } context.SaveChanges(); String resourceName = "MessageParser.SeedData."; XmlTextReader reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_courses.xml")); Course course = null; String property = null; int count = 0; Boolean done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.Course")) { course = new Course(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { course.ID = Int32.Parse(reader.Value); } else if (property.Equals("prefix")) { course.coursePrefix = reader.Value; } else if (property.Equals("number")) { course.courseNumber = Int32.Parse(reader.Value); } else if (property.Equals("title")) { course.courseTitle = reader.Value; } else if (property.Equals("description")) { course.courseDescription = reader.Value; } else if (property.Equals("minHours")) { course.minHours = int.Parse(reader.Value); } else if (property.Equals("maxHours")) { course.maxHours = int.Parse(reader.Value); } else if (property.Equals("variableHours")) { if (reader.Value.Equals("false")) { course.variable = false; } else { course.variable = true; } } else if (property.Equals("ugrad")) { if (reader.Value.Equals("false")) { course.undergrad = false; } else { course.undergrad = true; } } else if (property.Equals("grad")) { if (reader.Value.Equals("false")) { course.graduate = false; } else { course.graduate = true; } } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.Course")) { try { context.Courses.AddOrUpdate(i => i.ID, course); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_electivelists.xml")); ElectiveList elist = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.ElectiveList")) { elist = new ElectiveList(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { elist.ID = Int32.Parse(reader.Value); } else if (property.Equals("name")) { elist.electiveListName = reader.Value; } else if (property.Equals("shortname")) { elist.shortName = reader.Value; } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.ElectiveList")) { try { context.ElectiveLists.AddOrUpdate(i => i.ID, elist); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_degreeprograms.xml")); DegreeProgram dp = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.DegreeProgram")) { dp = new DegreeProgram(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { dp.ID = Int32.Parse(reader.Value); } else if (property.Equals("name")) { dp.degreeProgramName = reader.Value; } else if (property.Equals("description")) { dp.degreeProgramDescription = reader.Value; } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.DegreeProgram")) { try { context.DegreePrograms.AddOrUpdate(i => i.ID, dp); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_electivelistcourses.xml")); ElectiveListCourse ec = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.ElectiveListCourse")) { ec = new ElectiveListCourse(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { ec.ID = Int32.Parse(reader.Value); } else if (property.Equals("course")) { ec.courseID = Int32.Parse(reader.Value); } else if (property.Equals("electivelist")) { ec.electiveListID = Int32.Parse(reader.Value); } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.ElectiveListCourse")) { try { context.ElectiveListCourses.AddOrUpdate(i => i.ID, ec); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_requiredcourses.xml")); RequiredCourse rq = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.RequiredCourse")) { rq = new RequiredCourse(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { rq.ID = Int32.Parse(reader.Value); } else if (property.Equals("course")) { rq.courseID = Int32.Parse(reader.Value); } else if (property.Equals("degree")) { rq.degreeProgramID = Int32.Parse(reader.Value); } else if (property.Equals("semester")) { rq.semester = Int32.Parse(reader.Value); } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.RequiredCourse")) { try { context.RequiredCourses.AddOrUpdate(i => i.ID, rq); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_electivecourses.xml")); ElectiveCourse ecr = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.ElectiveCourse")) { ecr = new ElectiveCourse(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { ecr.ID = Int32.Parse(reader.Value); } else if (property.Equals("degree")) { ecr.degreeProgramID = Int32.Parse(reader.Value); } else if (property.Equals("electivelist")) { ecr.electiveListID = Int32.Parse(reader.Value); } else if (property.Equals("semester")) { ecr.semester = Int32.Parse(reader.Value); } else if (property.Equals("credits")) { ecr.credits = Int32.Parse(reader.Value); } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.ElectiveCourse")) { try { context.ElectiveCourses.AddOrUpdate(i => i.ID, ecr); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); reader = new XmlTextReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName + "ksu_prerequisitecourses.xml")); PrerequisiteCourse pre = null; property = null; count = 0; done = false; while (reader.Read() && !done) { switch (reader.NodeType) { case XmlNodeType.Element: // The node is an element. if (reader.Name.Equals("htmlparse.PrerequisiteCourse")) { pre = new PrerequisiteCourse(); } else { property = reader.Name; } break; case XmlNodeType.Text: //Display the text in each element. if (property.Equals("id")) { pre.ID = Int32.Parse(reader.Value); } else if (property.Equals("prerequisiteCourse")) { pre.prerequisiteCourseID = Int32.Parse(reader.Value); } else if (property.Equals("prerequisiteFor")) { pre.prerequisiteForCourseID = Int32.Parse(reader.Value); } break; case XmlNodeType.EndElement: //Display the end of the element. if (reader.Name.Equals("htmlparse.PrerequisiteCourse")) { try { context.PrerequisiteCourses.AddOrUpdate(i => i.ID, pre); //if (count++ > 500) //{ // done = true; //} } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { var sb = new System.Text.StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new Exception(sb.ToString()); } } break; } } reader.Close(); context.SaveChanges(); } }
public Object Update() { try { if (request.Type == ModelType.Course) { Course value = (request as Request <Course>).RequestedMembers[0]; Course replace = (request as Request <Course>).RequestedMembers[1]; return(new Response <Course>(request as Request <Course>, courses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.DegreeProgram) { DegreeProgram value = (request as Request <DegreeProgram>).RequestedMembers[0]; DegreeProgram replace = (request as Request <DegreeProgram>).RequestedMembers[1]; return(new Response <DegreeProgram>(request as Request <DegreeProgram>, degreePrograms.UpdateAndSave(value, replace))); } if (request.Type == ModelType.ElectiveCourse) { ElectiveCourse value = (request as Request <ElectiveCourse>).RequestedMembers[0]; ElectiveCourse replace = (request as Request <ElectiveCourse>).RequestedMembers[1]; return(new Response <ElectiveCourse>(request as Request <ElectiveCourse>, electiveCourses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.ElectiveList) { ElectiveList value = (request as Request <ElectiveList>).RequestedMembers[0]; ElectiveList replace = (request as Request <ElectiveList>).RequestedMembers[1]; return(new Response <ElectiveList>(request as Request <ElectiveList>, electiveLists.UpdateAndSave(value, replace))); } if (request.Type == ModelType.ElectiveListCourse) { ElectiveListCourse value = (request as Request <ElectiveListCourse>).RequestedMembers[0]; ElectiveListCourse replace = (request as Request <ElectiveListCourse>).RequestedMembers[1]; return(new Response <ElectiveListCourse>(request as Request <ElectiveListCourse>, electiveListCourses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.Plan) { Plan value = (request as Request <Plan>).RequestedMembers[0]; Plan replace = (request as Request <Plan>).RequestedMembers[1]; return(new Response <Plan>(request as Request <Plan>, plans.UpdateAndSave(value, replace))); } if (request.Type == ModelType.PlanCourse) { PlanCourse value = (request as Request <PlanCourse>).RequestedMembers[0]; PlanCourse replace = (request as Request <PlanCourse>).RequestedMembers[1]; return(new Response <PlanCourse>(request as Request <PlanCourse>, planCourses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.PrerequisiteCourse) { PrerequisiteCourse value = (request as Request <PrerequisiteCourse>).RequestedMembers[0]; PrerequisiteCourse replace = (request as Request <PrerequisiteCourse>).RequestedMembers[1]; return(new Response <PrerequisiteCourse>(request as Request <PrerequisiteCourse>, prerequisiteCourses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.RequiredCourse) { RequiredCourse value = (request as Request <RequiredCourse>).RequestedMembers[0]; RequiredCourse replace = (request as Request <RequiredCourse>).RequestedMembers[1]; return(new Response <RequiredCourse>(request as Request <RequiredCourse>, requiredCourses.UpdateAndSave(value, replace))); } if (request.Type == ModelType.Semester) { Semester value = (request as Request <Semester>).RequestedMembers[0]; Semester replace = (request as Request <Semester>).RequestedMembers[1]; return(new Response <Semester>(request as Request <Semester>, semesters.UpdateAndSave(value, replace))); } } catch { return(null); } return(null); }
public Object Add() { try { if (request.Type == ModelType.Course) { Course value = (request as Request <Course>).RequestedMembers.First(); return(new Response <Course>(request as Request <Course>, courses.AddAndSave(value))); } if (request.Type == ModelType.DegreeProgram) { DegreeProgram value = (request as Request <DegreeProgram>).RequestedMembers.First(); return(new Response <DegreeProgram>(request as Request <DegreeProgram>, degreePrograms.AddAndSave(value))); } if (request.Type == ModelType.ElectiveCourse) { ElectiveCourse value = (request as Request <ElectiveCourse>).RequestedMembers.First(); return(new Response <ElectiveCourse>(request as Request <ElectiveCourse>, electiveCourses.AddAndSave(value))); } if (request.Type == ModelType.ElectiveList) { ElectiveList value = (request as Request <ElectiveList>).RequestedMembers.First(); return(new Response <ElectiveList>(request as Request <ElectiveList>, electiveLists.AddAndSave(value))); } if (request.Type == ModelType.ElectiveListCourse) { ElectiveListCourse value = (request as Request <ElectiveListCourse>).RequestedMembers.First(); return(new Response <ElectiveListCourse>(request as Request <ElectiveListCourse>, electiveListCourses.AddAndSave(value))); } if (request.Type == ModelType.Plan) { Plan value = (request as Request <Plan>).RequestedMembers.First(); return(new Response <Plan>(request as Request <Plan>, plans.AddAndSave(value))); } if (request.Type == ModelType.PlanCourse) { PlanCourse value = (request as Request <PlanCourse>).RequestedMembers.First(); return(new Response <PlanCourse>(request as Request <PlanCourse>, planCourses.AddAndSave(value))); } if (request.Type == ModelType.PrerequisiteCourse) { PrerequisiteCourse value = (request as Request <PrerequisiteCourse>).RequestedMembers.First(); return(new Response <PrerequisiteCourse>(request as Request <PrerequisiteCourse>, prerequisiteCourses.AddAndSave(value))); } if (request.Type == ModelType.RequiredCourse) { RequiredCourse value = (request as Request <RequiredCourse>).RequestedMembers.First(); return(new Response <RequiredCourse>(request as Request <RequiredCourse>, requiredCourses.AddAndSave(value))); } if (request.Type == ModelType.Semester) { Semester value = (request as Request <Semester>).RequestedMembers.First(); return(new Response <Semester>(request as Request <Semester>, semesters.AddAndSave(value))); } } catch { return(null); } return(null); }