Esempio n. 1
0
        /// <summary>
        /// Check if the list of pre-requisites is different in any way
        /// If so, then returns true
        /// </summary>
        /// <returns></returns>
        public bool IsPreReqListDifferent()
        {
            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    // Gets the course object based on the selected Department Name
                    Course currentlySelectedCourse = context.Courses.Where(i => i.CourseName == CourseName).Single();
                    // Variable to keep track of difference in pre-req list
                    bool isDifferent = true;

                    IList <int> preReqIds = (from c in context.Courses
                                             join pr in context.PreRequisites on c.CourseId equals pr.CourseId
                                             where c.CourseId == currentlySelectedCourse.CourseId
                                             select pr.PrereqId).ToList();

                    if (preReqIds.Any())
                    {
                        // Gets the course name based on the Pre-req Id
                        IList <Course> course_Name = context.Courses.Where(i => preReqIds.Contains(i.CourseId)).ToList();

                        if (SelectedCourseCollection.Count() == preReqIds.Count())
                        {
                            foreach (var item in course_Name)
                            {
                                // IsDifferent is set to false when the list hasn't changed at all
                                if (SelectedCourseCollection.Where(i => i.CourseId == item.CourseId).Any())
                                {
                                    isDifferent = false;
                                }
                                // IsDifferent is set to true when the list is different in one or more ways
                                else
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                    return(isDifferent);
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a list of course Ids based on the pre-req names
        /// currently in the pre-reqs list (SelectedCourseCollection)
        /// </summary>
        /// <returns></returns>
        public IList <int> GetPreReqIds()
        {
            IList <int> preReqIds = new List <int>();

            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    if (SelectedCourseCollection.Any())
                    {
                        // Gets all the pre-req courses names
                        IList <string> pre_reqNames = SelectedCourseCollection.Where(i => i.CourseName != string.Empty).Select(i => i.CourseName).ToList();
                        // Gets all the course ids off of the courses names added to the pre-reqs list // pre-req = course ids
                        return(preReqIds = context.Courses.Where(i => pre_reqNames.Contains(i.CourseName)).Select(i => i.CourseId).ToList());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
            return(null);
        }
Esempio n. 3
0
 /// <summary>
 /// Checks if the course in edit is added
 /// as it's own pre-requisite
 /// </summary>
 /// <returns></returns>
 public bool IsCourseItsOwnPreRequisite()
 {
     return(GetPreReqIds().Contains(SelectedCourseCollection.Where(i => i.CourseName == CourseName).Select(i => i.CourseId).SingleOrDefault()));
 }