public ActionResult ArticlePost(ArticleSubmitView articlePost) { var article = new Article { AuthorId = articlePost.AuthorId, Title = HttpUtility.HtmlEncode(articlePost.Title), SubTitle = articlePost.SubTitle, Content = articlePost.Content }; var tags = Request.Form["tags"]; if (article.Content != null) { article.Content = articlePost.Content.Replace("style=\"height:", "name=\"height:"); article.Content = HttpUtility.HtmlEncode(article.Content); } article.PostDate = DateTime.Now; var one = new ArticleStruct { Article = article, RootComments = new List<CommentLevel>() }; if (ModelState.IsValid && !string.IsNullOrEmpty(article.Title)) { var tagsId = GetTagId(tags); article.TagId1 = tagsId[0]; article.TagId2 = tagsId[1]; article.TagId3 = tagsId[2]; article.TagId4 = tagsId[3]; article.TagId5 = tagsId[4]; _db.Articles.Add(article); _db.SaveChanges(); return RedirectToAction("Index",new { articleId =article.ArticleId}); } return RedirectToAction("Index", "Home"); }
public ActionResult ArticlePreview(ArticleSubmitView articlePreview) { var article = new Article { AuthorId = articlePreview.AuthorId, Title = HttpUtility.HtmlEncode(articlePreview.Title), SubTitle = articlePreview.SubTitle, Content = articlePreview.Content }; ViewBag.AuthorName = (from a in _db.Members where a.UserId == articlePreview.AuthorId select string.IsNullOrEmpty(a.NickName) ? a.UserName : a.NickName).FirstOrDefault(); if (article.Content != null) { article.Content = articlePreview.Content.Replace("style=\"height:", "name=\"height:"); article.Content = HttpUtility.HtmlEncode(article.Content); } article.PostDate = DateTime.Now; var one = new ArticleStruct { Article = article, RootComments = new List<CommentLevel>() }; ViewBag.isPreView = true; return View("Index", one); }
public ActionResult Index(long articleId = 0) { var article = _db.Articles.Find(articleId); if (article == null) return HttpNotFound(); // article.Content = article.Content.Replace("\r\n", "<br>"); if (article.TagId1 != null) { ViewBag.tag1 = _db.Tags.Find(article.TagId1)?.TagContent; ViewBag.tagId1 = article.TagId1; } if (article.TagId2 != null) { ViewBag.tag2 = _db.Tags.Find(article.TagId2)?.TagContent; ViewBag.tagId2 = article.TagId2; } if (article.TagId3 != null) { ViewBag.tag3 = _db.Tags.Find(article.TagId3)?.TagContent; ViewBag.tagId3 = article.TagId3; } if (article.TagId4 != null) { ViewBag.tag4 = _db.Tags.Find(article.TagId4)?.TagContent; ViewBag.tagId4 = article.TagId4; } if (article.TagId5 != null) { ViewBag.tag5 = _db.Tags.Find(article.TagId5)?.TagContent; ViewBag.tagId5 = article.TagId5; } if (articleId > 0) { ViewBag.AuthorName = (from a in _db.Members where a.UserId == article.AuthorId select string.IsNullOrEmpty(a.NickName) ? a.UserName : a.NickName).FirstOrDefault(); } var comments = _db.CommentDetailInfo.Where(a => (a.ArticleId == articleId && (a.ReplyId == -1))).ToList(); var oneArticle = new ArticleStruct { Article = article, RootComments = new List<CommentLevel>() }; foreach (var oneComment in comments.Select(rootComment => new CommentLevel { ParentComment = rootComment, ChildComments = _db.CommentDetailInfo.Where( a => a.ArticleId == articleId && a.ReplyId == rootComment.CommentId).ToList() })) { oneArticle.RootComments.Add(oneComment); } /*fetch the emoji in Content\img\emoji */ var emojiPath = Server.MapPath("/Content/img/emoji/"); var emojiDir = new DirectoryInfo(emojiPath); try { var categoryList = emojiDir.GetDirectories(); ViewBag.emoji = new string[categoryList.Length]; for (var i = 0; i < categoryList.Length; i++) ViewBag.emoji[i] = categoryList[i].Name; } catch (Exception e) { throw new Exception(e.ToString()); } return View(oneArticle); }
public ActionResult CommentPost(ArticleStruct articlePost) { if (!string.IsNullOrEmpty(articlePost.CommentArticle.Content)) { articlePost.CommentArticle.CommentId = null; articlePost.CommentArticle.IsValid = 1; if (Session["LoggedUserID"] != null) articlePost.CommentArticle.CommenterId = long.Parse(Session["LoggedUserID"].ToString()); if (articlePost.CommentArticle.ReplyId == null) articlePost.CommentArticle.ReplyId = -1; var address = Request.ServerVariables["REMOTE_ADDR"]; articlePost.CommentArticle.IpAddress = address; articlePost.CommentArticle.ArticleId = articlePost.Article.ArticleId; articlePost.CommentArticle.CreateDate = DateTime.Now; articlePost.CommentArticle.Content = HttpUtility.HtmlEncode(RegexEmojiReplace(articlePost.CommentArticle.Content)); _db.ArticleComments.Add(articlePost.CommentArticle); _db.SaveChanges(); } return RedirectToAction("Index", "Article", new { ArticleID = articlePost.Article.ArticleId }); }