Exemplo n.º 1
0
        public async Task <IActionResult> PostAsync([FromBody] SaveCocktailResource resource)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.GetErrorMessages()));
            }
            var cocktail = _mapper.Map <SaveCocktailResource, Domain.Models.Cocktail>(resource);
            var result   = await _cocktailService.AddAsync(cocktail, resource.Ingredients);

            if (!result.Success)
            {
                return(BadRequest(result.Message));
            }

            var cocktailResource = _mapper.Map <Domain.Models.Cocktail, CocktailResource>(result.Cocktail);

            return(Ok(cocktailResource));
        }
Exemplo n.º 2
0
 public async Task SaveCocktail(SaveCocktailResource resource, List <Ingredient> ingredients)
 {
     var cocktail = _mapper.Map <SaveCocktailResource, Cocktails.Domain.Models.Cocktail>(resource);
     await _cocktailsService.AddAsync(cocktail, ingredients);
 }