public CourseViewModel(Course m)
        {
            ID = m.ID;
            Number = m.Number;
            Name = m.Name;
            IsFoundational = m.IsFoundational;

            Prerequisites = (m.Prerequisites == null) ? new List<CourseViewModel>() :  m.Prerequisites.Select(n => new CourseViewModel(n)).ToList();
        }
        public CourseViewModel Course(Course course)
        {
            using (var ctx = new ApplicationDbContext())
            {
                if (course.Number == null || course.Name == null || ctx.Courses.Where(m => m.Number == course.Number).Any())
                {
                    //record already exists or is invalid
                    return null;
                }

                if (course.Prerequisites != null)
                {
                    var prereqIds = course.Prerequisites.Select(n => n.ID);

                    course.Prerequisites = ctx.Courses.Where(m => prereqIds.Contains(m.ID)).ToList();
                }
                ctx.Courses.Add(course);
                ctx.SaveChanges();

                return new CourseViewModel(course);
            }
        }
 public CourseViewModel(Course m, bool isCompleted)
     : this(m)
 {
     IsCompleted = isCompleted;
 }
        /// <summary>
        /// The writeResults class writes the Course Optimization run to the database.  The class takes in the optimization model, all students, all courses, 
        /// all semesters, all course/semster offerings, the dB context, the optimization variable (total slack for overbooked students across all course/
        /// semester offerings, and the RunName provided to the Optimization engine.  
        /// </summary>
        /// <param name="GRBModelData"></param>
        /// <param name="students"></param>
        /// <param name="courses"></param>
        /// <param name="sems"></param>
        /// <param name="crssems"></param>
        /// <param name="ctx"></param>
        /// <param name="ObjectiveValue"></param>
        /// <param name="RunName"></param>
        private static void writeResults(GRBVar[,,] GRBModelData, StudentPreference[] students, Course[] courses, Semester[] sems, CourseSemester[] crssems, ApplicationDbContext ctx, int ObjectiveValue, string RunName)
        {
            Recommendation rec = new Recommendation() { Name = RunName };
            rec.Records = new List<RecommendationRecord>();
            rec.StudentPreferences = students;
            rec.CourseSemesters = crssems;

            rec.MissingSeats = ObjectiveValue;
            for (int i = 0; i < students.Length; i++)
            {
                for (int j = 0; j < courses.Length; j++)
                {
                    for (int k = 0; k < sems.Length; k++)
                    {
                        try
                        {
                            if (GRBModelData[i, j, k].Get(GRB.DoubleAttr.X) == 1)
                                rec.Records.Add(new RecommendationRecord() { StudentPreference = students[i], CourseSemester = crssems.Single(m => m.Course == courses[j] && m.Semester == sems[k]) });
                        }
                        catch (GRBException e)
                        {
                        }
                    }
                }
            }
            ctx.Recommendations.Add(rec);
            ctx.SaveChanges();
        }