Skip to content

Instantly share code, notes, and snippets.

Created November 16, 2022 23:31
  • 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
Save dcomartin/1e1124a82be6185f4e2d474c1f424c72 to your computer and use it in GitHub Desktop.
public async Task TransferBasketAsync(Username anonymousId, Username userName)
var anonymousBasketSpec = new BasketWithItemsSpecification(anonymousId);
var anonymousBasket = await _basketRepository.GetBySpecAsync(anonymousBasketSpec);
if (anonymousBasket == null) return;
var userBasketSpec = new BasketWithItemsSpecification(userName);
var userBasket = await _basketRepository.GetBySpecAsync(userBasketSpec);
if (userBasket == null)
userBasket = new Basket(userName);
await _basketRepository.AddAsync(userBasket);
foreach (var item in anonymousBasket.Items)
userBasket.AddItem(item.CatalogItemId, item.UnitPrice, item.Quantity);
await _basketRepository.UpdateAsync(userBasket);
await _basketRepository.DeleteAsync(anonymousBasket);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment