예제 #1
0
        public async Task <bool> Handle(DeleteItemFromBasket request, CancellationToken cancellationToken)
        {
            var basket =
                (await _basketRepository.FindAsync(x => x.GoodsId == request.GoodsId && x.UserId == request.UserId)).Data;

            if (basket == null)
            {
                throw new DomainException(ErrorType.BasketDoesNotExist);
            }

            if (basket.Count < request.Count)
            {
                throw new DomainException(ErrorType.BasketItemCountLessThenNeed);
            }

            if (basket.Count == request.Count)
            {
                _basketRepository.Delete(basket);
            }

            else
            {
                basket.Count -= request.Count;
                _basketRepository.Update(basket);
            }

            await _basketRepository.SaveAsync().ConfigureAwait(false);

            return(true);
        }
예제 #2
0
        public void Do(BasketId basketId)
        {
            BasketDTO basket = _basketRepository.Get(basketId.ConsumerId, basketId.Id);

            if (basket != null)
            {
                _basketRepository.Delete(basketId.ConsumerId, basketId.Id);
            }
        }
예제 #3
0
 private void BasketIsDeleted()
 {
     A.CallTo(() => _basketRepository.Delete(_consumerId, _basketId))
     .MustHaveHappened();
 }
예제 #4
0
 public void Delete(Basket entity)
 {
     _repo.Delete(entity);
 }