protected void AddCourseOffering_OnClick(object sender, EventArgs e)
    {
        try
        {
            CourseOffering offer = null;
            //checking if there are any courses to compare to
            if (db.CourseOfferings.Any())
            {
                using (var context = new Lab7DbEntities1())
                {
                    foreach (var c in db.CourseOfferings)
                    {
                        //checking if the course has already been added
                        if (c.Course.CourseID == drpCourse.SelectedValue && c.Semester == drpSemester.SelectedValue &&
                            c.Year.ToString() == drpYear.SelectedValue)
                        {
                            Title = "This course has already been registered for this semester and year";
                        }
                        //add the course as courseOffering
                        else
                        {
                            offer = new CourseOffering
                            {
                                Course_CourseID = drpCourse.SelectedValue,
                                Semester = drpSemester.SelectedValue,
                                Year = Int32.Parse(drpYear.SelectedValue)
                            };

                        }
                        context.CourseOfferings.Add(offer);
                        context.SaveChanges();
                    }
                }

            }
            //if courseOffering list is empty add the course
            else
            {
                using (var context = new Lab7DbEntities1())
                {
                    offer = new CourseOffering
                    {
                        Course_CourseID = drpCourse.SelectedValue,
                        Semester = drpSemester.SelectedValue,
                        Year = Int32.Parse(drpYear.SelectedValue)
                    };

                    context.CourseOfferings.Add(offer);
                    context.SaveChanges();
                }
            }
        }
        catch (Exception er)
        {

        }

        drpYear.SelectedIndex = 0;
        drpSemester.SelectedIndex = 0;
    }
Esempio n. 2
0
 public static List<Student> GetStudents(CourseOffering offering)
 {
     if (offering == null)
     {
         return null;
     }
     var studentList = offering.Students.ToList();
     studentList.Sort(new StudentSorter().Compare);
     return studentList;
 }
Esempio n. 3
0
 public static bool StudentExists(CourseOffering offering, string number,Lab7DbEntities1 entity)
 {
     //entity.Configuration.AutoDetectChangesEnabled = false;
     return offering.Students.FirstOrDefault(s => s.StudentNum == number) != null;
 }