public ActionResult Edit(int id) { Anecdote anecdote = new Anecdote(); anecdote = db.Anecdotes.Find(id); ViewBag.Anecdote = anecdote; return View(); }
public ActionResult Delete(int id) { var anecdote = new Anecdote(); try { anecdote = db.Anecdotes.Find(id); db.Anecdotes.Remove(anecdote); db.SaveChanges(); return Content("ok"); } catch(Exception ex) { log.Error(new LogContent("删除牛人轶事失败", Helpers.HttpHelper.GetIPAddress()), ex); return Content("fail"); } }
public ActionResult Add(Anecdote model) { if (ModelState.IsValid) { model.Time = DateTime.Now; model.Browses = 0; db.Anecdotes.Add(model); db.SaveChanges(); return Redirect("/Admin/Anecdote/Index"); } else { ModelState.AddModelError("", "信息输入错误!"); } return View(); }
public ActionResult Edit(Anecdote model) { if (ModelState.IsValid) { try { Anecdote anecdote = new Anecdote(); anecdote = db.Anecdotes.Find(model.ID); anecdote.Title = model.Title; anecdote.Description = model.Description; anecdote.IsPublish = model.IsPublish; db.SaveChanges(); return Redirect("/Admin/Anecdote/Show/" + model.ID); } catch (Exception ex) { log.Error(new LogContent("编辑牛人轶事失败!", Helpers.HttpHelper.GetIPAddress()), ex); } } else { ModelState.AddModelError("", "修改的信息输入错误!"); } return View(); }
public ActionResult Show(int id) { var anecdote = new Anecdote(); anecdote = db.Anecdotes.Find(id); ViewBag.Anecdote = anecdote; return View(); }