// GET: Article/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ArticleModel article = db.Articles.Find(id); if (article == null) { return HttpNotFound(); } EditArticleViewModel editArticleViewModel = new EditArticleViewModel() { ArticleDate = article.ArticleDateTime, ArticleTime = article.ArticleDateTime, ArticleText = article.ArticleText, ArticleTitle = article.ArticleTitle }; return View(editArticleViewModel); }
public ActionResult Edit(EditArticleViewModel editArticleViewModel) { if (ModelState.IsValid) { ArticleModel article = db.Articles.Find(editArticleViewModel.Id); var newDateTime = new DateTime( editArticleViewModel.ArticleDate.Year, editArticleViewModel.ArticleDate.Month, editArticleViewModel.ArticleDate.Day, editArticleViewModel.ArticleTime.Hour, editArticleViewModel.ArticleTime.Minute, editArticleViewModel.ArticleTime.Second ); article.ArticleDateTime = newDateTime; article.ArticleText = editArticleViewModel.ArticleText; article.ArticleTitle = editArticleViewModel.ArticleTitle; db.Entry(article).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(editArticleViewModel); }