Skip to content

Instantly share code, notes, and snippets.

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
You can’t perform that action at this time.