public async Task <IActionResult> PostAsync(CreateBeerStyle beerStyle)
        {
            IActionResult result = null;

            try
            {
                var itemToAdd = _mapper.Map <BeerStyle>(beerStyle);
                await _context.BeerStyles.AddAsync(itemToAdd);

                await _context.SaveChangesAsync();

                result = CreatedAtAction(nameof(GetByIdAsync), new { id = itemToAdd.StyleId }, itemToAdd);
            }
            catch (Exception e)
            {
                result = BadRequest();
            }

            return(result);
        }
Beispiel #2
0
        public async Task <IActionResult> PostAsync(CreateBeerContainer container)
        {
            IActionResult result = null;

            try
            {
                var containerToCreate = _mapper.Map <BeerContainer>(container);
                await _context.BeerContainers.AddAsync(containerToCreate);

                await _context.SaveChangesAsync();

                result = CreatedAtAction("Get", new { id = containerToCreate.BeerContainerId }, containerToCreate);
            }
            catch (Exception e)
            {
                result = BadRequest();
            }

            return(result);
        }
        public async Task <IActionResult> Post(CreateCellarItem createCellarItemRequest)
        {
            IActionResult result = null;

            try
            {
                var cellarItem = _mapper.Map <CellarItem>(createCellarItemRequest);
                await _context.CellarItems.AddAsync(cellarItem);

                await _context.SaveChangesAsync();

                result = CreatedAtAction(nameof(GetById), new { id = cellarItem.CellarItemId }, cellarItem);
            }
            catch (Exception e)
            {
                result = BadRequest();
            }



            return(result);
        }