public async Task <bool> Handle(AddItemToBasket request, CancellationToken cancellationToken) { var basket = await _context.Baskets .FirstOrDefaultAsync(x => x.GoodsId == request.GoodsId && x.UserId == request.UserId, cancellationToken : cancellationToken) .ConfigureAwait(false); if (!(await _goodsRepository.ExistAsync(x => x.Id == request.GoodsId)).Data) { throw new DomainException(ErrorType.GoodsDoesNotExist); } if (basket == null) { var item = request.ToModel(); _basketRepository.Create(item); } else { basket.Count += request.Count; } await _basketRepository.SaveAsync().ConfigureAwait(false); return(true); }