예제 #1
0
        // GET: Books
        public ActionResult Index()
        {
            _bookEntities = new bookEntities();
            List <books> books = _bookEntities.books.ToList();

            return(View(books));
        }
예제 #2
0
        public ActionResult Update(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest));
            }
            var db       = new bookEntities();
            var toUpdate = db.books.Find(id);

            return(View(toUpdate));
        }
예제 #3
0
        public ActionResult Delete(int?id)
        {
            var db       = new bookEntities();
            var toDelete = db.books.Find(id);

            if (toDelete != null)
            {
                db.books.Remove(toDelete);
                db.SaveChanges();
            }
            return(RedirectToAction("Show", "Admin"));
        }
예제 #4
0
 public ActionResult Create(book model)
 {
     if (ModelState.IsValid)
     {
         var db = new bookEntities();
         db.books.Add(new book
         {
             Firstname  = model.Firstname,
             Secondname = model.Secondname,
             Bookname   = model.Bookname,
             Author     = model.Author,
             Datetaken  = model.Datetaken
         }); db.SaveChanges();
     }
     return(RedirectToAction("Show", "Admin"));
 }
예제 #5
0
        public ActionResult Update(int?id, book model)
        {
            var db       = new bookEntities();
            var toUpdate = db.books.Find(id);

            if (ModelState.IsValid)
            {
                if (toUpdate != null)
                {
                    toUpdate.Id         = id ?? default(int);
                    toUpdate.Firstname  = model.Firstname;
                    toUpdate.Secondname = model.Secondname;
                    toUpdate.Bookname   = model.Bookname;
                    toUpdate.Author     = model.Author;
                    toUpdate.Datetaken  = model.Datetaken;
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("Show", "Admin"));
        }
예제 #6
0
        public ActionResult Show()
        {
            var entities = new bookEntities();

            return(View(entities.books.ToList()));
        }