예제 #1
0
        public async Task <IActionResult> Read(int Id)
        {
            //Get article and increment view count
            var requestedArticle = _articleService.GetById(Id);

            requestedArticle.ViewCount++;
            _articleService.Update(requestedArticle);

            //Get comments of article
            var comments = _articleCommentService.GetCommentsByArticleId(Id).ToList();

            //Get logged in user
            var user = await _userManager.GetUserAsync(HttpContext.User);

            bool isLikedBefore = false;

            if (user != null)
            {
                string username = user.UserName;
                isLikedBefore = _userLikeService.CheckUserLikeExists(username, Id);
            }

            ReadArticleVM ravm = new ReadArticleVM {
                Article = requestedArticle, IsLikedBefore = isLikedBefore, Comments = comments
            };

            return(View(ravm));
        }
예제 #2
0
        public async Task <IActionResult> Read(int Id, ReadArticleVM comment)
        {
            //Get logged in user
            var user = await _userManager.GetUserAsync(HttpContext.User);

            string username = user.UserName;

            ArticleComment ac = new ArticleComment {
                CommentText = comment.PostedComment, ArticleId = Id, Username = username
            };

            _articleCommentService.Create(ac);

            return(RedirectToAction("Read", new { Id = Id }));
        }