/// <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);
     }
 }
Пример #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;
     }
 }
Пример #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;
            }
        }
Пример #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;
     }
 }
Пример #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;
     }
 }
Пример #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;
     }
 }
Пример #7
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;
     }
 }