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); }
public void Do(BasketId basketId) { BasketDTO basket = _basketRepository.Get(basketId.ConsumerId, basketId.Id); if (basket != null) { _basketRepository.Delete(basketId.ConsumerId, basketId.Id); } }
private void BasketIsDeleted() { A.CallTo(() => _basketRepository.Delete(_consumerId, _basketId)) .MustHaveHappened(); }
public void Delete(Basket entity) { _repo.Delete(entity); }