/// <summary>
 /// Attempts to add student to database if all necessary fields have input, otherwise error MessageBox is displayed
 /// </summary>
 /// <returns></returns>
 public void CommitStudent()
 {
     if (FormCompleted())
     {
         try
         {
             using (var context = new SchoolU_DBEntities())
             {
                 context.Database.Connection.Open();
                 var temp = new Student()
                 {
                     StudentFirstName = FirstName,
                     StudentLastName  = LastName,
                     StudentUserName  = "******",
                     StudentEmail     = null,
                     StudentPassword  = "******",
                     StudentYearId    = YearOf(nameof(SelectedStudentYear))
                 };
                 context.Entry(temp).State = EntityState.Added;
                 context.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             //MessageBox.Show(ex.Message);
             return;
         }
     }
     else
     {
         MessageBox.Show("Please make sure all necessary fields are completed.", "Input Error", MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Inserts all user input in the events screen into
 /// the database
 /// </summary>
 public void CommitNewEvent()
 {
     try
     {
         using (var context = new SchoolU_DBEntities())
         {
             context.Database.Connection.Open();
             int departmentId = 0;
             if (SelectedDepartment != DepartmentCollection.ElementAt(0))
             {
                 departmentId = context.Departments.Where(i => i.DepartmentName == SelectedDepartment.DepartmentName).Select(i => i.DepartmentId).Single();
             }
             var newEvent = new Event()
             {
                 EventName           = EventTitle,
                 EventDescription    = EventDescription,
                 IsSchoolWideEvent   = IsSchoolWideEvent,
                 EventDate           = StartDate,
                 EndDate             = EndDate,
                 IntrestedDepartment = departmentId,
                 EventStartTime      = DateTime.ParseExact(SelectedStartTime + ":00", "HH:mm", CultureInfo.InvariantCulture), EventEndTime = DateTime.ParseExact(SelectedEndTime + ":00", "HH:mm", CultureInfo.InvariantCulture)
             };
             context.Entry(newEvent).State = EntityState.Added;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         return;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Commits all the information on the courses screen,
        /// except the preReqs, to the courses table in database
        /// </summary>
        public void CommitCourse()
        {
            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    context.Database.Connection.Open();
                    int departmentId = 0;

                    // get department id
                    if (SelectedDepartment != DepartmentCollection.Where(i => i.DepartmentName == "None"))
                    {
                        departmentId = context.Departments.Where(i => i.DepartmentName == SelectedDepartment.DepartmentName).Select(i => i.DepartmentId).Single();
                    }

                    // if NOT editing, create a new course and save
                    if (Edit_SaveLabel == "Edit")
                    {
                        var newCourse = new Course()
                        {
                            CourseName   = CourseName,
                            DepartmentId = departmentId
                        };
                        context.Entry(newCourse).State = EntityState.Added;
                    }
                    // If editing, and course name or deparment is changed, then set status as modified before saving
                    else
                    {
                        Course currentCourse = context.Courses.Where(i => i.CourseName == OldCourseName).Single();

                        if (IsSelectedDepartmentDifferent())
                        {
                            currentCourse.DepartmentId = departmentId;
                        }
                        currentCourse.CourseName           = CourseName;
                        context.Entry(currentCourse).State = EntityState.Modified;
                    }
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return;
            }
        }
Exemplo n.º 4
0
 public void CommitMajor()
 {
     try
     {
         using (var context = new SchoolU_DBEntities())
         {
             context.Database.Connection.Open();
             var temp = new Major {
                 MajorDescription = MajorDesc, MajorAbbr = MajorAbbr
             };
             context.Entry(temp).State = EntityState.Added;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         return;
     }
 }
Exemplo n.º 5
0
 public void DeleteDepartment()
 {
     try
     {
         using (var context = new SchoolU_DBEntities())
         {
             if (SelectedDepartment != null)
             {
                 Department getDepartmentInfo = context.Departments.Where(i => i.DepartmentName == SelectedDepartment.DepartmentName && i.DepartmentAbbr == SelectedDepartment.DepartmentAbbr).Single();
                 context.Entry(getDepartmentInfo).State = EntityState.Deleted;
                 context.SaveChanges();
                 DepartmentCollection.Remove(SelectedDepartment);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
         return;
     }
 }
Exemplo n.º 6
0
 public void CommitDepartment()
 {
     try
     {
         using (var context = new SchoolU_DBEntities())
         {
             context.Database.Connection.Open();
             var temp = new Department()
             {
                 DepartmentName = DpName, DepartmentAbbr = DpAbbr
             };
             context.Entry(temp).State = EntityState.Added;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         return;
     }
 }
Exemplo n.º 7
0
        /// <summary>
        /// Commits the courses, that were moved to the
        /// pre-reqs listview, to the preReqs table
        /// </summary>
        public void CommitPreReqs()
        {
            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    // Gets all the courses names
                    IList <string> allCourseName = context.Courses.Where(i => i.CourseId != 0).Select(i => i.CourseName).ToList();
                    // Gets the course id for the course that was recently added
                    int courseAdded = context.Courses.Where(i => i.CourseName == CourseName).Select(i => i.CourseId).Single();

                    if (SelectedCourseCollection.Any())
                    {
                        // Stores the PreRequisite objects so they can be added all at the same time using the AddRange method
                        IList <PreRequisite> PreReqList = new List <PreRequisite>();

                        if (IsPreReqListDifferent())
                        {
                            for (int i = 0; i < GetPreReqIds().Count; i++)
                            {
                                var newPreReq = new PreRequisite()
                                {
                                    CourseId = courseAdded,
                                    PrereqId = GetPreReqIds().ElementAt(i)
                                };
                                PreReqList.Add(newPreReq);
                            }
                            context.PreRequisites.AddRange(PreReqList);
                        }
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return;
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Deletes the selected Course
 /// </summary>
 public void DeleteSelectedCourse()
 {
     try
     {
         using (var context = new SchoolU_DBEntities())
         {
             if (SelectedCourse != null)
             {
                 // Removes the selected course from the Available courses list
                 // Then deletes it from the database
                 Course courseForDeletion = context.Courses.Where(i => i.CourseName == SelectedCourse.CourseName).Single();
                 context.Entry(courseForDeletion).State = EntityState.Deleted;
                 AvailableCourseCollection.Remove(courseForDeletion);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         //MessageBox.Show(ex.Message);
         return;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Deletes the pre-requisites for the selected course
        /// </summary>
        public void DeleteSelectedCourse_PreRequisites()
        {
            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    if (SelectedCourse != null)
                    {
                        // Gets the selected course's course Id
                        int courseId = context.Courses.Where(i => i.CourseName == SelectedCourse.CourseName).Select(i => i.CourseId).Single();
                        // Gets the pre-req ids for the selected course
                        IList <int> PreReqIds = context.PreRequisites.Where(i => i.CourseId == courseId).Select(i => i.PrereqId).ToList();

                        if (PreReqIds.Any())
                        {
                            // Gets a list of PreRequisite objects associated with the selected course
                            IList <PreRequisite> PreReqs = (from pr in context.PreRequisites join c in context.Courses
                                                            on pr.PrereqId equals c.CourseId
                                                            where PreReqIds.Contains(pr.PrereqId)
                                                            select pr).ToList();

                            context.PreRequisites.RemoveRange(PreReqs);
                            context.SaveChanges();
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Deletes the pre-reqs in the database so the
        /// new list of pre-reqs can be added
        /// </summary>
        public void DeletePreReqs()
        {
            try
            {
                using (var context = new SchoolU_DBEntities())
                {
                    // Gets the course object based on the selected Department Name
                    int currentlySelectedCourse = context.Courses.Where(i => i.CourseName == CourseName).Select(i => i.CourseId).Single();

                    // Gets a list of pre-reqs where the course id is the course currently in edit
                    IList <PreRequisite> preReqIds = (from c in context.Courses
                                                      join pr in context.PreRequisites on c.CourseId equals pr.CourseId
                                                      where c.CourseId == currentlySelectedCourse
                                                      select pr).ToList();

                    if (preReqIds.Any())
                    {
                        // List to store the pre-req objects to delete
                        IList <PreRequisite> PreReqsToDelete = new List <PreRequisite>();

                        foreach (var preReq in preReqIds)
                        {
                            PreReqsToDelete.Add(preReq);
                        }

                        context.PreRequisites.RemoveRange(PreReqsToDelete);
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);
                return;
            }
        }