public async Task <IActionResult> Edit(int id, [Bind("TransactionId,UserId,BookISBN")] BookOwned bookOwned) { if (id != bookOwned.TransactionId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(bookOwned); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BookOwnedExists(bookOwned.TransactionId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(bookOwned)); }
public void AddNewOwnedBook(IAddNewOwnedBookView inForm, IOwnedRepository ownedRepository) { if (inForm.ShowViewModal() == true) { try { string title = inForm.Title; string author = inForm.Author; string publisher = inForm.Publisher; DateTime datePub = inForm.DatePublished; int numPages = inForm.NumberOfPages; string genre = inForm.Genre; decimal price = inForm.Price; string placeBought = inForm.PlaceBought; bool read = inForm.Read; BookOwned newOwned = BookFactory.CreateBookOwned(title, author, publisher, datePub, numPages, genre, price, placeBought, read); ownedRepository.AddBookOwned(newOwned); } catch (Exception ex) { MessageBox.Show("EXCEPTION: " + ex.Message); throw; } } }
private void UpdateList() { for (int i = 0; i < _listBooks.Count(); i++) { BookOwned book = _listBooks[i]; string bookAuthor = book.Author; string bookPublisher = book.Publisher; string bookDatePublished = book.DatePublished.ToString(); string bookGenre = book.Genre; string bookPages = book.NumPages.ToString(); string bookPrice = book.Price.ToString(); string bookBought = book.PlaceBought; string bookRead = book.Read.ToString(); ListViewItem lvt = new ListViewItem(book.Title); lvt.SubItems.Add(bookAuthor); lvt.SubItems.Add(bookPublisher); lvt.SubItems.Add(bookDatePublished); lvt.SubItems.Add(bookPages); lvt.SubItems.Add(bookGenre); lvt.SubItems.Add(bookPrice); lvt.SubItems.Add(bookBought); lvt.SubItems.Add(bookRead); listOwned.Items.Add(lvt); } }
public void AddBookOwned(BookOwned bookOwned) { bookOwned._bookId = ++_lastId; _listBooks.Add(bookOwned); NotifyObservers(); }
public async Task <IActionResult> Create([Bind("TransactionId,UserId,BookISBN")] BookOwned bookOwned) { if (ModelState.IsValid) { _context.Add(bookOwned); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(bookOwned)); }
public ActionResult AfterPurchase(IFormCollection form) { var myuser = form["UserID"].ToString(); var userItems = _context.MyShoppingCart.Where(m => m.UserId.Equals(myuser)).ToList(); var booksBought = _context.Books.ToList(); int count = 0; foreach (ShoppingCart s in userItems) { if (s.Checked == true) { count++; if (s.UserId.Equals(myuser)) { foreach (Book b in booksBought) { if (b.ISBN.Equals(s.BookISBN)) { b.Quantity -= s.Quantity; b.Sold += s.Quantity; _context.Entry(b).State = EntityState.Modified; _context.SaveChanges(); } } _context.MyShoppingCart.Remove(s); _context.SaveChanges(); BookOwned bought = new BookOwned { UserId = myuser, BookISBN = s.BookISBN }; _context.BooksOwned.Add(bought); _context.SaveChanges(); } } } if (count > 0) { return(RedirectToAction("ConfirmPurchase", "Home")); } else { return(RedirectToAction("NoItems", "Home")); } }