Esempio n. 1
0
        public async Task <ActionResult> PostComment(AddCommentViewModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["ValidationError"] = "Niste uneli komentar!";
                return(Redirect($"/Artikli/{model.ArticleId}"));
            }

            var article = ArticleManager.FindById(model.ArticleId);
            var user    = await UserManager.FindByIdAsync(User.Identity.GetUserId());

            if (article != null && user != null)
            {
                Comment comment = new Comment
                {
                    Article       = article,
                    DatePublished = DateTime.Now,
                    PostedBy      = user,
                    Text          = model.Text
                };

                await ArticleManager.CreateCommentAsync(comment);

                return(Redirect($"/Artikli/{model.ArticleId}"));
            }
            // Korisnik ili artikal nisu pronadjeni
            return(View("Error"));
        }