PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 13            if (recordToDelete != '') {
 14
 15                // Perform the ajax post
 16                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
 17                    function (data) {
 18                        // Successful requests get here
 19                        // Update the page elements
 20                        if (data.ItemCount == 0) {
 21                            $('#row-' + data.DeleteId).fadeOut('slow');
 22                        } else {
 23                            $('#item-count-' + data.DeleteId).text(data.ItemCount);
 24                        }
 25
 26                        $('#cart-total').text(data.CartTotal);
 27                        $('#update-message').text(data.Message);
 28                        $('#cart-status').text('Cart (' + data.CartCount + ')');
 29                    });
 30            }
 31        });
 32
 33    });
 34
 35
 36    function handleUpdate() {
 37        // Load and deserialize the returned JSON data
 38        var json = context.get_data();
 39        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
 40
 41        // Update the page elements
 42        if (data.ItemCount == 0) {
 43            $('#row-' + data.DeleteId).fadeOut('slow');
 44        } else {
 45            $('#item-count-' + data.DeleteId).text(data.ItemCount);
 46        }
 47
 48        $('#cart-total').text(data.CartTotal);
 49        $('#update-message').text(data.Message);
 50        $('#cart-status').text('Cart (' + data.CartCount + ')');
 51    }
 52</script>
 53<h3>
 54    <em>Review</em> your cart:
 55</h3>
 56<p class="button">
 57    @Html.ActionLink("Checkout >>", "AddressAndPayment", "Checkout")
 58</p>
 59<div id="update-message">
 60</div>
 61<table>
 62    <tr>
 63        <th>
 64            Album Name
 65        </th>
 66        <th>
 67            Price (each)
 68        </th>
 69        <th>
 70            Quantity
 71        </th>
 72        <th></th>
 73    </tr>
 74    @foreach (var item in Model.CartItems)
 75    {
 76        <tr id="row-@item.RecordId">
 77            <td>
 78                @Html.ActionLink(item.Album.Title, "Details", "Store", new { id = item.AlbumId }, null)
 79            </td>
 80            <td>
 81                @item.Album.Price
 82            </td>
 83            <td id="item-count-@item.RecordId">
 84                @item.Count
 85            </td>
 86            <td>
 87                <a href="#" class="RemoveLink" data-id="@item.RecordId">Remove from cart</a>
 88            </td>
 89        </tr>
 90    }
 91    <tr>
 92        <td>
 93            Total
 94        </td>
 95        <td>
 96        </td>
 97        <td>
 98        </td>
 99        <td id="cart-total">
100            @Model.CartTotal
101        </td>
102    </tr>
103</table>