示例#1
0
 private Plan createTempPlan()
 {
     Plan temp = new Plan()
     {
         ID = 3,
         planName = "Plan 3",
         degreeProgramID = 2,
         degreeProgram = degreePrograms.Find(2),
         userID = 2,
         user = users.Find(2),
         semesterID = 2,
         semester = semesters.Find(2),
         planCourses = new Collection<PlanCourse>()
     };
     temp.degreeProgram.requiredCourses = new List<RequiredCourse>();
     temp.degreeProgram.electiveCourses = new List<ElectiveCourse>();
     return temp;
 }
示例#2
0
        private void ChangeDegreeProgram(Plan plan)
        {
            List<PlanCourse> plans = planCourses.Where(i => i.planID == plan.ID).ToList();
            foreach (PlanCourse planCourse in plans)
            {
                planCourses.Remove(planCourse);
                planCourses.SaveChanges();
            }
            Dictionary<int, int> semesterOrders = new Dictionary<int, int>();
            Dictionary<int, int> semesterMap = new Dictionary<int, int>();
            int nowSem = 1;
            List<Semester> semesterList = semesters.Where(i => i.ID >= plan.semesterID).ToList();
            foreach (Semester sem in semesterList)
            {
                if (sem.standard == true)
                {
                    semesterMap.Add(nowSem, sem.ID);
                    semesterOrders.Add(nowSem, 0);
                    nowSem++;
                }
            }

            List<RequiredCourse> requirements = plan.degreeProgram.requiredCourses.ToList();
            foreach (RequiredCourse req in requirements)
            {
                PlanCourse pcourse = new PlanCourse();
                pcourse.planID = plan.ID;
                int order = semesterOrders[req.semester];
                pcourse.order = order;
                semesterOrders[req.semester] = order + 1;
                pcourse.semesterID = semesterMap[req.semester];
                pcourse.courseID = req.courseID;
                pcourse.credits = req.course.courseHours;
                planCourses.Add(pcourse);
                planCourses.SaveChanges();
            }

            List<ElectiveCourse> elects = plan.degreeProgram.electiveCourses.ToList();
            foreach (ElectiveCourse elect in elects)
            {
                PlanCourse pcourse = new PlanCourse();
                pcourse.planID = plan.ID;
                int order = semesterOrders[elect.semester];
                pcourse.order = order;
                semesterOrders[elect.semester] = order + 1;
                pcourse.semesterID = semesterMap[elect.semester];
                pcourse.electiveListID = elect.electiveListID;
                pcourse.credits = elect.credits.ToString();
                planCourses.Add(pcourse);
                planCourses.SaveChanges();
            }
        }
        public ActionResult Create(Plan plan)
        {
            if (ModelState.IsValid)
            {
                //plans.Add(plan);
                //plans.SaveChanges();
                Plan newPlan = _planProducer.Create(plan).First();

                //Plan newPlan = plans.Find(plan.ID);
                //Plan newPlan = _planProducer.Get(new Plan() { ID = id });
                newPlan = _planProducer.Get(newPlan);
                //newPlan.degreeProgram = degreePrograms.Find(newPlan.degreeProgramID);
                ChangeDegreeProgram(newPlan);
                return RedirectToAction("Index");
            }
            ViewBag.degreeProgramID = new SelectList(_degreeProgramProducer.GetAll().AsEnumerable(), "ID", "degreeProgramName", plan.degreeProgramID);
            //ViewBag.degreeProgramID = new SelectList(degreePrograms.GetAll().AsEnumerable(), "ID", "degreeProgramName", plan.degreeProgramID);
            if (webSecurity.CurrentUser.IsInRole("Advisor"))
            {
                ViewBag.userID = new SelectList(users.GetAll().AsEnumerable(), "ID", "username");
                ViewBag.Advisor = true;
            }
            else
            {
                ViewBag.userID = webSecurity.CurrentUserId;
                ViewBag.Advisor = false;
            }
            var semesterList = _semesterProducer.GetAll().Where(i => i.standard == true);
            ViewBag.semesterID = new SelectList(semesterList.AsEnumerable(), "ID", "semesterName");
            return View(plan);
        }
示例#4
0
 public ActionResult Edit(Plan plan)
 {
     if (ModelState.IsValid)
     {
         Plan planAttached = plans.Find(plan.ID);
         plan.userID = planAttached.userID;
         if (webSecurity.CurrentUser.IsInRole("Advisor") || plan.userID == webSecurity.CurrentUserId)
         {
             plans.UpdateValues(planAttached, plan);
             plans.SaveChanges();
             Plan newPlan = plans.Find(plan.ID);
             newPlan.degreeProgram = degreePrograms.Find(newPlan.degreeProgramID);
             ChangeDegreeProgram(newPlan);
             return RedirectToAction("Index");
         }
     }
     ViewBag.degreeProgramID = new SelectList(degreePrograms.GetAll().AsEnumerable(), "ID", "degreeProgramName", plan.degreeProgramID);
     if (webSecurity.CurrentUser.IsInRole("Advisor"))
     {
         ViewBag.userID = new SelectList(users.GetAll().AsEnumerable(), "ID", "username", plan.userID);
         ViewBag.Advisor = true;
     }
     else
     {
         ViewBag.userID = webSecurity.CurrentUserId;
         ViewBag.Advisor = false;
     }
     ViewBag.semesterID = new SelectList(semesters.Where(i => i.standard == true).AsEnumerable(), "ID", "semesterName", plan.semesterID);
     return View(plan);
 }
示例#5
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;
        }