May 2018
Intermediate to advanced
334 pages
7h 25m
English
Inserting data into the cart table can be done by calling the POST action, which should look like the following code block in CartsController:
// POST: api/Carts[HttpPost]public async Task<IActionResult> PostCart([FromBody] Cart cart){ if (!ModelState.IsValid) { return BadRequest(ModelState); } _context.Cart.Add(cart); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (CartExists(cart.Id)) { return new StatusCodeResult(StatusCodes.Status409Conflict); } else { throw; } } return CreatedAtAction("GetCart", new { id = cart.Id }, cart);}
The client-side function to call this action can be designed as follows:
function PostCart(customerId, productId, qty, finalPrice) { var cart = { Customerid: customerId, ...