public List <string> LoadCreateClassPage(string userName) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { return((from t in db.Teachers where t.UserName == userName join tc in db.TeacherCategories on t.Id equals tc.TeacherId select tc.Category).ToList()); } catch (Exception ex) { throw ex; }; }
public bool PostMessage(Message data) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { var query = from m in db.Messages where m.ClassId == data.ClassId select m; if (query.Any()) { db.Messages.Remove(query.FirstOrDefault()); } ; data.Date = DateTime.Now; db.Messages.Add(data); db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; }; }
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 bool AddLessons(ClassGroupDTO data) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { foreach (var id in data.lessonIDs) { var query = from lc in db.LessonsToClasses where lc.ClassId == data.Id && lc.LessonId == id select lc; query.First().IsActive = true; } ; 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 StudentToClassesDTO GetStudentsNamesByClassGroup(int classGroupId) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { var query = from sg in db.StudentsToClasses join s in db.Students on sg.StudentId equals s.Id join c in db.ClassGroups on sg.ClassId equals c.Id where sg.ClassId == classGroupId select new { c.Category, c.Grade, s.Name } into result group result by new { result.Category, result.Grade }; StudentToClassesDTO studentsNamesInClassGroup = new StudentToClassesDTO(query.First().Key.Category, query.First().Key.Grade); foreach (var student in query.First()) { studentsNamesInClassGroup.Students.Add(student.Name); } return(studentsNamesInClassGroup); } catch (InvalidOperationException ex) { if (ex.Message == "Sequence contains no elements") { return(new StudentToClassesDTO("No such class group ot the class is empty", 0)); } else { return(new StudentToClassesDTO("An error accured", 0)); } }; }
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 <ExamQuestionsDTO> GetExamQuestions(int classId) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { var myClass = (from c in db.ClassGroups where c.Id == classId select new { c.Grade, c.Category }).First(); var query = from q in db.ExamQuestions where q.Category == myClass.Category && q.Grade == myClass.Grade select new ExamQuestionsDTO { Id = q.Id, Category = q.Category, Grade = q.Grade, Question = q.Question, AnswerA = q.AnswerA, AnswerB = q.AnswerB, AnswerC = q.AnswerC, AnswerD = q.AnswerD, RightAnswer = q.RightAnswer }; return(query.ToList()); } catch (Exception ex) { throw ex; }; }
public bool CreateExam(ExamDTO data) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { var query = from e in db.Exams where e.ClassId == data.ClassId select e; foreach (var rec in query) { db.Exams.Remove(rec); } ; foreach (var id in data.QuestionIDs) { db.Exams.Add(new Exam { ClassId = data.ClassId, QuestionId = id }); } ; db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; }; }
public ClassGroupDTO LoadAddLessonsPage(string category, int grade) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); try { ClassGroupDTO classGroup = new ClassGroupDTO(); classGroup.lessons = new List <LessonDTO>(); classGroup.lessons = (from l in db.Lessons where l.Category == category && l.Grade == grade orderby l.SeqNum select new LessonDTO { Id = l.Id, Name = l.Name, Description = l.Description, SeqNum = l.SeqNum }).ToList(); return(classGroup); } 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 LessonStats LessonStats(int classGroupId, int lessonNum) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); LessonStats lStats = new LessonStats { QLDist = new List <QResLessonDistribution>(), Students = new List <PersonDTO>() }; try { //Get all the records of the results in the lesson var results = from lc in db.LessonsToClasses where lc.ClassId == classGroupId join l in db.Lessons on lc.LessonId equals l.Id where l.SeqNum == lessonNum join rl in db.ResultInLessons on l.Id equals rl.LessonId join sc in db.StudentsToClasses on lc.ClassId equals sc.ClassId where sc.StudentId == rl.StudentId select rl; if (results.Any()) { //Get max result by student var studentsBestResults = from r in results group r by r.StudentId into stdRes select stdRes.Max(x => x.Result); //Count how many students achieved PASS result lStats.StFinished = 0; foreach (var stdRes in studentsBestResults) { if (stdRes >= StudyController.MIN_RES_TO_PASS) { lStats.StFinished++; } ; } ; //Getting questions results int lessonId = GetLessonId(lessonNum, classGroupId); var query = from rq in db.ResultInQuestions where rq.LessonId == lessonId group rq by rq.QuestionNum into qRes select qRes; foreach (var question in query) { lStats.QLDist.Add(new QResLessonDistribution { QNum = question.Key, RightCount = 0, WrongCount = 0 }); foreach (var res in question) { if (res.Result == true) { lStats.QLDist.Last().RightCount++; } else { lStats.QLDist.Last().WrongCount++; }; } ; } ; //Adding empty question objects to fill up the list to 10 for (int i = lStats.QLDist.Count; i < NUM_OF_QUESTIONS_IN_LESSON; i++) { lStats.QLDist.Add(new QResLessonDistribution() { QNum = i + 1, RightCount = 0, WrongCount = 0 }); } ; lStats.StTried = studentsBestResults.Count(); lStats.FinishedOfTriedPercent = (double)lStats.StFinished / (double)lStats.StTried; lStats.AvgBestRes = studentsBestResults.Average(); lStats.AvgRes = results.Average(x => x.Result); } else { lStats.SetDefaults(); }; //Build students list lStats.Students = GetStudentsList(classGroupId); return(lStats); } 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); }
public List <QResLessonDistribution> LessonInStudentStats(int classGroupId, int studentId, int lessonNum) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); List <QResLessonDistribution> qDist = new List <QResLessonDistribution>(); try { int lessonId = GetLessonId(lessonNum, classGroupId); var results = from rq in db.ResultInQuestions where rq.LessonId == lessonId && rq.StudentId == studentId group rq by rq.QuestionNum into qRes select qRes; if (results.Any()) { foreach (var lesson in results) { qDist.Add(new QResLessonDistribution { QNum = lesson.Key, RightCount = 0, WrongCount = 0 }); foreach (var res in lesson) { if (res.Result == true) { qDist.Last().RightCount++; } else { qDist.Last().WrongCount++; }; } } ; //Adding empty question objects to fill up the list to 10 for (int i = qDist.Count; i < NUM_OF_QUESTIONS_IN_LESSON; i++) { qDist.Add(new QResLessonDistribution() { QNum = i + 1, RightCount = 0, WrongCount = 0 }); } ; } ; return(qDist); } catch (Exception ex) { throw ex; }; }
public StudentStats StudentStats(int classGroupId, int studentId) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); StudentStats sStats = new StudentStats { RDist = new List <LessonResDistribution>() }; try { //Get all the records of the results in the class grouped by lesson, then grouped by 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()) { /*------------------------------------------------------------------------------------------ * Lesson Results Distribution *------------------------------------------------------------------------------------------*/ //Loop through each lesson and assign results foreach (var lesson in results) { sStats.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 = sStats.RDist.Count; i < NUM_OF_LESSONS_IN_CLASS; i++) { sStats.RDist.Add(new LessonResDistribution() { LNum = i + 1, AvgRes = 0, BestRes = 0 }); } ; /*------------------------------------------------------------------------------------------- * Course average result *------------------------------------------------------------------------------------------*/ sStats.AvgRes = (from pc in db.ProgressInClasses where pc.ClassId == classGroupId && pc.StudentId == studentId select pc.Result).FirstOrDefault(); } else { sStats.AvgRes = 0; }; return(sStats); } 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 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 ClassStats ClassStats(int classGroupId) { try { LoginController.checkOnAccess(this.Request.Headers); } catch (Exception ex) { throw ex; }; var db = new DBModel(); ClassStats cStats = new ClassStats { RDist = new List <LessonResDistribution>(), ADist = new List <LessonAttempts>() }; try { //Get all the records of the results in the class grouped by lesson, then grouped by 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 join sc in db.StudentsToClasses on lc.ClassId equals sc.ClassId where sc.StudentId == rl.StudentId group rl by l.SeqNum into lRes select new { lRes.Key, studentsRes = from lrg in lRes group lrg by lrg.StudentId into studRes select studRes }; if (results.Any()) { List <double> avgRes; List <double> avgBestRes; /*------------------------------------------------------------------------------------------ * Lesson Results Distribution *------------------------------------------------------------------------------------------*/ //Loop through each lesson foreach (var lesson in results) { avgRes = new List <double>(); avgBestRes = new List <double>(); //Create lesson object cStats.RDist.Add(new LessonResDistribution { LNum = lesson.Key }); //Loop through each student's results in the lesson and calc his average and max results foreach (var res in lesson.studentsRes) { avgRes.Add(res.Average(x => x.Result)); avgBestRes.Add(res.Max(x => x.Result)); } ; //Calc overall 'average' and 'average best' results cStats.RDist.Last().AvgRes = avgRes.Average(); cStats.RDist.Last().AvgBestRes = avgBestRes.Average(); } ; //Adding empty lessons objects to fill up the list to 10 for (int i = cStats.RDist.Count; i < NUM_OF_LESSONS_IN_CLASS; i++) { cStats.RDist.Add(new LessonResDistribution() { LNum = i + 1, AvgRes = 0, AvgBestRes = 0 }); } ; /*------------------------------------------------------------------------------------------ * Lesson attempts and completion distribution *------------------------------------------------------------------------------------------*/ int passed; //Loop through each lesson foreach (var lesson in results) { passed = 0; //Create lesson object cStats.ADist.Add(new LessonAttempts { LNum = lesson.Key }); //Check each student's results to see if he passed the lesson foreach (var res in lesson.studentsRes) { if (res.Max(x => x.Result >= StudyController.MIN_RES_TO_PASS)) { passed++; } ; } ; cStats.ADist.Last().StFinished = passed; cStats.ADist.Last().StTried = lesson.studentsRes.Count(); } ; //Adding empty lessons objects to fill up the list to 4 for (int i = cStats.ADist.Count; i < NUM_OF_LESSONS_IN_CLASS; i++) { cStats.ADist.Add(new LessonAttempts() { LNum = i + 1, StFinished = 0, StTried = 0 }); } ; /*------------------------------------------------------------------------------------------- * Course average result *------------------------------------------------------------------------------------------*/ var query = from pc in db.ProgressInClasses where pc.ClassId == classGroupId select pc.Result; if (query.Any()) { cStats.AvgRes = (double)query.Average(); } else { cStats.AvgRes = 0; }; } else { cStats.AvgRes = 0; }; return(cStats); } catch (Exception ex) { throw ex; }; }