Beispiel #1
0
        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);
        }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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)));
        }