Example #1
0
        public override bool Equals(object obj)
        {
            RequiredCourse course = obj as RequiredCourse;

            if (course != null)
            {
                if (course.ID == ID)
                {
                    return(true);
                }
                return(false);
            }
            return(base.Equals(obj));
        }
 public void RequiredCourseEquality()
 {
     RequiredCourse course1 = new RequiredCourse()
     {
         ID = 1,
         courseID = 1
     };
     RequiredCourse course2 = new RequiredCourse()
     {
         ID = 1,
         courseID = 2
     };
     Assert.AreEqual(course1, course2);
 }
 /// <summary>
 /// @russfeld
 /// This uses AJAX to return the HTML code for a new required 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 RequiredCourseRow(int id = 0)
 {
     if (id > 0)
     {
         RequiredCourse reqcourse = new RequiredCourse()
         {
             degreeProgramID = id,
             courseID = -1,
             semester = 1
         };
         return PartialView("RequiredCourseFormPartial", reqcourse);
     }
     else
     {
         return PartialView("RequiredCourseFormPartial");
     }
 }
Example #4
0
        public static Object GetRegularObject(Type type, Object o, bool continueDeserializing = true)
        {
            Object return_object = null;
            if (type == typeof(DegreeProgram))
            {
                SerializableModels.DegreeProgram dp = (SerializableModels.DegreeProgram) o;

                DegreeProgram newItem = new DegreeProgram
                {
                    ID = dp.ID,
                    degreeProgramName = dp.degreeProgramName,
                    degreeProgramDescription = dp.degreeProgramDescription,
                };

                if (dp.requiredCourses != null && dp.electiveCourses != null)
                {
                    newItem.requiredCourses = new List<RequiredCourse>();
                    newItem.electiveCourses = new List<ElectiveCourse>();
                    foreach (SerializableModels.RequiredCourse rc in dp.requiredCourses)
                    {
                        newItem.requiredCourses.Add((RequiredCourse)GetRegularObject(typeof(RequiredCourse), rc, true));
                    }
                    foreach (SerializableModels.ElectiveCourse ec in dp.electiveCourses)
                    {
                        newItem.electiveCourses.Add((ElectiveCourse)GetRegularObject(typeof(ElectiveCourse), ec, true));
                    }
                }

                return_object = newItem;
            }
            else if (type == typeof(RequiredCourse))
            {
                SerializableModels.RequiredCourse rq = (SerializableModels.RequiredCourse) o;

                RequiredCourse newItem = new RequiredCourse
                {
                    ID = rq.ID,
                    courseID = rq.courseID,
                    degreeProgramID = rq.degreeProgramID,
                    semester = rq.semester,
                };

                newItem.course = (Course)GetRegularObject(typeof(Course), rq.course, true);

                return_object = newItem;
            }
            else if (type == typeof(ElectiveCourse))
            {
                SerializableModels.ElectiveCourse eq = (SerializableModels.ElectiveCourse) o;

                ElectiveCourse newItem = new ElectiveCourse
                {
                    ID = eq.ID,
                    electiveListID = eq.electiveListID,
                    degreeProgramID = eq.degreeProgramID,
                    semester = eq.semester,
                    credits = eq.credits,
                };

                newItem.electiveList = (ElectiveList)GetRegularObject(typeof(ElectiveList), eq.electiveList, true);

                return_object = newItem;
            }
            else if (type == typeof(Course))
            {
                SerializableModels.Course c = (SerializableModels.Course) o;

                Course newItem = new Course
                {
                    ID = c.ID,
                    coursePrefix = c.coursePrefix,
                    courseNumber = c.courseNumber,
                    courseTitle = c.courseTitle,
                    courseDescription = c.courseDescription,
                    minHours = c.minHours,
                    maxHours = c.maxHours,
                    undergrad = c.undergrad,
                    graduate = c.graduate,
                    variable = c.variable,
                };

                if (continueDeserializing)
                {
                    List<PrerequisiteCourse> prereqsList = new List<PrerequisiteCourse>();
                    List<PrerequisiteCourse> prereqsForList = new List<PrerequisiteCourse>();
                    foreach (SerializableModels.PrerequisiteCourse pc in c.prerequisites)
                    {
                        prereqsList.Add((PrerequisiteCourse)GetRegularObject(typeof(PrerequisiteCourse), pc, true));
                    }
                    foreach (SerializableModels.PrerequisiteCourse pc in c.prerequisiteFor)
                    {
                        prereqsForList.Add((PrerequisiteCourse)GetRegularObject(typeof(PrerequisiteCourse), pc, true));
                    }
                    newItem.prerequisites = prereqsList.ToArray();
                    newItem.prerequisiteFor = prereqsForList.ToArray();
                }

                return_object = newItem;
            }
            else if (type == typeof(ElectiveList))
            {
                SerializableModels.ElectiveList eList = (SerializableModels.ElectiveList) o;

                ElectiveList newItem = new ElectiveList
                {
                    ID = eList.ID,
                    electiveListName = eList.electiveListName,
                    shortName = eList.shortName,
                };

                return_object = newItem;
            }
            else if (type == typeof(ElectiveListCourse))
            {
                SerializableModels.ElectiveListCourse elc = (SerializableModels.ElectiveListCourse) o;

                ElectiveListCourse newItem = new ElectiveListCourse
                {
                    ID = elc.ID,
                    courseID = elc.courseID,
                    electiveListID = elc.electiveListID,
                    course = (Course)GetRegularObject(typeof(Course), elc.course, true),
                };

                return_object = newItem;
            }
            else if (type == typeof(PrerequisiteCourse))
            {
                SerializableModels.PrerequisiteCourse pc = (SerializableModels.PrerequisiteCourse) o;

                PrerequisiteCourse newItem = new PrerequisiteCourse
                {
                    ID = pc.ID,
                    prerequisiteCourseID = pc.prerequisiteCourseID,
                    prerequisiteForCourseID = pc.prerequisiteForCourseID,
                    prerequisiteCourse = (Course)GetRegularObject(typeof(Course),pc.prerequisiteCourse,false),
                    prerequisiteForCourse = (Course)GetRegularObject(typeof(Course), pc.prerequisiteForCourse, false),
                };

                return_object = newItem;
            }
            else if (type == typeof(Plan))
            {
                SerializableModels.Plan plan = (SerializableModels.Plan) o;

                Plan newItem = new Plan
                {
                    ID = plan.ID,
                    planName = plan.planName,
                    degreeProgramID = plan.degreeProgramID,
                    userID = plan.userID,
                    semesterID = plan.semesterID,
                    semester = plan.semester,
                };

                if (continueDeserializing)
                {
                    newItem.degreeProgram = (DegreeProgram)GetRegularObject(typeof(DegreeProgram), plan.degreeProgram, false);
                    newItem.user = (User)GetRegularObject(typeof(User), plan.user, true);
                    List<PlanCourse> planCourses = new List<PlanCourse>();
                    foreach (SerializableModels.PlanCourse planCourse in plan.planCourses)
                    {
                        planCourses.Add((PlanCourse)GetRegularObject(typeof(PlanCourse), planCourse, true));
                    }
                    newItem.planCourses = planCourses.ToArray();
                }

                return_object = newItem;
            }
            else if (type == typeof(User))
            {
                SerializableModels.User user = (SerializableModels.User) o;

                User newItem = new User
                {
                    ID = user.ID,
                    username = user.username,
                    realName = user.realName,
                };

                if (continueDeserializing && user.plans != null)
                {
                    List<Plan> plans = new List<Plan>();
                    foreach (SerializableModels.Plan plan in user.plans)
                    {
                        plans.Add((Plan)GetRegularObject(typeof(Plan), plan, false));
                    }
                }

                return_object = newItem;
            }
            else if (type == typeof(PlanCourse))
            {
                SerializableModels.PlanCourse pc = (SerializableModels.PlanCourse) o;

                PlanCourse newItem = new PlanCourse
                {
                    ID = pc.ID,
                    notes = pc.notes,
                    planID = pc.planID,
                    courseID = pc.courseID,
                    electiveListID = pc.electiveListID,
                    semesterID = pc.semesterID,
                    order = pc.order,
                    semester = pc.semester,
                    credits = pc.credits,
                };

                if (continueDeserializing)
                {
                    newItem.plan = (Plan)GetRegularObject(typeof(Plan), pc.plan, false);
                    if (pc.course.courseDescription != null)
                    {
                        newItem.course = (Course)GetRegularObject(typeof(Course), pc.course, true);
                    }
                    newItem.electiveList = (ElectiveList)GetRegularObject(typeof(ElectiveList), pc.electiveList, false);
                }

                return_object = newItem;
            }
            else
            {
                throw new NotImplementedException();
            }
            return return_object;
        }