public ActionResult Create(ArticleViewModel model) { if (ModelState.IsValid) { try { Article article = new Article() { AddTime = DateTime.Now, ArticleCode = model.ArticleCode, Content = model.Content, Name = model.Name, LastTime = DateTime.Now }; ArticleService.Create(article); return RedirectToAction("index"); } catch (Exception ex) { ViewBag.Message = ex.Message; return View(model); } } else { return View(model); } }
public void Update(ArticleViewModel model) { Article article = Find(model.ID); DB_Service.Attach<Article>(article); article.ArticleCode = model.ArticleCode; article.Content = model.Content; article.Name = model.Name; article.LastTime = DateTime.Now; DB_Service.Commit(); }
public ActionResult Edit(ArticleViewModel model) { if (ModelState.IsValid) { try { ArticleService.Update(model); return RedirectToAction("index"); } catch (Exception ex) { ViewBag.Message = ex.Message; return View(model); } } else { return View(model); } }
public ActionResult Edit(int id) { Article article = ArticleService.Find(id); ArticleViewModel model = new ArticleViewModel() { Name = article.Name, ID = article.ID, ArticleCode = article.ArticleCode, Content = article.Content }; return View(model); }