示例#1
0
        public static bool DeleteUser(string email, string passAssert, string passRepeat)
        {
            using (var db = new HwProj_DBContext())
            {
                if (passAssert != passRepeat)
                {
                    return(false);
                }

                if (db.Teacher.Any(t => t.Email == email && t.Password == passAssert))
                {
                    var curUser = db.Teacher.Find(email);
                    db.Teacher.Remove(curUser);
                }
                else if (db.Student.Any(s => s.Email == email && s.Password == passAssert))
                {
                    var curUser = db.Student.Find(email);
                    db.Student.Remove(curUser);
                }
                else
                {
                    return(false);
                }
                db.SaveChanges();
                return(true);
            }
        }
示例#2
0
 public static bool CreateAccount(string email, string pass, string fullname, bool isTeacher)
 {
     using (var db = new HwProj_DBContext())
     {
         if (db.Teacher.Any(user => user.Email == email) || db.Student.Any(user => user.Email == email))
         {
             return(false);
         }
         if (isTeacher)
         {
             var newTeacher = new Teacher()
             {
                 Email = email, Password = pass, FullName = fullname
             };
             db.Teacher.Add(newTeacher);
         }
         else
         {
             var newStudent = new Student()
             {
                 Email = email, Password = pass, FullName = fullname
             };
             db.Student.Add(newStudent);
         }
         db.SaveChanges();
         return(true);
     }
 }
 public static void DeleteOngoingCourse(int courseId)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.OngoingCourse.First(course => course.Id == courseId);
         db.OngoingCourse.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#4
0
 public static void ChangeUrl(int id, string newUrl)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Material.Find(id);
         target.Url = newUrl;
         db.SaveChanges();
     }
 }
示例#5
0
 public static void DeleteAnnouncement(int id)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.Announcement.Find(id);
         db.Announcement.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#6
0
 public static void DeleteHomeworkFromCourse(int hwId)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.Homework.First(task => task.Id == hwId);
         db.Homework.Remove(toDelete);
         db.SaveChanges();
     }
 }
 public static void ChangeCourseTitle(int courseId, string newTitle)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Course.Find(courseId);
         target.Title = newTitle;
         db.SaveChanges();
     }
 }
示例#8
0
 public static void DeleteSolution(int id)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.HomeworkSolution.First(s => s.Id == id);
         db.HomeworkSolution.Remove(toDelete);
         db.SaveChanges();
     }
 }
 public static void LeaveCourse(int studentId, int courseId)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.StudentCourse.Find((studentId, courseId));
         db.StudentCourse.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#10
0
 public static void SetAccepted(int id)
 {
     using (var db = new HwProj_DBContext())
     {
         var toSet = db.HomeworkSolution.First(s => s.Id == id);
         toSet.Status = 3;
         db.SaveChanges();
     }
 }
 public static void DeleteCourse(int courseId)
 {
     using (var db = new HwProj_DBContext())
     {
         var courseToDelete = db.Course.Find(courseId);
         db.Course.Remove(courseToDelete);
         db.SaveChanges();
     }
 }
示例#12
0
 public static void ChangeAnnouncement(int id, string newMsg)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Announcement.Find(id);
         target.Message = newMsg;
         db.SaveChanges();
     }
 }
示例#13
0
 public static void DeleteMaterial(int id)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.Material.Find(id);
         db.Material.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#14
0
 public static void DeleteLecture(int lecId)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.Lecture.Find(lecId);
         db.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#15
0
 public static void ChangeLectureTitle(int lecId, string newTitle)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Lecture.Find(lecId);
         target.Title = newTitle;
         db.SaveChanges();
     }
 }
示例#16
0
 public static void DeleteTest(int testId)
 {
     using (var db = new HwProj_DBContext())
     {
         var toDelete = db.Test.First(task => task.Id == testId);
         db.Test.Remove(toDelete);
         db.SaveChanges();
     }
 }
示例#17
0
 public static void SetRequestChanges(int id)
 {
     using (var db = new HwProj_DBContext())
     {
         var toSet = db.TestSolution.First(s => s.Id == id);
         toSet.Status = 2;
         db.SaveChanges();
     }
 }
示例#18
0
 public static void DeleteHometask(int taskId)
 {
     using (var db = new HwProj_DBContext())
     {
         var taskToDelete =
             db.Hometask.First(task => task.Id == taskId);
         db.Hometask.Remove(taskToDelete);
         db.SaveChanges();
     }
 }
示例#19
0
 public static void AddAnnouncement(int lectureId, string msg)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Lecture.First(l => l.Id == lectureId);
         var toAdd  = new Announcement()
         {
             LectureId = lectureId, Message = msg, Lecture = target
         };
         target.Announcement.Add(toAdd);
         db.Announcement.Add(toAdd);
         db.SaveChanges();
     }
 }
示例#20
0
 public static void AddMaterial(int lectureId, string url)
 {
     using (var db = new HwProj_DBContext())
     {
         var target = db.Lecture.Find(lectureId);
         var toAdd  = new Material()
         {
             LectureId = lectureId,
             Url       = url,
             Lecture   = target
         };
         db.Material.Add(toAdd);
         db.SaveChanges();
     }
 }
示例#21
0
 public static void AddNewLecture(int courseId, string title)
 {
     using (var db = new HwProj_DBContext())
     {
         var relatedCourse = db.OngoingCourse.First(c => c.Id == courseId);
         var toAdd         = new Lecture()
         {
             CourseId = courseId,
             Title    = title,
             Course   = relatedCourse
         };
         relatedCourse.Lecture.Add(toAdd);
         db.Lecture.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();
     }
 }
示例#23
0
 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();
     }
 }
示例#24
0
 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 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 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 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();
     }
 }
示例#28
0
 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();
     }
 }
示例#29
0
 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 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();
     }
 }