public async Task <IActionResult> EditBeersQuantityOfWholesaler(int wholesalerId, int beerId, [FromBody] DTOs.UpdateStock updateBeer)
        {
            var wholesaler = await _repository.ReadAsync(wholesalerId);

            if (wholesaler == null)
            {
                return(NotFound());
            }

            var newBeer = updateBeer.Clone().SetBeerId(beerId);
            var beer    = await _beerRepository.ReadAsync(newBeer.BeerId);

            if (beer == null)
            {
                return(NotFound());
            }

            await BusinessRequirements.EnsureBeersAreSoldByWholesalerAsync(wholesalerId, new List <DTOs.Stock> {
                newBeer
            }, _repository);

            await BusinessRequirements.EnsureQuantitiesAreNotGreaterThanStockAsync(wholesalerId, new List <DTOs.Stock> {
                newBeer
            }, _repository);

            wholesaler.AddQuantity(-1 * newBeer.Quantity, beer);
            await _repository.SaveChangesAsync();

            return(NoContent());
        }
Beispiel #2
0
        public void ThrowBusinessExceptionBeerNotSoldByWholesaler()
        {
            var wholesalerId = 1;
            var sut          = _order.OrderDetails = new List <Stock>
            {
                new Stock {
                    BeerId = 6, Quantity = 1
                }
            };
            var wholesalerRepo = new WholesalerRepository(_context, null);

            Assert.That(() => BusinessRequirements.EnsureBeersAreSoldByWholesalerAsync(wholesalerId, sut, wholesalerRepo),
                        Throws.TypeOf <BusinessException>().With.Message.EqualTo("BEER_NOT_SOLD_BY_WHOLESALER")
                        );
        }