예제 #1
0
        private HomeIndexModel BuildHomeIndex()
        {
            var recentQuestion       = _questionImplementation.GetLatestQuestions(10);
            var popularQuestion      = _questionImplementation.GetPopularQuestions(10);
            var mostResponseQuestion = _questionImplementation.GetMostResponseQuestions(10);
            var priorityQuestion     = _questionImplementation.GetPriorityQuestions(10);
            var recentQuestions      = recentQuestion.Select(question => new QuestionListingModel
            {
                QuestionId      = question.QuestionId,
                QuestionTitle   = question.QuestionTitle,
                QuestionContent = question.QuestionContent,
                AuthorId        = question.User.Id,
                AuthorName      = question.User.UserName,
                QuestionCreated = question.QuestionCreated.ToString(),
                AnswerCount     = question.Answers.Count(),
                NumberView      = question.NumberViews,
                Category        = GetCategoryListingForQuestion(question)
            });
            var popularQuestions = popularQuestion.Select(question => new QuestionListingModel
            {
                QuestionId      = question.QuestionId,
                QuestionTitle   = question.QuestionTitle,
                QuestionContent = question.QuestionContent,
                AuthorId        = question.User.Id,
                AuthorName      = question.User.UserName,
                QuestionCreated = question.QuestionCreated.ToString(),
                AnswerCount     = question.Answers.Count(),
                NumberView      = question.NumberViews,
                Category        = GetCategoryListingForQuestion(question)
            });
            var mostResponseQuestions = mostResponseQuestion.Select(question => new QuestionListingModel
            {
                QuestionId      = question.QuestionId,
                QuestionTitle   = question.QuestionTitle,
                QuestionContent = question.QuestionContent,
                AuthorId        = question.User.Id,
                AuthorName      = question.User.UserName,
                QuestionCreated = question.QuestionCreated.ToString(),
                AnswerCount     = question.Answers.Count(),
                NumberView      = question.NumberViews,
                Category        = GetCategoryListingForQuestion(question)
            });
            var priorityQuestions = priorityQuestion.Select(question => new QuestionListingModel
            {
                QuestionId      = question.QuestionId,
                QuestionTitle   = question.QuestionTitle,
                QuestionContent = question.QuestionContent,
                AuthorId        = question.User.Id,
                AuthorName      = question.User.UserName,
                QuestionCreated = question.QuestionCreated.ToString(),
                AnswerCount     = question.Answers.Count(),
                NumberView      = question.NumberViews,
                Category        = GetCategoryListingForQuestion(question)
            });
            var Ip = _accessor.HttpContext.Connection.RemoteIpAddress.ToString();

            return(new HomeIndexModel
            {
                IpAddress = Ip,
                RecentQuestion = recentQuestions,
                PopularQuestion = popularQuestions,
                MostResponseQuestion = mostResponseQuestions,
                PriorityQuestion = priorityQuestions,
            });
        }