Skip to content

Instantly share code, notes, and snippets.

Last active November 16, 2022 23:10
  • 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/c6c59c5fb8e526662f9bdd39a0663f91 to your computer and use it in GitHub Desktop.
public async Task TransferBasketAsync(string anonymousId, string userName)
Guard.Against.NullOrEmpty(anonymousId, nameof(anonymousId));
Guard.Against.NullOrEmpty(userName, nameof(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