Created
November 18, 2016 01:58
-
-
Save dcomartin/27f049f897f137b53b19d4e1ebe38ac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AddToCartHandler : ICancellableAsyncRequestHandler<AddToCart, Unit> | |
{ | |
private readonly MusicStoreContext _dbContext; | |
public AddToCartHandler(MusicStoreContext dbContext) | |
{ | |
_dbContext = dbContext; | |
} | |
public async Task<Unit> Handle(AddToCart message, CancellationToken cancellationToken) | |
{ | |
// Retrieve the album from the database | |
var addedAlbum = await _dbContext.Albums | |
.SingleAsync(album => album.AlbumId == message.AlbumId, cancellationToken); | |
// Add it to the shopping cart | |
var cart = Models.ShoppingCart.GetCart(_dbContext, message.CartId); | |
await cart.AddToCart(addedAlbum); | |
await _dbContext.SaveChangesAsync(cancellationToken); | |
return Unit.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment