public void SaveArticle(Article article) { if (article.articleID == 0) { _db.Articles.Add(article); } else { var dbEntry = _db.Articles.Find(article.articleID); if (dbEntry != null) { dbEntry.title = article.title; dbEntry.userID = article.userID; dbEntry.imageURL = article.imageURL; dbEntry.description = article.description; dbEntry.date = article.date; } } _db.SaveChanges(); }
public ActionResult EditArticle(Article article) { article.userID = CurrentUserId; if (ModelState.IsValid) { article.date = DateTime.Now; repository.SaveArticle(article); TempData["message"] = string.Format("Новину {0} було збережено!", article.title); return RedirectToAction("ArticlesList"); } else { return View(article); } }