public async Task <IActionResult> PostAsync([FromBody] IngredientInputResource resource) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var result = await this.ingredientsService.AddAsync(resource); if (!result.Success) { return(BadRequest(result.Message)); } return(Ok(result.Ingredient)); }
public async Task <IngredientResponse> AddAsync(IngredientInputResource resource) { try { var ingredient = this.mapper.Map <IngredientInputResource, Ingredient>(resource); await this.ingredientsRepository.AddAsync(ingredient); var ingredientResource = this.mapper.Map <Ingredient, IngredientResource>(ingredient); return(new IngredientResponse(ingredientResource)); } catch (Exception ex) { //TODO: Log errors return(new IngredientResponse(string.Format(GlobalConstants.AddIngredientErrorMessage, ex.Message))); } }