Example #1
0
 public async Task<IActionResult> Edit(Article article)
 {
     if (ModelState.IsValid)
     {
         _context.Update(article);
         await _context.SaveChangesAsync();
         return RedirectToAction("Index");
     }
     return View(article);
 }
 private static AtomEntry CreateAtomEntry(Article article)
 {
     var slugUri = string.Format("http://henrylawson.net/{0}", article.SlugTitle);
     var entry = new AtomEntry
         {
             Id = new AtomId(new Uri(slugUri)),
             Title = new AtomTextConstruct(article.Title),
             UpdatedOn = article.Date,
             PublishedOn = article.Date,
             Content = new AtomContent(article.Body, "html"),
         };
     entry.Links.Add(new AtomLink
         {
             Uri = new Uri(slugUri)
         });
     return entry;
 }
        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 void Add(Article item)
 {
     throw new NotImplementedException();
 }
 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);
 }