May 2018
Intermediate to advanced
334 pages
7h 25m
English
Now that we have added one cart record, let's move to update that record whenever a customer repeatedly hits the Add To Cart button. We already have the code that updates the quantity and price on the client-side table, so we just need to write the code to call the PUT endpoint to update the record, as follows:
function PutCart(cartItem) { var cart = { Id: cartItem.attr('data-cart-id'), Customerid: '910D4C2F-B394-4578-8D9C-7CA3FD3266E2', Productid: cartItem.attr('data-product-id'), Qty: cartItem.find('td.qty').html(), Finalprice: cartItem.find('td.price').html().replace('$', '') }; $.ajax({ url: 'http://localhost:57571/api/Carts/' + cart.Id, type: "PUT", contentType: "application/json", dataType: "json", data: JSON.stringify(cart), ...