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")); }
public ActionResult LoadPost(int articleId = -1) { // var article = Context.Articles.FindById(articleId); var article = ArticleManager.FindById(articleId); if (article == null) { return(Redirect("/")); } ViewBag.Title = article.Title; return(View(article)); }
public async Task <ActionResult> UkloniObjavu(int articleId = -1) { var article = ArticleManager.FindById(articleId); if (article != null) { if (await ArticleManager.DeleteAsync(article)) { return(Redirect("/")); } } // Artikal ne postoji ili brisanje nije uspelo return(View("Error")); }
public async Task <ActionResult> ObrisiObjavu(int postId = -1) { var article = ArticleManager.FindById(postId); if (article == null) { // Ne otkrivati da ne postoji return(View("AdminErrorPage")); } if (article.Author.Id == User.Identity.GetUserId()) { if (await ArticleManager.DeleteAsync(article)) { return(RedirectToAction("Objave")); } } // Doslo je do modifikacije id-a objave, ili nije uspelo brisanje return(View("AdminErrorPage")); }