コード例 #1
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));
        }