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
What would you like to do?
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