public ActionResult Edit(int articleId) { ArticleDao aDao = new ArticleDao(); Article article = aDao.GetById(articleId); return(View(article)); }
public ActionResult Detail(int articleId) { ArticleDao aDao = new ArticleDao(); CommentDao cDao = new CommentDao(); Article article = aDao.GetById(articleId); ViewBag.CommentsCount = cDao.GetByArticleId(article).Count.ToString(); User user = Membership.GetUser(User.Identity.Name) as User; if (user != null && User.Identity.IsAuthenticated) { if (user.Id == article.AuthorId) { ViewBag.canEdit = true; } else { if (User.IsInRole("Admin")) { ViewBag.canEdit = true; } else { ViewBag.canEdit = false; } } } else { ViewBag.canEdit = false; } return(View(article)); }
public ActionResult CommentsForArticle(int articleId) { ArticleDao aDao = new ArticleDao(); Article article = aDao.GetById(articleId); ViewBag.ArticleTitle = article.Title; ViewBag.ArticleId = article.Id; CommentDao cDao = new CommentDao(); return(View(cDao.GetByArticleId(article))); }
public ActionResult Update(Comment comment, int articleId) { if (ModelState.IsValid) { CommentDao cDao = new CommentDao(); ArticleDao aDao = new ArticleDao(); comment.Article = aDao.GetById(articleId); cDao.Update(comment); TempData["message-success"] = "Komentář byl upraven"; } else { return(View("Edit", comment)); } return(RedirectToAction("CommentsForArticle", new RouteValueDictionary( new { controller = "Comments", action = "CommentsForArticle", articleId = comment.Article.Id }))); }
public ActionResult Add(Comment comment, int articleId) { string articleTitle; if (ModelState.IsValid) { CommentDao cDao = new CommentDao(); ArticleDao aDao = new ArticleDao(); Article article = aDao.GetById(articleId); comment.Article = article; articleTitle = article.Title; comment.IpAddress = Request.UserHostAddress; comment.UserAgent = Request.UserAgent; if (User != null && User.Identity.IsAuthenticated) { User user = Membership.GetUser(User.Identity.Name) as User; comment.AuthorNick = user.Nick; comment.AuthorEmail = user.Email; } cDao.Create(comment); TempData["message-success"] = "Příspěvek do diskuze byl úspěšně přidán"; } else { return(View("Create", comment)); } try { SendNotificationEmail(comment.AuthorEmail, articleTitle); } catch (Exception e) { TempData["error"] = e; } return(RedirectToAction("CommentsForArticle", new RouteValueDictionary( new { controller = "Comments", action = "CommentsForArticle", articleId = articleId }))); }
public ActionResult DeleteArticle( int id ) { try { ArticleDao articleDao = new ArticleDao(); Article article = articleDao.GetById( id ); if( article.ImageName != null ) System.IO.File.Delete( Server.MapPath( "~/uploads/articleImage/" + article.ImageName ) ); articleDao.Delete( article ); TempData["message-success"] = "Článek" + article.Title + "byla smazan."; } catch( Exception exception ) { throw; } return RedirectToAction( "Index" ); }