Exemplo n.º 1
0
        public async Task <IActionResult> Put(string id, [FromBody] UpdateBeerDto update)
        {
            if (Guid.TryParse(id, out Guid consumeId))
            {
                var beer = await _beersService.Get(consumeId);

                if (beer != null)
                {
                    beer.Title      = update.Title;
                    beer.TypeId     = update.TypeId;
                    beer.NonAlcohol = update.NonAlcohol;
                    beer.Volume     = update.Volume;

                    bool increased = await _beersService.Update(beer);

                    return(new OkObjectResult(increased));
                }
                else
                {
                    beer = new Beer();

                    beer.Id         = Guid.NewGuid();
                    beer.TypeId     = update.TypeId;
                    beer.Title      = update.Title;
                    beer.NonAlcohol = update.NonAlcohol;
                    beer.Volume     = update.Volume;

                    bool increased = await _beersService.Update(beer);

                    return(new OkObjectResult(increased));
                }
            }

            return(new OkObjectResult(false));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Put(string beerId, [FromBody] UpdateBeerDto updateBeer)
        {
            if (Guid.TryParse(beerId, out Guid id))
            {
                var beer = await _beersService.Get(id);

                if (beer == null)
                {
                    return(NotFound());
                }
                else
                {
                    beer.Title         = updateBeer.Title;
                    beer.NonAlcohol    = updateBeer.NonAlcohol;
                    beer.Volume        = updateBeer.Volume;
                    beer.DrankQuantity = updateBeer.DrankQuantity;

                    var increased = await _beersService.Update(beer);

                    return(new OkObjectResult(increased));
                }
            }

            return(NotFound());
        }
Exemplo n.º 3
0
 public UpdateBeerCommand(UpdateBeerDto beerDto, int requestId) => (Dto, BeerId) = (beerDto, requestId);