public static List <CourseViewModel> GetCoursesToTeacher(string snn) { using (var context = new FinalSchool()) { var CourseViewModelList = new List <CourseViewModel>(); var coursesNeww = (from teacher in context.Teachers join tc in context.TeacherCourses on teacher.TeacherId equals tc.TeacherId where teacher.TeacherId == snn join course in context.Courses on tc.CourseId equals course.CourseId select course).ToList(); foreach (var course in coursesNeww) { var courseView = new CourseViewModel() { CourseId = course.CourseId, LevelName = course.Level.Name, Name = course.Name }; CourseViewModelList.Add(courseView); } return(CourseViewModelList); } }
public static void PutOne(TeacherViewModel teacherModel) { using (var context = new FinalSchool()) { var id = teacherModel.TeacherSNN; foreach (var item in teacherModel.CourseName) { var CourseId = context.Courses.FirstOrDefault(w => w.Name == item).CourseId; var teacherCourse = context.TeacherCourses.Find(id); teacherCourse.TeacherId = id; teacherCourse.CourseId = CourseId; } var teacher = context.Teachers.FirstOrDefault(x => x.TeacherId == teacherModel.TeacherSNN); teacher.TeacherId = teacherModel.TeacherSNN; teacher.FName = teacherModel.FName; teacher.Email = teacherModel.Email; teacher.Password = teacherModel.Password; teacher.LName = teacherModel.LName; teacher.Gender = teacherModel.Gender; teacher.Street = teacherModel.Street; teacher.City = teacherModel.City; teacher.Phone = teacherModel.Phone; teacher.Age = teacherModel.Age; context.SaveChanges(); } }
public static void ChangeAttendenceState(AttendenceViewModel attendenceViewModel) { using (var context = new FinalSchool()) { var studentAtt = context.Students.FirstOrDefault(x => x.StudentId == attendenceViewModel.StudentSNN); var courseAtt = context.Courses.FirstOrDefault(x => x.Name == attendenceViewModel.CourseName); var teacher = context.Teachers.FirstOrDefault(x => x.FName == attendenceViewModel.TeacherName); var session = new Session { Course = courseAtt, CourseId = courseAtt.CourseId, StartDate = DateTime.Now, Teacher = teacher, TeacherId = teacher.TeacherId, }; context.Sessions.Add(session); context.SaveChanges(); var attendence = new Attendence() { Student = studentAtt, StudentId = studentAtt.StudentId, IsAttended = attendenceViewModel.IsAttended, Session = session, SessionId = session.SessionId, }; context.Attendences.Add(attendence); context.SaveChanges(); } }
public int Post(Login login) { using (var context = new FinalSchool()) { var _student = context.Students.FirstOrDefault(x => x.StudentId == login.SNN && x.Password == login.Password); if (_student != null) { var studentView = StudentService.GetOne(_student.StudentId); return(1); } var _teacher = context.Teachers.FirstOrDefault(x => x.TeacherId == login.SNN && x.Password == login.Password); if (_teacher != null) { return(2); } var _parent = context.Parents.FirstOrDefault(x => x.ParentSNN == login.SNN && x.Password == login.Password); if (_parent != null) { return(3); } var _admin = context.Admins.FirstOrDefault(x => x.SNN == login.SNN && x.Password == login.Password); if (_admin != null) { return(4); } throw new HttpResponseException(HttpStatusCode.Unauthorized); } }
public static IEnumerable <ResultViewModel> GetToCourse(string courseName, string studentId) { using (var context = new FinalSchool()) { var course = context.Courses.FirstOrDefault(x => x.Name == courseName); var courseExamsResults = from exam in context.Exams join cour in context.Courses on exam.CourseId equals cour.CourseId where cour.CourseId == course.CourseId join result in context.Results on exam.ExamId equals result.ExamId select result; var studentResults = from student in context.Students join result in courseExamsResults on student.StudentId equals result.StudentId where student.StudentId == studentId select result; var resultToStudentViewList = new List <ResultViewModel>(); foreach (var item in studentResults) { var result = new ResultViewModel { ExamId = item.ExamId, StudentId = item.StudentId, StudentResult = item.StudentResult }; resultToStudentViewList.Add(result); } return(resultToStudentViewList); } }
public static void PostListOfAttendenceState(List <AttendenceViewModel> attendenceViewModel) { using (var context = new FinalSchool()) { var CN = attendenceViewModel[0].CourseName; var courseAtt = context.Courses.FirstOrDefault(x => x.Name == CN); var te = attendenceViewModel[0].TeacherSNN; Teacher teacher = context.Teachers.FirstOrDefault(x => x.TeacherId == te); var session = new Session { CourseId = courseAtt.CourseId, StartDate = DateTime.Now, TeacherId = teacher.TeacherId, }; context.Sessions.Add(session); context.SaveChanges(); foreach (var item in attendenceViewModel) { var attendence = new Attendence() { StudentId = item.StudentSNN, IsAttended = item.IsAttended, SessionId = session.SessionId, }; context.Attendences.Add(attendence); } context.SaveChanges(); } }
public static IEnumerable <AttendenceViewModel> GetAttendencesToStudent(string snn) { using (var context = new FinalSchool()) { var student = context.Students.Find(snn); var studentAttendences = (from stu in context.Students join attend in context.Attendences on stu.StudentId equals attend.StudentId where stu.StudentId == snn select attend) .ToList(); var studentAttendViewList = new List <AttendenceViewModel>(); foreach (var item in studentAttendences) { var studentAttendView = new AttendenceViewModel() { StudentSNN = item.StudentId, CourseName = item.Session.Course.Name, IsAttended = item.IsAttended, SessionDate = item.Session.StartDate, StudentName = item.Student.FName + ' ' + item.Student.FName, TeacherName = item.Session.Teacher.FName + ' ' + item.Session.Teacher.LName, }; studentAttendViewList.Add(studentAttendView); } return(studentAttendViewList); } }
public static string Create(StudentViewModel studentViewModel) { using (var context = new FinalSchool()) { var classRoomStudent = context.ClassRooms.FirstOrDefault(x => x.Name == studentViewModel.ClassName); var stulevel = context.Levels.FirstOrDefault(x => x.Name == studentViewModel.LevelName); var studentParent = new Parent() { FName = studentViewModel.ParentFName, LName = studentViewModel.ParentLName, ParentSNN = studentViewModel.ParentSNN, }; var student = new Student() { Age = studentViewModel.Age, City = studentViewModel.City, Email = studentViewModel.Email, FName = studentViewModel.FName, Gender = studentViewModel.Gender, LName = studentViewModel.LName, Street = studentViewModel.Street, StudentId = studentViewModel.StudentSNN, Phone = studentViewModel.Phone, Parent = studentParent, ClassRoom = classRoomStudent, Password = studentViewModel.Password }; student.ClassRoom.Level = stulevel; context.Students.Add(student); context.SaveChanges(); return(student.StudentId); } }
public static TeacherViewModel GetOne(string id) { using (var context = new FinalSchool()) { var teacher = context.Teachers.Find(id); var courses = (from course in context.Courses join techcourse in context.TeacherCourses on course.CourseId equals techcourse.CourseId join teach in context.Teachers on techcourse.TeacherId equals teach.TeacherId where teach.TeacherId == id select course.Name).ToList(); var teacherModel = new TeacherViewModel() { TeacherSNN = teacher.TeacherId, FName = teacher.FName, Age = teacher.Age, City = teacher.City, Street = teacher.Street, LName = teacher.LName, Email = teacher.Email, Gender = teacher.Gender, Password = teacher.Password, Phone = teacher.Phone, CourseName = courses, }; return(teacherModel); } }
///// ///Additions /*to get Students in a specific class in a specific course*/ public static IEnumerable <StudentViewModel> GetStudentsToSepcificClass(string className) { using (var context = new FinalSchool()) { var studentsViewList = new List <StudentViewModel>(); var studentsClass = context.Students.Where(x => x.ClassRoom.Name == className).ToList(); foreach (var item in studentsClass) { var studentView = new StudentViewModel { Age = item.Age, City = item.City, Email = item.Email, FName = item.FName, Gender = item.Gender, LName = item.LName, Phone = item.Phone, Street = item.Street, StudentSNN = item.StudentId, ClassName = item.ClassRoom.Name, LevelName = item.ClassRoom.Level.Name, ParentFName = item.Parent.FName, ParentLName = item.Parent.LName, Password = item.Password, ParentSNN = item.Parent.ParentSNN, }; studentsViewList.Add(studentView); } return(studentsViewList); } }
public static StudentViewModel GetOne(string id) { using (var context = new FinalSchool()) { var student = context.Students.Find(id); var studentView = new StudentViewModel() { Password = student.Password, Age = student.Age, City = student.City, Email = student.Email, FName = student.FName, Gender = student.Gender, LName = student.LName, Phone = student.Phone, Street = student.Street, StudentSNN = student.StudentId, ClassName = student.ClassRoom.Name, LevelName = student.ClassRoom.Level.Name, ParentFName = student.Parent.FName, ParentLName = student.Parent.LName, ParentSNN = student.Parent.ParentSNN }; return(studentView); } }
public static IEnumerable <StudentViewModel> GetAll() { using (var context = new FinalSchool()) { var studentViewList = new List <StudentViewModel>(); foreach (var item in context.Students.ToList()) { var studentView = new StudentViewModel() { Password = item.Password, Age = item.Age, City = item.City, Email = item.Email, FName = item.FName, Gender = item.Gender, LName = item.LName, Phone = item.Phone, Street = item.Street, ClassName = item.ClassRoom.Name, StudentSNN = item.StudentId, LevelName = item.ClassRoom.Level.Name, ParentFName = item.Parent.FName, ParentLName = item.Parent.LName, ParentSNN = item.Parent.ParentSNN, }; studentViewList.Add(studentView); } return(studentViewList); } }
public static string Edit(StudentViewModel studentViewModel) { using (var context = new FinalSchool()) { var classroom = context.ClassRooms.FirstOrDefault(x => x.Name == studentViewModel.ClassName); var level = context.Levels.FirstOrDefault(x => x.Name == studentViewModel.LevelName); var student = context.Students.FirstOrDefault(ww => ww.StudentId == studentViewModel.StudentSNN); student.Age = studentViewModel.Age; student.City = studentViewModel.City; student.Email = studentViewModel.Email; student.FName = studentViewModel.FName; student.Gender = studentViewModel.Gender; student.LName = studentViewModel.LName; student.Street = studentViewModel.Street; student.StudentId = studentViewModel.StudentSNN; student.Phone = studentViewModel.Phone; student.ClassRoom = classroom; student.ClassRoom.Level = level; student.Password = studentViewModel.Password; var parent = new Parent() { FName = studentViewModel.ParentFName, LName = studentViewModel.LName, }; context.Parents.Add(parent); context.SaveChanges(); student.Parent = parent; context.SaveChanges(); return(student.StudentId); } }
public static void PostOne(TeacherViewModel teacherModel) { using (var context = new FinalSchool()) { var teacher = new Teacher() { TeacherId = teacherModel.TeacherSNN, FName = teacherModel.FName, Age = teacherModel.Age, City = teacherModel.City, Street = teacherModel.Street, LName = teacherModel.LName, Email = teacherModel.Email, Gender = teacherModel.Gender, Password = teacherModel.Password, Phone = teacherModel.Phone, }; context.Teachers.Add(teacher); foreach (var item in teacherModel.CourseName) { var CourseId = context.Courses.FirstOrDefault(w => w.Name == item).CourseId; var teacherCourse = new TeacherCourse() { TeacherId = teacher.TeacherId, CourseId = CourseId }; context.TeacherCourses.Add(teacherCourse); } context.SaveChanges(); } }
public static void Delete(string id) { using (var context = new FinalSchool()) { context.Students.Remove(context.Students.Find(id)); context.SaveChanges(); } }
public static void DeleteOne(string id) { using (var context = new FinalSchool()) { var teacher = context.Teachers.Find(id); context.Teachers.Remove(teacher); context.SaveChanges(); } }
public static void DeleteOne(int id) { using (var context = new FinalSchool()) { var level = context.Levels.Find(id); context.Levels.Remove(level); context.SaveChanges(); } }
public static void DeleteOne(int id) { using (var context = new FinalSchool()) { var classRoom = context.ClassRooms.Find(id); context.ClassRooms.Remove(classRoom); context.SaveChanges(); } }
public static void DeleteOne(int id) { using (var context = new FinalSchool()) { var exam = context.Exams.Find(id); context.Exams.Remove(exam); context.SaveChanges(); } }
public static void PutOne(int id, LevelViewModel levelModel) { using (var context = new FinalSchool()) { var level = context.Levels.Find(id); level.Name = levelModel.Name; context.SaveChanges(); } }
public static void PutOne(CourseViewModel courseViewModel) { using (var context = new FinalSchool()) { var course = context.Courses.FirstOrDefault(w => w.CourseId == courseViewModel.CourseId); var level = context.Levels.FirstOrDefault(x => x.Name == courseViewModel.LevelName); course.Name = courseViewModel.Name; course.LevelId = level.LevelId; context.SaveChanges(); } }
public static LevelViewModel GetOne(int id) { using (var context = new FinalSchool()) { var level = context.Levels.Find(id); var levelModel = new LevelViewModel() { Name = level.Name }; return(levelModel); } }
public static void PutOne(ClassRoomViewModel classRoomModel) { using (var context = new FinalSchool()) { var classRoom = context.ClassRooms.Find(classRoomModel.ClassId); classRoom.Name = classRoomModel.Name; // classRoom.LevelId = classRoomModel.LevelId; classRoom.ClassRoomId = classRoomModel.ClassId; classRoom.Level.Name = classRoomModel.LevelName; context.SaveChanges(); } }
public static void PutOne(ExamViewModel examViewModel) { using (var context = new FinalSchool()) { var courseId = context.Courses.FirstOrDefault(x => x.Name == examViewModel.CourseName).CourseId; var exam = context.Exams.Find(examViewModel.ExamId); exam.ExamName = examViewModel.ExamName; exam.CourseId = courseId; exam.MaxExamDegree = examViewModel.MaxExamDegree; context.SaveChanges(); } }
public static int GetLevelByName(string levelName) { using (var context = new FinalSchool()) { var level = context.Levels.FirstOrDefault(x => x.Name == levelName); var levelview = new LevelViewModel() { Name = level.Name, LevelId = level.LevelId, }; return(levelview.LevelId); } }
public static int PostOne(LevelViewModel levelModel) { using (var context = new FinalSchool()) { var level = new Level() { Name = levelModel.Name, LevelId = levelModel.LevelId }; context.Levels.Add(level); context.SaveChanges(); return(level.LevelId); } }
public static int DeleteOne(int id) { using (var context = new FinalSchool()) { var course = context.Courses.Find(id); if (course != null) { context.Courses.Remove(course); context.SaveChanges(); } return(course.CourseId); } }
public static ExamViewModel GetOne(int id) { using (var context = new FinalSchool()) { var exam = context.Exams.Find(id); var examModel = new ExamViewModel() { ExamId = exam.ExamId, ExamName = exam.ExamName, CourseName = exam.Course.Name, MaxExamDegree = exam.MaxExamDegree }; return(examModel); } }
public static CourseViewModel GetOne(int id) { using (var context = new FinalSchool()) { var course = context.Courses.Find(id); var level = context.Levels.FirstOrDefault(x => x.LevelId == course.LevelId); var courseView = new CourseViewModel() { CourseId = course.CourseId, Name = course.Name, LevelName = level.Name, }; return(courseView); } }
public static ClassRoomViewModel GetOne(int id) { using (var context = new FinalSchool()) { var classRoom = context.ClassRooms.Find(id); var classRoomModel = new ClassRoomViewModel() { Name = classRoom.Name, // LevelId = classRoom.LevelId, ClassId = classRoom.ClassRoomId, LevelName = classRoom.Level.Name, }; return(classRoomModel); } }