Example #1
0
        public StatsOfCatQueAnsVm GetStatsAboutCatQueAns()
        {
            int    counter    = 1;
            int    minCounter = int.MaxValue;
            int    maxCounter = int.MinValue;
            string categoryWithTheMostQuestions   = "empty";
            string categoryWithTheFewestQuestions = "empty";
            var    questions = _catQueAnsRepo.ShowQuestions().ProjectTo <QuestionToListAdminVm>
                                   (_mapper.ConfigurationProvider).ToList();

            for (int i = 0; i < questions.Count; i++)
            {
                for (int j = i + 1; j < questions.Count; j++)
                {
                    if (questions[i].CategoryText == questions[j].CategoryText)
                    {
                        counter++;
                    }
                }
                if (maxCounter <= counter)
                {
                    maxCounter = counter;
                    categoryWithTheMostQuestions = questions[i].CategoryText;
                }
                if (minCounter >= counter)
                {
                    minCounter = counter;
                    categoryWithTheFewestQuestions = questions[i].CategoryText;
                }
                counter = 1;
            }
            StatsOfCatQueAnsVm statsOfCatQueAnsVm = new StatsOfCatQueAnsVm()
            {
                AmountOfCategories             = _statsRepo.GetAmountOfCategories(),
                AmountOfQuestions              = _statsRepo.GetAmountOfQuestions(),
                AmountOfAnswers                = _statsRepo.GetAmountOfAnswers(),
                AmountOfGoodAnswers            = _statsRepo.GetAmountOfGoodAnswers(),
                AmountOfNonAcceptedCategories  = _statsRepo.GetAmountOfNonAcceptedCategories(),
                AmountOfNonAcceptedQuestions   = _statsRepo.GetAmountOfNonAcceptedQuestions(),
                AmountOfNonAcceptedAnswers     = _statsRepo.GetAmountOfNonAcceptedAnswers(),
                CategoryWithTheMostQuestions   = categoryWithTheMostQuestions,
                CategoryWithTheFewestQuestions = categoryWithTheFewestQuestions,
            };

            return(statsOfCatQueAnsVm);
        }