public static void Render(int custId, ModelStore modelStore) { ViewHeader.Render(custId, modelStore); var shoppingCartItems = modelStore.GetCustomer(custId).ShoppingCart.Items; if (shoppingCartItems.Count == 0) { Console.WriteLine(" Your shopping cart is EMPTY."); } else { Console.WriteLine(" Your shopping cart:"); Console.WriteLine(" <table>"); Console.WriteLine(" <tr>"); Console.WriteLine(" <th>Title</th>"); Console.WriteLine(" <th>Count</th>"); Console.WriteLine(" <th>Price</th>"); Console.WriteLine(" <th>Actions</th>"); Console.WriteLine(" </tr>"); decimal total = 0; foreach (var item in shoppingCartItems) { var book = modelStore.GetBook(item.BookId); Console.WriteLine(" <tr>"); Console.WriteLine(" <td><a href=\"/Books/Detail/"+ book.Id.ToString() + "\">" + book.Title + "</a></td>"); Console.WriteLine(" <td>"+ item.Count.ToString() + "</td>"); Console.WriteLine(" <td>"+ (item.Count == 1 ? book.Price.ToString() : item.Count.ToString() + " * " + book.Price.ToString() + " = " + (item.Count * book.Price).ToString()) + " EUR</td>"); Console.WriteLine(" <td><<a href=\"/ShoppingCart/Remove/"+ book.Id.ToString() + "\">Remove</a>></td>"); Console.WriteLine(" </tr>"); total += item.Count * book.Price; } Console.WriteLine(" </table>"); Console.WriteLine(" Total price of all items: " + total.ToString() + " EUR"); } Console.WriteLine("</body>"); Console.WriteLine("</html>"); }
public static void Render(int custId, ModelStore modelStore) { ViewHeader.Render(custId, modelStore); Console.WriteLine(" Our books for you:"); Console.WriteLine(" <table>"); var books = modelStore.GetBooks(); for (int i = 0; i < books.Count; i++) { var book = books[i]; // start new row if (i % 3 == 0) { // end last row if (i != 0) { Console.WriteLine(" </tr>"); } Console.WriteLine(" <tr>"); } Console.WriteLine(" <td style=\"padding: 10px;\">"); Console.WriteLine(" <a href=\"/Books/Detail/"+ book.Id.ToString() + "\">" + book.Title + "</a><br />"); Console.WriteLine(" Author: "+ book.Author + "<br />"); Console.WriteLine(" Price: "+ book.Price.ToString() + " EUR <<a href=\"/ShoppingCart/Add/" + book.Id.ToString() + "\">Buy</a>>"); Console.WriteLine(" </td>"); } if (books.Count > 0) { // end last row Console.WriteLine(" </tr>"); } Console.WriteLine(" </table>"); Console.WriteLine("</body>"); Console.WriteLine("</html>"); }
public static void Render(int custId, int bookId, ModelStore modelStore) { var book = modelStore.GetBook(bookId); if (book == null) { ViewInvalidRequest.Render(); return; } ViewHeader.Render(custId, modelStore); Console.WriteLine(" Book details:"); Console.WriteLine(" <h2>" + book.Title + "</h2>"); Console.WriteLine(" <p style=\"margin-left: 20px\">"); Console.WriteLine(" Author: " + book.Author + "<br />"); Console.WriteLine(" Price: " + book.Price.ToString() + " EUR<br />"); Console.WriteLine(" </p>"); Console.WriteLine(" <h3><<a href=\"/ShoppingCart/Add/" + book.Id.ToString() + "\">Buy this book</a>></h3>"); Console.WriteLine("</body>"); Console.WriteLine("</html>"); }