public static List<CourseOffering> GetAllCourseOfferings(Lab7DbEntities1 entity) { //entity.Configuration.AutoDetectChangesEnabled = false; var courseOfferingList = entity.CourseOfferings.ToList(); courseOfferingList.Sort(new CourseSorter().Compare); return courseOfferingList; }
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; }
public static CourseOffering GetCourseOffering(string title, Lab7DbEntities1 entity) { //entity.Configuration.AutoDetectChangesEnabled = false; var offering = (from c in entity.CourseOfferings where c.Course_CourseID + " " + c.Course.CourseTitle + " " + c.Year + " " + c.Semester == title select c).FirstOrDefault(); return offering; }
public static bool HasStudents(string id, Lab7DbEntities1 entity) { if (GetStudents(GetCourseOffering(id, entity)).Count == 0) { return false; } return true; }
protected void submitCourse_OnClick(object sender, EventArgs e) { if (db.Courses.Any()) { using (var context = new Lab7DbEntities1()) { foreach (var c in db.Courses) { if (c.CourseID == courseNumber.Text) { Title = "Course already exists"; } else { Course course = new Course { CourseID = courseNumber.Text, CourseTitle = courseName.Text, HoursPerWeek = Int32.Parse(wklyHours.Text) }; context.Courses.Add(course); context.SaveChanges(); } } } } else { using (var context = new Lab7DbEntities1()) { Course course = new Course { CourseID = courseNumber.Text, CourseTitle = courseName.Text, HoursPerWeek = Int32.Parse(wklyHours.Text) }; context.Courses.Add(course); context.SaveChanges(); } } }
protected void submitCourse_OnClick(object sender, EventArgs e) { if (db.Courses.Any()) { using (var context = new Lab7DbEntities1()) { Course course = new Course { CourseID = courseNumber.Text, CourseTitle = courseName.Text, HoursPerWeek = Int32.Parse(wklyHours.Text), Description = txtbxDesc.Text }; context.Courses.AddOrUpdate(course); context.SaveChanges(); } } else { using (var context = new Lab7DbEntities1()) { Course course = new Course { CourseID = courseNumber.Text, CourseTitle = courseName.Text, HoursPerWeek = Int32.Parse(wklyHours.Text), Description = txtbxDesc.Text }; context.Courses.AddOrUpdate(course); context.SaveChanges(); } } }
public static bool StudentExists(CourseOffering offering, string number,Lab7DbEntities1 entity) { //entity.Configuration.AutoDetectChangesEnabled = false; return offering.Students.FirstOrDefault(s => s.StudentNum == number) != null; }