コード例 #1
0
        // this is a bool because return did it change the data context (save changes)
        public bool BookInventoryCreate(BookInventoryCreate model)
        {
            var content =
                new BookInventory()
            {
                BookInventoryID = model.BookInventoryID,
                UserID          = _userID,
                BookID          = model.BookID,
                HasRead         = model.HasRead,
                Notes           = model.Notes,
                TypeOfBook      = model.TypeOfBook
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.BookInventory.Add(content);
                return(ctx.SaveChanges() == 1);
            }
        }
コード例 #2
0
        public ActionResult Create(BookInventoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateInventoryService();


            if (service.BookInventoryCreate(model))
            {
                TempData["SaveResult"] = "Your Book was added.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Book could not be added.");

            return(View(model));
        }