public bool JoinClass([FromBody] UserDetails data) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); int studentId = LoginController.GetUserID(data.userName, "student"); try { db.StudentsToClasses.Add(new StudentToClasses { ClassId = data.classId, StudentId = studentId }); db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; }; }
public List <LessonResDistribution> LoadPersonalGraph(int classGroupId, string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); List <LessonResDistribution> RDist = new List <LessonResDistribution>(); try { int studentId = LoginController.GetUserID(userName, "student"); var results = from lc in db.LessonsToClasses where lc.ClassId == classGroupId join l in db.Lessons on lc.LessonId equals l.Id join rl in db.ResultInLessons on l.Id equals rl.LessonId where rl.StudentId == studentId group rl by l.SeqNum into lRes select lRes; if (results.Any()) { //Loop through each lesson and assign results foreach (var lesson in results) { RDist.Add(new LessonResDistribution { LNum = lesson.Key, AvgRes = lesson.Average(x => x.Result), BestRes = lesson.Max(x => x.Result) }); } ; //Adding empty lessons objects to fill up the list to 4 for (int i = RDist.Count; i < NUM_OF_LESSONS_IN_CLASS; i++) { RDist.Add(new LessonResDistribution() { LNum = i + 1, AvgRes = 0, BestRes = 0 }); } ; } return(RDist); } catch (Exception ex) { throw ex; }; }
public TeacherProfile TeacherProfilePage(string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; TeacherProfile profile = new TeacherProfile(); profile.categories = new List <string>(); profile.classes = new List <SCourses>(); int teacherId = LoginController.GetUserID(userName, "teacher"); var db = new DBModel(); try { //Subjects list profile.categories = (from tcat in db.TeacherCategories where tcat.TeacherId == teacherId select tcat.Category).ToList(); //Classes list (CLassID, NAME, GRADE,) profile.classes = (from tcl in db.TeachersToClasses where tcl.TeacherId == teacherId join cg in db.ClassGroups on tcl.ClassId equals cg.Id orderby cg.Category, cg.Grade select new SCourses { CourseId = cg.Id, Category = cg.Category, Grade = cg.Grade }).ToList(); profile.Picture = (from u in db.Users where u.UserName == userName select u.Picture).First(); } catch (Exception ex) { throw ex; }; return(profile); }
public List <ClassGroupDTO> JoinClass(string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); List <ClassGroupDTO> classesToJoin = new List <ClassGroupDTO>(); List <ClassGroupDTO> tempList = new List <ClassGroupDTO>(); try { int schoolId = GetSchoolId(userName, "student"); int grade = GetGrade(userName); int studentId = LoginController.GetUserID(userName, "student"); //Get list of all classes in the student's school and grade tempList = (from c in db.ClassGroups where c.SchoolId == schoolId && c.Grade == grade join tc in db.TeachersToClasses on c.Id equals tc.ClassId join t in db.Teachers on tc.TeacherId equals t.Id select new ClassGroupDTO { Id = c.Id, Category = c.Category, Teacher = t.Name }).ToList(); classesToJoin = tempList.ToList(); //Get list of all classes that the student is registered for var query2 = (from sc in db.StudentsToClasses where sc.StudentId == studentId join c in db.ClassGroups on sc.ClassId equals c.Id select c.Category).ToList(); int i = 0; //index diference when items deleted from the main list foreach (var item in tempList) { foreach (var item2 in query2) { if (item.Category == item2) { classesToJoin.RemoveAt(tempList.IndexOf(item) - i); i++; break; } } ; } ; return(classesToJoin); } catch (Exception ex) { throw ex; }; }
public bool CreateClass(ClassGroupDTO data) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { int schoolId = GetSchoolId(data.TeacherUserName, "teacher"); //Create new ClassGroup record db.ClassGroups.Add(new ClassGroup { Category = data.Category, Grade = data.Grade, SchoolId = schoolId }); db.SaveChanges(); int classId = (from c in db.ClassGroups where c.Category == data.Category && c.Grade == data.Grade && c.SchoolId == schoolId orderby c.Id descending select c.Id).First(); //Assign the teacher to the class by creating new Teacher to Class record int teacherId = LoginController.GetUserID(data.TeacherUserName, "teacher"); db.TeachersToClasses.Add(new TeacherToClasses { ClassId = classId, TeacherId = teacherId }); //Get the list of all lessons of the category for the grade var query = from l in db.Lessons where l.Category == data.Category && l.Grade == data.Grade select l.Id; //Add all the lessons of the category for the grade to the new class group foreach (var lessonId in query) { bool isActive; if (data.lessonIDs.Exists(x => x == lessonId)) { isActive = true; } else { isActive = false; }; db.LessonsToClasses.Add(new LessonsToClass { ClassId = classId, LessonId = lessonId, IsActive = isActive }); } ; db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; }; }
public ClassGroupDTO LoadClassPage(int courseId, string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { ClassGroupDTO classGroup = (from c in db.ClassGroups where c.Id == courseId select new ClassGroupDTO { Category = c.Category, Grade = c.Grade }).First(); classGroup.Teacher = (from tc in db.TeachersToClasses where tc.ClassId == courseId join t in db.Teachers on tc.TeacherId equals t.Id select t.Name).First(); classGroup.numOfStudents = (from sc in db.StudentsToClasses where sc.ClassId == courseId select sc).Count(); classGroup.message = (from m in db.Messages where m.ClassId == courseId select new MessageDTO { Text = m.Text, Date = m.Date }).FirstOrDefault(); classGroup.lessons = new List <LessonDTO>(); classGroup.lessons = (from lc in db.LessonsToClasses where lc.ClassId == courseId join l in db.Lessons on lc.LessonId equals l.Id orderby l.SeqNum select new LessonDTO { Id = l.Id, Name = l.Name, IsActive = lc.IsActive, Description = l.Description, SeqNum = l.SeqNum }).ToList(); classGroup.ExamExists = (from e in db.Exams where e.ClassId == courseId select e).Any(); string role = (from u in db.Users where u.UserName == userName select u.Role).FirstOrDefault(); if (role == "student") { int studentId = LoginController.GetUserID(userName, "student"); foreach (var lesson in classGroup.lessons) { lesson.Result = (from rl in db.ResultInLessons where rl.StudentId == studentId && rl.LessonId == lesson.Id group rl by rl.LessonId into lessonRes select lessonRes.Max(x => x.Result)).FirstOrDefault(); if (lesson.Result >= MIN_RES_TO_PASS) { lesson.IsPassed = true; } else { lesson.IsPassed = false; }; } ; } ; return(classGroup); } catch (Exception ex) { throw ex; }; }
public StudentProfile StudentProfilePage(string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; StudentProfile profile = new StudentProfile { sCourses = new List <SCourses>(), sClasses = new List <SClasses>(), Badges = new bool[] { false, false, false, false, false, false, false, false, false } }; int studentId = LoginController.GetUserID(userName, "student"); var db = new DBModel(); try { //Courses tab var query = from sc in db.StudentsToClasses where sc.StudentId == studentId join c in db.ClassGroups on sc.ClassId equals c.Id select c; foreach (var item in query) { profile.sCourses.Add(new SCourses { CourseId = item.Id, Category = item.Category, Grade = item.Grade }); } ; var query2 = from sc in db.StudentsToClasses join c in db.ClassGroups on sc.ClassId equals c.Id join pc in db.ProgressInClasses on c.Id equals pc.ClassId where sc.StudentId == studentId && pc.StudentId == studentId orderby c.Grade descending, pc.Result select pc; foreach (var item in query2) { foreach (var item2 in profile.sCourses) { if (item.ClassId == item2.CourseId) { item2.Result = item.Result; break; } ; } ; } ; //Clases and assignments tab var query3 = from sc in db.StudentsToClasses join lc in db.LessonsToClasses on sc.ClassId equals lc.ClassId where sc.StudentId == studentId && lc.IsActive == true join l in db.Lessons on lc.LessonId equals l.Id orderby l.SeqNum descending select new { lc, l }; foreach (var item in query3.ToList()) { var query4 = from rl in db.ResultInLessons where rl.StudentId == studentId && rl.LessonId == item.l.Id orderby rl.Result descending select rl.Result; profile.sClasses.Add(new SClasses { CourseId = item.lc.ClassId, Category = item.l.Category, LessonNum = item.l.SeqNum, Name = item.l.Name, Description = item.l.Description, Attempts = query4.Count(), BestRes = query4.FirstOrDefault() }); } ; profile.sClasses.OrderByDescending(x => x.LessonNum).OrderBy(y => y.Attempts); //Achievements tab profile.qCorrAnswered = StatisticsController.QCorrAnswered(studentId); profile.lessonsCompleted = StatisticsController.LessonsCompleted(studentId); var query5 = from pc in db.ProgressInClasses where pc.StudentId == studentId && pc.Result != 0 orderby pc.Result descending select pc; //If a record for the student in the class exists if (query5.Any()) { profile.avgCourseRes = query5.Average(x => x.Result); profile.bestCourseRes = query5.First().Result; } //If no previous record exists else { profile.avgCourseRes = profile.bestCourseRes = 0; }; profile.Picture = (from u in db.Users where u.UserName == userName select u.Picture).First(); //Badges //---1 var tempQuery = (from rq in db.ResultInQuestions where rq.StudentId == studentId && rq.Result group rq by new { rq.LessonId, rq.QuestionNum } into question select question).Count(); profile.Badges[0] = (tempQuery >= QUESTIONS_CORRECT_ANSWER) ? true : false; //--2 var tempQuery2 = from rl in db.ResultInLessons where rl.StudentId == studentId join lc in db.LessonsToClasses on rl.LessonId equals lc.LessonId join c in db.ClassGroups on lc.ClassId equals c.Id where c.Category == "Math" group rl by rl.LessonId into lesRes select lesRes; if (tempQuery2.Count() == NUM_OF_LESSONS_IN_CLASS) { foreach (var les in tempQuery2) { profile.Badges[1] = (les.Max(x => x.Result) >= StudyController.MIN_RES_TO_PASS) ? true : false; } ; } ; //--3 tempQuery2 = from rl in db.ResultInLessons where rl.StudentId == studentId join lc in db.LessonsToClasses on rl.LessonId equals lc.LessonId join c in db.ClassGroups on lc.ClassId equals c.Id where c.Category == "Science" group rl by rl.LessonId into lesRes select lesRes; if (tempQuery2.Count() == NUM_OF_LESSONS_IN_CLASS) { foreach (var les in tempQuery2) { profile.Badges[2] = (les.Max(x => x.Result) >= StudyController.MIN_RES_TO_PASS) ? true : false; } ; } ; //--4,5,6,9 profile.Badges[3] = profile.Badges[4] = profile.Badges[5] = profile.Badges[8] = false; //--7 var tempQuery3 = from rl in db.ResultInLessons where rl.StudentId == studentId join lc in db.LessonsToClasses on rl.LessonId equals lc.LessonId group new { lc, rl } by lc.ClassId into classRes select classRes; foreach (var classR in tempQuery3) { if (classR.Min(x => x.rl.Result) >= StudyController.MIN_RES_TO_PASS && classR.Select(x => x.lc.LessonId).Distinct().Count() == NUM_OF_LESSONS_IN_CLASS) { profile.Badges[6] = true; break; } ; } ; //--8 var tempQuery4 = from rl in db.ResultInLessons where rl.StudentId == studentId join lc in db.LessonsToClasses on rl.LessonId equals lc.LessonId group new { lc, rl } by lc.ClassId into classRes select classRes; int temp = 0; foreach (var classR in tempQuery4) { if (classR.Average(x => x.rl.Result) == MAX_RES && classR.Select(x => x.lc.LessonId).Distinct().Count() == NUM_OF_LESSONS_IN_CLASS) { temp++; } ; } ; if (temp >= BADGE_8_REQ) { profile.Badges[7] = true; } ; } catch (Exception ex) { throw ex; }; return(profile); }