public ActionResult Edit(int bookInventoryID, BookInventoryEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (model.BookInventoryID != bookInventoryID)

            {
                ModelState.AddModelError("", "Id Mismatch");
                return(View(model));
            }

            var service = CreateInventoryService();

            if (service.UpdateInventoryBook(model))
            {
                TempData["SaveResult"] = "Your book was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your book could not be updated.");
            return(View(model));
        }
Пример #2
0
        public bool UpdateFutureReading(BookInventoryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .FutureReading
                    .Single(e => e.FutureReadingID == model.FutureReadingID && e.UserID == _userID);

                entity.FutureReadingID = model.FutureReadingID;
                entity.BookID          = model.BookID;
                entity.UserID          = _userID;
                entity.Notes           = model.Notes;

                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Edit(int bookInventoryID)
        {
            var service = CreateInventoryService();
            var detail  = service.GetBookByInventoryID(bookInventoryID);
            var model   =
                new BookInventoryEdit
            {
                BookInventoryID = detail.BookInventoryID,
                BookID          = detail.BookID,
                Title           = detail.Title,
                Author          = detail.Author,
                HasRead         = detail.HasRead,
                TypeOfBook      = detail.TypeOfBook,
                Notes           = detail.Notes
            };

            return(View(model));
        }
Пример #4
0
        public bool UpdateInventoryBook(BookInventoryEdit model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity =
                    ctx
                    .BookInventory
                    .Single(e => e.BookInventoryID == model.BookInventoryID && e.UserID == _userID);

                entity.BookInventoryID = model.BookInventoryID;
                entity.UserID          = _userID;
                entity.BookID          = model.BookID;
                entity.HasRead         = model.HasRead;
                entity.Notes           = model.Notes;
                entity.TypeOfBook      = model.TypeOfBook;

                return(ctx.SaveChanges() == 1);
            }
        }