예제 #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);
        }
예제 #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));
        }
예제 #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)));
        }