/// <summary> Adds book to Customer's ShoppingCart or increases book's count by 1.</summary> /// <param name="customer">Customer object for custId from command.</param> /// <param name="book">Book object for BookId from command.</param> /// <exception cref="System.Exception">Throws when customer or book doesn't exist.</exception> internal void AddBook(Customer customer, Book book) { if(customer == null || book == null) throw new Exception("Customer or Book doesn't exist."); ShoppingCart cart = customer.ShoppingCart; ShoppingCartItem cItem = cart.Items.Find(itm => itm.BookId == book.Id); if(cItem != null) cItem.Count++; else cart.Items.Add(new ShoppingCartItem { BookId = book.Id, Count = 1 }); view.ShowShoppingCart(customer, model); }
/// <summary> Shows HTML source for one book detail. </summary> /// <param name="item">Book object from model.</param> /// <param name="customer">Customer object.</param> public void ShowBookDetail(Book item, Customer customer) { PrintHeadAndMenu(customer.FirstName, customer.ShoppingCart.Items.Count); stdOut.WriteLine(" Book details:"); stdOut.WriteLine(" <h2>" + item.Title + "</h2>"); stdOut.WriteLine(" <p style=\"margin-left: 20px\">"); stdOut.WriteLine(" Author: " + item.Author + "<br />"); stdOut.WriteLine(" Price: " + item.Price + " EUR<br />"); stdOut.WriteLine(" </p>"); stdOut.WriteLine(" <h3><<a href=\"/ShoppingCart/Add/" + item.Id + "\">Buy this book</a>></h3>"); stdOut.WriteLine("</body>"); stdOut.WriteLine("</html>"); PrintCmdEnd(); }
/// <summary> Removes book from Customer's ShoppingCart or decreases book's count by 1. </summary> /// <param name="customer">Customer object for custId from command.</param> /// <param name="book">Book object for BookId from command.</param> /// <exception cref="System.Exception">Throws when Book isn't in Customer's ShoppingCart.</exception> /// <exception cref="System.Exception"> /// Throws when Book isn't in Customer's ShoppingCart or when customer or book doesn't exist. /// </exception> internal void RemoveBook(Customer customer, Book book) { if(customer == null || book == null) throw new Exception("Customer or Book doesn't exist."); ShoppingCart cart = customer.ShoppingCart; ShoppingCartItem cItem = cart.Items.Find(itm => itm.BookId == book.Id); if(cItem == null) throw new Exception("Book doesn't exist in Customers ShoppingCart."); if(cItem.Count > 1) cItem.Count--; else cart.Items.Remove(cItem); view.ShowShoppingCart(customer, model); }