PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/MvcMusicStore/Views/ShoppingCart/Index.cshtml

#
Razor | 103 lines | 95 code | 8 blank | 0 comment | 8 complexity | 83330278b0add6ef00f08f7cce05aaf4 MD5 | raw file
  1. @model MvcMusicStore.ViewModels.ShoppingCartViewModel
  2. @{
  3. ViewBag.Title = "Shopping Cart";
  4. }
  5. <script src="/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
  6. <script type="text/javascript">
  7. $(function () {
  8. // Document.ready -> link up remove event handler
  9. $(".RemoveLink").click(function () {
  10. // Get the id from the link
  11. var recordToDelete = $(this).attr("data-id");
  12. if (recordToDelete != '') {
  13. // Perform the ajax post
  14. $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
  15. function (data) {
  16. // Successful requests get here
  17. // Update the page elements
  18. if (data.ItemCount == 0) {
  19. $('#row-' + data.DeleteId).fadeOut('slow');
  20. } else {
  21. $('#item-count-' + data.DeleteId).text(data.ItemCount);
  22. }
  23. $('#cart-total').text(data.CartTotal);
  24. $('#update-message').text(data.Message);
  25. $('#cart-status').text('Cart (' + data.CartCount + ')');
  26. });
  27. }
  28. });
  29. });
  30. function handleUpdate() {
  31. // Load and deserialize the returned JSON data
  32. var json = context.get_data();
  33. var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
  34. // Update the page elements
  35. if (data.ItemCount == 0) {
  36. $('#row-' + data.DeleteId).fadeOut('slow');
  37. } else {
  38. $('#item-count-' + data.DeleteId).text(data.ItemCount);
  39. }
  40. $('#cart-total').text(data.CartTotal);
  41. $('#update-message').text(data.Message);
  42. $('#cart-status').text('Cart (' + data.CartCount + ')');
  43. }
  44. </script>
  45. <h3>
  46. <em>Review</em> your cart:
  47. </h3>
  48. <p class="button">
  49. @Html.ActionLink("Checkout >>", "AddressAndPayment", "Checkout")
  50. </p>
  51. <div id="update-message">
  52. </div>
  53. <table>
  54. <tr>
  55. <th>
  56. Album Name
  57. </th>
  58. <th>
  59. Price (each)
  60. </th>
  61. <th>
  62. Quantity
  63. </th>
  64. <th></th>
  65. </tr>
  66. @foreach (var item in Model.CartItems)
  67. {
  68. <tr id="row-@item.RecordId">
  69. <td>
  70. @Html.ActionLink(item.Album.Title, "Details", "Store", new { id = item.AlbumId }, null)
  71. </td>
  72. <td>
  73. @item.Album.Price
  74. </td>
  75. <td id="item-count-@item.RecordId">
  76. @item.Count
  77. </td>
  78. <td>
  79. <a href="#" class="RemoveLink" data-id="@item.RecordId">Remove from cart</a>
  80. </td>
  81. </tr>
  82. }
  83. <tr>
  84. <td>
  85. Total
  86. </td>
  87. <td>
  88. </td>
  89. <td>
  90. </td>
  91. <td id="cart-total">
  92. @Model.CartTotal
  93. </td>
  94. </tr>
  95. </table>