public IActionResult Topic(int id) { var category = _categoryImplementation.GetById(id); var questions = new List <Question>(); questions = _questionImplementation.GetFilteredQuestions(category).ToList(); var questionListings = questions.Select(question => new QuestionListingModel { QuestionId = question.QuestionId, AuthorName = question.User.UserName, QuestionTitle = question.QuestionTitle, QuestionContent = question.QuestionContent, QuestionCreated = question.QuestionCreated.ToString(), AnswerCount = question.Answers.Count(), NumberView = question.NumberViews, Category = BuildCategoryListing(question) }); var model = new CategoryTopicModel { Questions = questionListings, Category = BuildForumListing(category) }; return(View(model)); }
public IActionResult Result(string searchQuery) { var questions = _questionImplementation.GetFilteredQuestions(searchQuery); var areNoResults = (!string.IsNullOrEmpty(searchQuery) && !questions.Any()); var questionListingModel = questions.Select(question => new QuestionListingModel { QuestionId = question.QuestionId, QuestionTitle = question.QuestionTitle, AuthorName = question.User.UserName, QuestionCreated = question.QuestionCreated.ToString(), AnswerCount = question.Answers.Count(), NumberView = question.NumberViews, Category = BuildForumListing(question) }); var model = new SearchModel { Questions = questionListingModel, SearchQuery = searchQuery, EmptySearchResults = areNoResults }; return(View(model)); }