public async Task <IActionResult> AddBeerToWholesaler(int wholesalerId, [FromBody] DTOs.Stock newBeer) { var wholesaler = await _repository.ReadAsync(wholesalerId); if (wholesaler == null) { return(NotFound()); } var beer = await _beerRepository.ReadAsync(newBeer.BeerId); if (beer == null) { return(NotFound()); } await BusinessRequirements.EnsureBeersAreNotSoldByWholesalerAsync(wholesalerId, new List <DTOs.Stock> { newBeer }, _repository); wholesaler.AddStock(newBeer.Quantity, beer); await _repository.SaveChangesAsync(); return(NoContent()); }
public async Task <IActionResult> GetById(int id) { var entity = await _repository.ReadAsync(id); if (entity is null) { return(NotFound()); } return(Ok(Mapper.Map <DTOs.Beer>(entity))); }