public List <ExamDetailDTO> List() { List <ExamDetailDTO> responseList = new List <ExamDetailDTO>(); examRepository.ListByUserId(user.Id).ForEach(x => responseList.Add(new ExamDetailDTO { Id = x.Id, Time = x.Time.Split('.')[0], Name = x.Name, Description = x.Description, Password = x.Password, IsRandom = false, StartTime = DateTime.ParseExact(x.StartTime, CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.CurrentCulture).ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss"), EndTime = DateTime.ParseExact(x.EndTime, CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.CurrentCulture).ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss"), Count = examRepository.Count(x.Id, false) })); examRepository.ListRandomByUserId(user.Id).ForEach(x => responseList.Add(new ExamDetailDTO { Id = x.Id, Time = x.Time.Split('.')[0], Name = x.Name, Description = x.Description, Password = x.Password, IsRandom = true, StartTime = DateTime.ParseExact(x.StartTime, CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.CurrentCulture).ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss"), EndTime = DateTime.ParseExact(x.EndTime, CultureInfo.CurrentCulture.DateTimeFormat.RFC1123Pattern, CultureInfo.CurrentCulture).ToLocalTime().ToString("dd-MM-yyyy HH:mm:ss"), Count = examRepository.Count(x.Id, true) })); return(responseList); }
public ReviewExamDTO CalculateMark(ExamAnswerDTO examAnswer, Guid userId) { ReviewExamDTO mark = new ReviewExamDTO(); mark.TimeSpent = CalculateTimeSpent(examAnswer.ExamId, userId); int numsOfTrue = 0; examAnswer.AnswerDetails.ForEach(answer => { var key = questionRepository.GetById(answer.QuestionId); if (key.Type == 3) { if (answer.Content.Equals(key.Content)) { QuestionState.Add(key.Id, true); numsOfTrue++; } } else { var userAnswers = answer.UserAnswers.Where(x => x.IsSelected == true).Select(x => x.AnswerId).OrderBy(x => x).ToList(); var trueAnswers = answerRepository.ListByQuestionId(key.Id).Where(x => x.IsCorrect == true).Select(x => x.Id).OrderBy(x => x).ToList(); if (string.Join("", userAnswers).Equals(string.Join("", trueAnswers))) { QuestionState.Add(key.Id, true); numsOfTrue++; } } if (!QuestionState.ContainsKey(key.Id)) { QuestionState.Add(key.Id, false); } }); mark.Score = Math.Round(((Double)numsOfTrue) / examRepository.Count(examAnswer.ExamId, examService.IsRandom(examAnswer.ExamId)) * 10, 2, MidpointRounding.AwayFromZero); return(mark); }