Esempio n. 1
0
 public ActionResult Edit(int id)
 {
     Anecdote anecdote = new Anecdote();
     anecdote = db.Anecdotes.Find(id);
     ViewBag.Anecdote = anecdote;
     return View();
 }
Esempio n. 2
0
 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");
     }
 }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
 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();
 }
Esempio n. 5
0
 public ActionResult Show(int id)
 {
     var anecdote = new Anecdote();
     anecdote = db.Anecdotes.Find(id);
     ViewBag.Anecdote = anecdote;
     return View();
 }