Skip to content

Instantly share code, notes, and snippets.

Created November 10, 2016 00:36
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public async Task<IActionResult> AddToCart(int id, CancellationToken requestAborted)
// Retrieve the album from the database
var addedAlbum = await DbContext.Albums
.SingleAsync(album => album.AlbumId == id);
// Add it to the shopping cart
var cart = ShoppingCart.GetCart(DbContext, HttpContext);
await cart.AddToCart(addedAlbum);
await DbContext.SaveChangesAsync(requestAborted);
_logger.LogInformation("Album {albumId} was added to the cart.", addedAlbum.AlbumId);
// Go back to the main store page for more shopping
return RedirectToAction("Index");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment