public async Task <Beer> AddAsync(DTOs.Beer beer) { var brewery = await Context.Breweries.FirstOrDefaultAsync(br => br.Id == beer.BreweryId); var beerModel = await base.AddAsync(new Beer(beer.Name, beer.AlcoholLevel, beer.Price, brewery)); return(beerModel); }
public async Task <IActionResult> Post([FromBody] DTOs.CreateBeer beer, ApiVersion version = null) { if (version is null) { version = ApiVersion.Default; } await BusinessRequirements.EnsureBreweryExistsAsync(beer.BreweryId, _breweryRepository); DTOs.Beer newBeer = beer.Clone(); var entity = await _repository.AddAsync(newBeer); await _repository.SaveChangesAsync(); newBeer.Id = entity.Id; return(CreatedAtAction(nameof(GetById), new { id = newBeer.Id.ToString(), version = $"{version}" }, newBeer)); }
public Beer Add(DTOs.Beer beer) { var brewery = Context.Breweries.FirstOrDefault(br => br.Id == beer.BreweryId); return(base.Add(new Beer(beer.Name, beer.AlcoholLevel, beer.Price, brewery))); }