public async Task <SeasonModel> GetActiveSeason()
        {
            var season = await _query.GetActiveSeason();

            var model = _mapper.Map <SeasonModel>(season);

            return(model);
        }
Beispiel #2
0
        public async Task <ActiveCardModel> GetActiveCardId(int userId)
        {
            var activeSeason = await _seasonsQueryProcessor.GetActiveSeason();

            var model    = new ActiveCardModel();
            var userCard = _uow.Query <UserCard>()
                           .Include(x => x.Card)
                           .ThenInclude(x => x.CardQuestions)
                           .ThenInclude(x => x.Question)
                           .ThenInclude(x => x.Category)
                           .Include(x => x.UserSeasonLeague)
                           .Where(x => x.UserSeasonLeague.SeasonId == activeSeason.Id)
                           .Include(x => x.UserAnswers)
                           .Where(x => x.UserSeasonLeague.UserId == userId && x.CardStateId == CardStates.ACTIVE)
                           .SingleOrDefault();

            if (userCard == null)
            {
                throw new NotFoundException("no active card for this user !");
            }
            model.CardId = userCard.CardId;
            model.QuestionsByCategoryList = new List <QuestionsByCategory>();
            for (int i = 1; i <= 10; i++)
            {
                QuestionsByCategory q = new QuestionsByCategory();
                q.CategoryId = (from c in _uow.Query <Category>()
                                where c.Sort == i
                                select c
                                ).SingleOrDefault().Id;
                q.CategoryName = (from c in _uow.Query <Category>()
                                  where c.Sort == i
                                  select c
                                  ).SingleOrDefault().Name;
                q.QuestionId = userCard.Card.CardQuestions.Select(x => x.Question).Where(c => c.Category.Sort == i).SingleOrDefault().Id;
                if (userCard.UserAnswers.Where(c => c.Question.Category.Sort == i).Any())
                {
                    q.IsAnswered = true;
                }
                else
                {
                    q.IsAnswered = false;
                }
                q.Sort = i;

                model.QuestionsByCategoryList.Add(q);
            }


            model.CardScoreList = new List <CardScore>();
            for (int i = 1; i <= 10; i++)
            {
                CardScore score = new CardScore();
                if (userCard.UserAnswers.Where(c => c.Sort == i).Any())
                {
                    score.Sort  = i;
                    score.Score = userCard.UserAnswers.Where(c => c.Sort == i).SingleOrDefault().AnswerPoints;
                }
                else
                {
                    score.Sort  = i;
                    score.Score = null;
                }

                model.CardScoreList.Add(score);
            }
            return(model);
        }