Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created November 10, 2016 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/6845c25f7d4c9bc35ae9c5fb3dec3128 to your computer and use it in GitHub Desktop.
Save dcomartin/6845c25f7d4c9bc35ae9c5fb3dec3128 to your computer and use it in GitHub Desktop.
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