コード例 #1
0
        public Beer CreateBeer(Beer beer)
        {
            if (beer != null)
            {
                Validator.ValidateBeer(beer);

                if (TypeRepository.ReadTypeById(beer.Type.ID) == null)
                {
                    throw new InvalidOperationException("No type with such ID found");
                }
                if (BrandRepository.ReadBrandById(beer.Brand.ID) == null)
                {
                    throw new InvalidOperationException("No brand with such ID found");
                }
                return(BeerRepository.AddBeer(beer));
            }
            return(null);
        }
コード例 #2
0
 public void AddNewBeer(Beers beer)
 {
     _beerRepository.AddBeer(beer);
     _beerRepository.Save();
 }
コード例 #3
0
 public IActionResult Post(Beer beer)
 {
     _beerRepository.AddBeer(beer);
     return(CreatedAtAction("Get", new { id = beer.Id }, beer));
 }