public async Task <IActionResult> Details(int id)
        {
            var article = await _articleRepository.FirstOrDefaultAsync(id);

            if (article == null)
            {
                _logger.LogError("Doesn't exist article. Controller:Article. Action:Details");
                return(NotFound());
            }

            var user = await _userManager.FindByIdAsync(article.ProfileID);

            if (user == null)
            {
                _logger.LogError("Doesn't exist user. Controller:Article. Action:Details");
                return(RedirectPermanent("~/Error/Index?statusCode=404"));
            }

            List <Comment> comments = new List <Comment>();

            foreach (var item in _commentRepository.FindAllByArticle(article.ArticleID))
            {
                item.Profile = await _userManager.FindByIdAsync(item.ProfileID);

                comments.Add(item);
            }
            ViewData["UserName"] = user.UserName;
            ViewData["Comment"]  = comments;
            return(View(article));
        }
Example #2
0
        public async void TestFindFirst()
        {
            var Article = await repository.FirstOrDefaultAsync(4);

            Assert.NotNull(Article);
            Assert.Equal("Test4", Article.Text);
            Assert.IsType <Article>(Article);
            Article = await repository.FirstOrDefaultAsync(5);

            Assert.Null(Article);
        }