public async Task <IActionResult> Import([FromBody] RecipeImportRequest request) { var recipe = ToRecipe(request); await _recipeRepository.InsertAsync(recipe); var response = _mapper.Map <RecipeResponseContract>(recipe); return(Ok(response)); }
private Recipe ToRecipe(RecipeImportRequest request) { var ingredients = request.IngredientList .Split('\n', StringSplitOptions.RemoveEmptyEntries) .Select(_ingredientParser.Parse) .ToArray(); var instructions = request.InstructionList .Split('\n', StringSplitOptions.RemoveEmptyEntries); return(new Recipe { Id = Guid.NewGuid().ToString(), Name = request.Name, Ingredients = ingredients, Instructions = instructions, Servings = request.Servings, Preparation = TimeSpan.FromMinutes(request.Preparation) }); }