Exemplo n.º 1
0
        public async Task <List <ReportResource> > ListAsync(int testId)
        {
            var subtests = await _subtestRepository.ListAsync(testId);

            var protocols = await _protocolRepository.ListAsync(testId);

            var reports = new List <ReportResource>();

            foreach (var protocol in protocols)
            {
                var answeredSubtests = new List <Subtest>();
                foreach (var subtest in subtests)
                {
                    subtest.Questions = await _questionRepository.ListAnsweredAsync(subtest.Id, protocol.Id);

                    foreach (var q in subtest.Questions)
                    {
                        q.Answer = q.Answers.Where(a => a.ProtocolId == protocol.Id).FirstOrDefault();
                    }
                    await this.CalculateScoreAndPercent(subtest);

                    await this.ApplySubtestFilters(subtest);

                    subtest.Percentage = (int)Math.Round((subtest.Score / subtest.Max) * 100);
                    answeredSubtests.Add(subtest);
                }
                var report = new Report {
                    Subtests = answeredSubtests, Protocol = protocol
                };
                reports.Add(
                    _mapper.Map <Report, ReportResource>(report)
                    );
            }

            return(reports);
        }
Exemplo n.º 2
0
 public async Task <IEnumerable <Protocol> > ListAsync(int testId)
 {
     // TODO :: CHECK IF TEST BELONGS TO TOKEN USER
     //https://stackoverflow.com/questions/46112258/how-do-i-get-current-user-in-net-core-web-api-from-jwt-token
     return(await _protocolRepository.ListAsync(testId));
 }