public async Task HandleAsync(T eEvent) { if (eEvent is IDontRequireCart) { return; } var result = await ErrorSafe.WithLogger(logger).ExecuteAsync(() => restClient .For($"{settings.Value.BaseUrl}/cart/{0}", "userid") .Timeout(1000) .GetAsync <IEnumerable <CartItemDto> >()); provider.Set(new CartDto(result.Value?.Output)); }
public async Task HandleAsync(AddItemToCart command) { var product = await _productRepository.GetAsync(command.ProductId); if (product == null) { throw new ArgumentException($"Product with id: '{command.ProductId}' was not found.", nameof(command.ProductId)); } var cart = _cartProvider.Get(command.UserId) ?? new Cart(command.UserId); cart.AddItem(product, command.Quantity); _cartProvider.Set(cart); await Task.CompletedTask; }
public async Task AddItemAsync(Guid userId, Guid productId, int quantity) { var product = await _productRepository.GetAsync(productId); if (product == null) { throw new ArgumentException($"Product with id: '{productId}' was not found.", nameof(productId)); } var cart = _cartProvider.Get(userId) ?? new Cart(userId); cart.AddItem(product, quantity); _cartProvider.Set(cart); await Task.CompletedTask; }