コード例 #1
0
        public void AddCategoryToBook(AddCategoryToBookBindingModel bindingModel)
        {
            Book     book     = this.Context.Books.Find(bindingModel.Id);
            Category category = this.Context.Categories
                                .First(c => c.Id.ToString() == bindingModel.SelectCategories);

            book.Categories.Add(category);
            this.Context.SaveChanges();
        }
コード例 #2
0
        public ActionResult AddCategoryToBook([Bind(Include = "Id,SelectCategories")] AddCategoryToBookBindingModel bindingModel)
        {
            if (ModelState.IsValid)
            {
                this.bookService.AddCategoryToBook(bindingModel);
                this.TempData["Success"] = "Success";
                return(RedirectToAction("Details", "Books", new { id = bindingModel.Id }));
            }

            this.TempData["Error"] = "Error";
            return(RedirectToAction("Details", "Books", new { id = bindingModel.Id }));
        }