public void AddBookToCart(int userId, int bookId) { string cartId = GetCartId(userId); int quantity = 1; CartItems existingCartItem = _dbContext.CartItems.FirstOrDefault(x => x.ProductId == bookId && x.CartId == cartId); if (existingCartItem != null) { existingCartItem.Quantity += 1; _dbContext.Entry(existingCartItem).State = EntityState.Modified; _dbContext.SaveChanges(); } else { CartItems cartItems = new CartItems { CartId = cartId, ProductId = bookId, Quantity = quantity }; _dbContext.CartItems.Add(cartItems); _dbContext.SaveChanges(); } }
public ActionResult Create(BookModel model) { if (ModelState.IsValid) { objBookDb.Entry(model).State = EntityState.Added; objBookDb.SaveChanges(); return(RedirectToAction("Index")); } return(View()); }
public async Task <IActionResult> PutCategories(int id, Categories categories) { if (id != categories.CategoryId) { return(BadRequest()); } _context.Entry(categories).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CategoriesExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Edit(Book book, string[] selectedCategories, bool?leaf) { if (ModelState.IsValid) { if (UploadFile(Request, book)) { book.UpdateTime = DateTime.Now; db.Entry(book).State = EntityState.Modified; } else { ViewBag.ErrorInfo = "文件上传失败"; } var guids = selectedCategories.Select(s => new Guid(s)); if (guids.Any()) { book.Categories = db.Categories.Where(c => guids.Contains(c.Id)).ToList(); db.SaveChanges(); return(RedirectToAction("Index")); } } InitializeBookPageViewBag(leaf); book = db.Books.Include(b => b.Categories).Single(b => b.Id == book.Id); return(View(book)); }
public async Task <IActionResult> PutBook([FromRoute] int id, [FromBody] Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.BookID) { return(BadRequest()); } _context.Entry(book).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int UpdateCategory(Categories category) { try { Categories oldCategoryData = GetCategoryData(category.CategoryId); oldCategoryData.CategoryName = category.CategoryName; _dbContext.Entry(oldCategoryData).State = EntityState.Modified; _dbContext.SaveChanges(); return(1); } catch { throw; } }
public IHttpActionResult PutBook(int id, Book book) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != book.Id) { return(BadRequest()); } db.Entry(book).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!BookExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public ActionResult Edit([Bind(Include = "Id,Title,ISBN,Author,Description")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Details", new { id = book.Id })); } return(View(book)); }
public ActionResult Edit([Bind(Include = "BookID,Category,Name,Numberfcopies,AuthorID,Price,PublishDate")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Borrow([Bind(Include = "ID,BookID,Name,Comment,BorrowDate")] Borrower borrower) { if (ModelState.IsValid) { // insert borrower record borrower.ReturnDate = borrower.BorrowDate; // LITTLE FUDGE AS DATABASE WAS NOT ACCETING NULL DATETIME dbBorrower.Borrowers.Add(borrower); dbBorrower.SaveChanges(); // update the book status to "out of self" Book book = db.Books.Find(borrower.BookID); book.isAvailable = false; db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(borrower)); }
public ActionResult Edit([Bind(Include = "ID,ISBN,Title,AuthorID,Publisher,PublishDate,Price")] book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "ISBN,AuthorID,Title,EditionNumber,Copyright,FirstName,LastName")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "BookID,Title,Author,Edition,PublishYear,Price,Quantity")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "ID,Title,ReleaseDate,Theme,Price")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit(BooksDB bookdb) { if (ModelState.IsValid) { db.Entry(bookdb).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(bookdb)); }
public string EditBook([Bind(Include = "title,author,price,qty")] Book book, int id) { if (ModelState.IsValid) { book.id = id; db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return("Success"); } return("Fail"); }
public async Task <ActionResult> Edit([Bind(Include = "ID,Name,PubDate,Price")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(book)); }
public ActionResult Edit([Bind(Include = "ID,Index,Name,Author,Year,Price,Stock")] S4452232 s4452232) { if (ModelState.IsValid) { db.Entry(s4452232).State = EntityState.Modified; db.SaveChanges(); SaveBooks(db.S4452232.ToList()); return(RedirectToAction("Index")); } return(View(s4452232)); }
public ActionResult Edit([Bind(Include = "Id,BookTitle,BookEdition,BookAuthor1,BookAuthor2,BookCategory,BookPurchasePrice,BookPublisher,BookISBN,BookStatus,BookStorage_Code,BookFormat,ReleaseDate,BFormatId,BCategoryId")] Book book) { if (ModelState.IsValid) { db.Entry(book).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.BCategoryId = new SelectList(db.BCategories, "Id", "BCategoryType", book.BCategoryId); ViewBag.BFormatId = new SelectList(db.BFormats, "Id", "FormatType", book.BFormatId); return(View(book)); }
public int UpdateBook(Document book) { try { Document oldBookData = GetBookData(book.DocumentId); if (oldBookData.CoverFileName != null) { if (book.CoverFileName == null) { book.CoverFileName = oldBookData.CoverFileName; } } _dbContext.Entry(book).State = EntityState.Modified; _dbContext.SaveChanges(); return(1); } catch { throw; } }
public ActionResult Create(Category category, bool?leaf) { if (ModelState.IsValid) { category.Id = Guid.NewGuid(); db.Categories.Add(category); // Otherwise EF will try to insert the parent and failed. db.Entry(category.Parent).State = EntityState.Unchanged; db.SaveChanges(); return(RedirectToAction("Index")); } InitializeCategoryViewBag(leaf, null); return(View(category)); }
public void UpdateBook(Book book) { db.Entry(book).State = System.Data.Entity.EntityState.Modified; }
public void Update(Book book) { context.Entry(book).State = System.Data.EntityState.Modified; }
public void SaveBook(int id, Book book) { _dbContext.Set <Book>().Attach(book); _dbContext.Entry(book).State = EntityState.Modified; _dbContext.SaveChanges(); }