Exemplo n.º 1
0
        public Beer Add(AddBeerCommand command)
        {
            var brewer = _context.Brewers.SingleOrDefault(brewer => brewer.Id == command.BrewerId);

            if (brewer == null)
            {
                throw new CustomBadRequestException("Brewer does not exist");
            }

            var beer = new Beer
            {
                AlcoholLevel = command.AlcoholLevel,
                Name         = command.Name,
                Price        = command.Price,
                IsActive     = true,
                Brewer       = brewer
            };

            _context.Beers.Add(beer);
            _context.SaveChanges();

            return(beer);
        }
Exemplo n.º 2
0
        public ActionResult <GetBeer> Add([FromBody] AddBeerCommand command)
        {
            var beer = _beerService.Add(command);

            return(CreatedAtAction(nameof(GetById), new { id = beer.Id }, _mapper.Map <GetBeer.Beer>(beer)));
        }