public ActionResult UpdateArticle(Article updatedArticle) { var db = new ArticlesDb(); var storedArticle = GetArticleById(updatedArticle.Id); if (storedArticle != null) { storedArticle.Content = updatedArticle.Content; storedArticle.Title = storedArticle.Title; db.SaveChanges(); TempData["success"] = "Article updated"; return(RedirectToAction("Index")); } Response.StatusCode = 404; return(Content("Article not found")); }
public ActionResult CreateArticle(Article article) { if (HttpContext.User.Identity.IsAuthenticated) { article.Author = HttpContext.User.Identity.Name; } else { article.Author = "Ricardo"; //this is when testing and not logged in } var db = new ArticlesDb(); article.PublishedDate = DateTime.Now; db.Articles.Add(article); db.SaveChanges(); TempData["success"] = "Article created successfully"; return(RedirectToAction("Index")); }
public ActionResult DeleteArticle(int id) { var db = new ArticlesDb(); var article = db.Articles.Find(id); if (article != null) { db.Articles.Remove(article); } else { Response.StatusCode = 404; return(Content("Article not found.")); } TempData["success"] = "Article deleted successfully"; db.SaveChanges(); return(RedirectToAction("Index")); }