public async Task <CartLineDto> AddCartLine(string customerId, CartLineForCreationDto cartLine, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrEmpty(customerId)) { throw new ArgumentNullException(nameof(customerId)); } var userCart = await GetUserCartEntity(customerId, cancellationToken); if (userCart == null) { userCart = new Cart { CustomerId = customerId }; _context.Add(userCart); } var result = userCart.AddCartLine(cartLine.Map(CartMapper.CartLineForCreationDtoToEntityFunc)); await _context.SaveChangesAsync(cancellationToken); var cartLineDto = result.Map(CartMapper.CartLineEntityToDto); if (cartLineDto != null && string.IsNullOrEmpty(cartLineDto.ProductName)) { cartLineDto.ProductName = cartLine.ProductName; } return(cartLineDto); }
public async Task <ActionResult <CartLineDto> > AdjustCartLine(CartLineForCreationDto cartLine, CancellationToken cancellationToken) { return(await _cartService.AddCartLine("CACTU", cartLine, cancellationToken)); }