public static void AddTest(int taskId, int courseId) { using (var db = new HwProj_DBContext()) { var relatedTask = db.TestTask.First(task => task.Id == taskId); var relatedCourse = db.Course.First(course => course.Id == courseId); var toAdd = new Test() { TaskId = taskId, CourseId = courseId, Course = relatedCourse, Task = relatedTask }; db.Test.Add(toAdd); db.SaveChanges(); } }
public static void AssignToCourse(string studentEmail, int courseId) { using (var db = new HwProj_DBContext()) { var targetSt = db.Student.Find(studentEmail); var targetCourse = db.OngoingCourse.Find(courseId); var toAdd = new StudentCourse() { StudentId = studentEmail, CourseId = courseId, Course = targetCourse, Student = targetSt }; db.StudentCourse.Add(toAdd); db.SaveChanges(); } }
public static bool AddNewCourse(string title) { using (var db = new HwProj_DBContext()) { if (db.Course.Any(course => course.Title == title)) { return(false); } else { db.Course.Add(new Course() { Title = title }); db.SaveChanges(); return(true); } } }
public static bool AddNewHomeTask(string title, string description) { using (var db = new HwProj_DBContext()) { if (db.Hometask.Any(task => task.Description == description && task.Title == title)) { return(false); } else { db.Hometask.Add(new Hometask() { Title = title, Description = description }); db.SaveChanges(); return(true); } } }
public static void AddSolution(string studentEmail, int hwId, string url) { using (var db = new HwProj_DBContext()) { var relatedStudent = db.Student.First(s => s.Email == studentEmail); var relatedHw = db.CurrentHomework.First(hw => hw.Id == hwId); var toAdd = new HomeworkSolution() { StudentId = studentEmail, HomeworkId = hwId, Url = url, Homework = relatedHw, Student = relatedStudent }; relatedStudent.HomeworkSolution.Add(toAdd); relatedHw.HomeworkSolution.Add(toAdd); db.SaveChanges(); } }
public static void AssignTest(int courseId, int testId) { using (var db = new HwProj_DBContext()) { var relatedTest = db.Test.First(task => task.Id == testId); var relatedCourse = db.OngoingCourse.First(course => course.Id == courseId); var curDate = DateTime.Today; var toAdd = new CurrentTest() { CourseId = courseId, TestId = testId, Date = curDate, Course = relatedCourse, Test = relatedTest }; db.CurrentTest.Add(toAdd); db.SaveChanges(); } }
public static void AssignHomework(int courseId, int hwId) { using (var db = new HwProj_DBContext()) { var relatedHw = db.Homework.First(task => task.Id == hwId); var relatedCourse = db.OngoingCourse.First(course => course.Id == courseId); var curDate = DateTime.Today; var toAdd = new CurrentHomework() { CourseId = courseId, HwId = hwId, Date = curDate, Course = relatedCourse, Hw = relatedHw }; db.CurrentHomework.Add(toAdd); db.SaveChanges(); } }
public static void AddSolution(string studentEmail, int testId, string url) { using (var db = new HwProj_DBContext()) { var relatedStudent = db.Student.First(s => s.Email == studentEmail); var relatedTest = db.CurrentTest.First(test => test.Id == testId); var toAdd = new TestSolution() { StudentId = studentEmail, TestId = testId, Url = url, Test = relatedTest, Student = relatedStudent }; relatedStudent.TestSolution.Add(toAdd); relatedTest.TestSolution.Add(toAdd); db.SaveChanges(); } }
public static void AddNewOngoingCourse(string teacherEmail, int courseId, string group, string title) { using (var db = new HwProj_DBContext()) { var relatedCourse = db.Course.First(c => c.Title == title); var teacher = db.Teacher.First(t => t.Email == teacherEmail); var course = db.Course.First(c => c.Id == courseId); var toAdd = new OngoingCourse() { TeacherId = teacherEmail, CourseId = courseId, GroupId = group, Course = course, Teacher = teacher, }; db.OngoingCourse.Add(toAdd); db.SaveChanges(); } }
public static bool ChangePassword(string email, string curPass, string passRepeat, string newPass) { if (curPass != passRepeat) { return(false); } using (var db = new HwProj_DBContext()) { if (db.Teacher.Any(t => t.Email == email && t.Password == curPass)) { db.Teacher.First(t => t.Email == email).Password = newPass; } else if (db.Student.Any(t => t.Email == email && t.Password == curPass)) { db.Student.First(s => s.Email == email).Password = newPass; } else { return(false); } db.SaveChanges(); return(true); } }
private static IEnumerable <Teacher> GetTeachers(HwProj_DBContext db) { var teachers = db.Teacher.AsEnumerable(); return(teachers); }
private static IEnumerable <Student> GetStudents(HwProj_DBContext db) { var students = db.Student.AsEnumerable(); return(students); }