public static void DeleteCourse(int id) { using (var context = new Classmaister5000Entities()) { var deleteThis = context.Courses.Where(c => c.Id == id).First(); TimetableActions.RemoveFromTimetableByCourseId(id); context.Courses.Remove(deleteThis); context.SaveChanges(); } }
public static bool SubjectRemove(string Name) { if (HasSubjectName(Name)) { using (var context = new Classmaister5000Entities()) { Subject removeThis = context.Subjects.Where(s => s.SubjectName.ToLower() == Name.ToLower()).First(); ICollection <Course> removeTheseCourses = removeThis.Courses; foreach (var item in removeTheseCourses) { TimetableActions.RemoveFromTimetableByCourseId(item.Id); } context.Courses.RemoveRange(removeTheseCourses); context.Subjects.Remove(removeThis); context.SaveChanges(); return(true); } } else { throw new SubjectNotExistsException(); } }