Пример #1
0
        public ActionResult DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(View("Error"));
            }
            //Album album = db.Albums.Find(id);
            //db.Albums.Remove(album);
            //db.SaveChanges();
            //Album =
            Album album = db.Albums.SingleOrDefault(a => a.AlbumId == id);

            if (album == null)
            {
                return(View("Error"));
            }
            db.Delete(album);
            return(RedirectToAction("Index"));
        }
        //{
        public ActionResult DeleteConfirmed(int?id)
        //    Album album = db.Albums.Find(id);
        {
            //    db.Albums.Remove(album);
            //Scaffolded code - no longer needed
            //    db.SaveChanges();
            //Album album = db.Albums.Find(id);
            //    return RedirectToAction("Index");
            //db.Albums.Remove(album);
            //}
            //db.SaveChanges();
            Album album = db.Albums.SingleOrDefault(a => a.AlbumId == id);

            if (album == null)
            {
                return(View("Error"));
            }
            else
            {
                db.Delete(album);
                return(RedirectToAction("Index"));
            }
        }