public JsonResult GetStudentQuizzes(int id) { var result = new List <QuizInfo>(); var quizzes = _repository.Get <Quiz>(); var userQuizzes = _repository.Get <QuizPass>(qp => qp.UserId == id); var quizBlocks = _repository.Get <QuizBlock>(); var quizQuestions = _repository.Get <QuizQuestion>(); var questions = _repository.Get <Question>(); var questionTypes = _repository.Get <QuestionType>(); var quizPasses = _repository.Get <QuizPass>(); var quizPassScores = _repository.Get <QuizPassScore>(); var autoQuestions = from qz in quizzes join qb in quizBlocks on qz.Id equals qb.QuizId join qq in quizQuestions on qb.Id equals qq.QuizBlockId join q in questions on qq.QuestionId equals q.Id join qt in questionTypes on q.QuestionTypeId equals qt.Id where qt.IsAutomatic group new { qz, qt } by qz.Id into grouped select new QuestionsAuto { QuizId = grouped.Key, IsAutomatic = grouped.Select(q => q.qt.IsAutomatic).Count() }; var passed = from q in quizzes join uq in userQuizzes on q.Id equals uq.QuizId join qb in quizBlocks on q.Id equals qb.QuizId join aq in autoQuestions on q.Id equals aq.QuizId join qps in quizPassScores on uq.Id equals qps.QuizPassId into temp from t in temp.DefaultIfEmpty() where uq.FinishTime != null select new QuizInfo { id = uq.Id, name = q.Name, state = t != null ? "Passed" : "In verification", questions = (int)qb.QuestionCount, verificationType = QuizInfo.SetVerificationType(aq.IsAutomatic, (int)qb.QuestionCount), otherDetails = q.Description, date = uq.FinishTime }; foreach (var item in passed) { result.Add(item); } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetStudentQuizzesOld(int id) { var passedQuizes = new List <QuizInfo>(); var result = new List <QuizInfo>(); var types = new List <object>(); var quizzes = _repository.Get <Quiz>(); var userQuizzes = _repository.Get <QuizPass>(qp => qp.UserId == id); var quizBlocks = _repository.Get <QuizBlock>(); var quizQuestions = _repository.Get <QuizQuestion>(); var questions = _repository.Get <Question>(); var questionTypes = _repository.Get <QuestionType>(); var quizStates = _repository.Get <QuizState>(); var quizPasses = _repository.Get <QuizPass>(); var quizPassScores = _repository.Get <QuizPassScore>(); var autoQuestions = from qz in quizzes join qb in quizBlocks on qz.Id equals qb.QuizId join qq in quizQuestions on qb.Id equals qq.QuizBlockId join q in questions on qq.QuestionId equals q.Id join qt in questionTypes on q.QuestionTypeId equals qt.Id where qt.IsAutomatic group new { qz, qt } by qz.Id into grouped select new QuestionsAuto { QuizId = grouped.Key, IsAutomatic = grouped.Select(q => q.qt.IsAutomatic).Count() }; foreach (var item in autoQuestions) { types.Add(item); } var passed = from q in quizzes join uq in userQuizzes on q.Id equals uq.QuizId join qb in quizBlocks on q.Id equals qb.QuizId join aq in autoQuestions on q.Id equals aq.QuizId join qp in quizPasses on q.Id equals qp.QuizId join qps in quizPassScores on qp.Id equals qps.QuizPassId where uq.UserId == id select new QuizInfo { id = uq.Id, name = q.Name, state = "Passed", questions = (int)qb.QuestionCount, verificationType = QuizInfo.SetVerificationType(aq.IsAutomatic, (int)qb.QuestionCount), otherDetails = q.Description, date = uq.FinishTime }; var notPassed = from q in quizzes join uq in userQuizzes on q.Id equals uq.QuizId join qb in quizBlocks on q.Id equals qb.QuizId join aq in autoQuestions on q.Id equals aq.QuizId where uq.UserId == id select new QuizInfo { id = uq.Id, name = q.Name, state = "In verification", questions = (int)qb.QuestionCount, verificationType = QuizInfo.SetVerificationType(aq.IsAutomatic, (int)qb.QuestionCount), otherDetails = q.Description, date = uq.FinishTime }; foreach (var item in passed) { passedQuizes.Add(item); } //passedQuizes = passedQuizes.Distinct(); foreach (var item in notPassed) { result.Add(item); } for (int i = 0; i < result.Count; i++) { for (int j = 0; j < passedQuizes.Count; j++) { if (result[i].Equals(passedQuizes[j])) { result[i] = passedQuizes[j]; break; } } } return(Json(result, JsonRequestBehavior.AllowGet)); }
public JsonResult GetQuizzesList() { var result = new List <object>(); var quiz = _repository.Get <Quiz>(); var quizBlock = _repository.Get <QuizBlock>(); var userGroup = _repository.Get <UserGroup>(); var quizPass = _repository.Get <QuizPass>(); var user = _repository.Get <User>(); var userToGroup = _repository.Get <UserToUserGroup>(); var quizQuestions = _repository.Get <QuizQuestion>(); var questions = _repository.Get <Question>(); var questionTypes = _repository.Get <QuestionType>(); var autoQuestions = from qz in quiz join qb in quizBlock on qz.Id equals qb.QuizId join qq in quizQuestions on qb.Id equals qq.QuizBlockId join q in questions on qq.QuestionId equals q.Id join qt in questionTypes on q.QuestionTypeId equals qt.Id where qt.IsAutomatic group new { qz, qt } by qz.Id into grouped select new QuestionsAuto { QuizId = grouped.Key, IsAutomatic = grouped.Select(q => q.qt.IsAutomatic).Count() }; var studentAmountReal = from q in quiz join qp in quizPass on q.Id equals qp.QuizId join u in user on qp.UserId equals u.Id group new { q, u } by new { q.Id } into grouped select new { quizId = grouped.Key, studentAmount = grouped.Select(item => item.u.Id).Count() }; //var studentAmount = from ug in userGroup // join utg in userToGroup on ug.Id equals utg.GroupId // join u in user on utg.UserId equals u.Id // group new { ug, u } by new { ug.Id, ug.Name } into grouped // select new // { // groupId = grouped.Key, // studentAmount = grouped.Select(item => item.u.Id).Count() // }; //var query = from passq in quizPass // join q in quiz on passq.QuizId equals q.Id // join ug in userGroup on q.GroupId equals ug.Id // join qb in quizBlock on q.Id equals qb.QuizId // join aq in autoQuestions on passq.QuizId equals aq.QuizId // join sa in studentAmount on ug.Id equals sa.groupId.Id // select new // { // id = passq.Id, // quiz_name = q.Name, // group_name = ug.Name, // questions_amount = qb.QuestionCount, // students_amount = sa.studentAmount, // verification_type = QuizInfo.SetVerificationType(aq.IsAutomatic, (int)qb.QuestionCount) // }; var query = from q in quiz join ug in userGroup on q.GroupId equals ug.Id join qb in quizBlock on q.Id equals qb.QuizId join aq in autoQuestions on q.Id equals aq.QuizId // join sa in studentAmount on ug.Id equals sa.groupId.Id join sa in studentAmountReal on q.Id equals sa.quizId.Id select new { id = q.Id, quiz_name = q.Name, group_name = ug.Name, questions_amount = qb.QuestionCount, students_amount = sa.studentAmount, verification_type = QuizInfo.SetVerificationType(aq.IsAutomatic, (int)qb.QuestionCount) }; foreach (var item in query) { result.Add(item); } return(Json(result, JsonRequestBehavior.AllowGet)); }