コード例 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Tbhero heroes = db.Tbheroes.Find(id);

            db.Tbheroes.Remove(heroes);
            db.SaveChanges();
            return(RedirectToAction("ListAll"));
        }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "Id,FirstName,LastName,Service,Description,Picture")] Tbhero heroes)
 {
     if (ModelState.IsValid)
     {
         db.Entry(heroes).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("ListAll"));
     }
     return(View(heroes));
 }
コード例 #3
0
        // GET: AllHeroes/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Tbhero heroes = db.Tbheroes.Find(id);

            if (heroes == null)
            {
                return(HttpNotFound());
            }
            return(View(heroes));
        }
コード例 #4
0
 public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Service,Description,Picture")] Tbhero heroes)
 {
     if (heroes.Picture == null)
     {
         heroes.Picture = "http://www.flags.net/images/largeflags/POLA0001.GIF";
     }
     try
     {
         if (ModelState.IsValid)
         {
             db.Tbheroes.Add(heroes);
             db.SaveChanges();
             return(RedirectToAction("ListAll"));
         }
     }
     catch (DataException)
     {
         ModelState.AddModelError("", "Unable to save changes. Try again.");
     }
     return(View(heroes));
 }