Beispiel #1
0
        public async Task <IngredientDto> GetOrCreate(string name)
        {
            var ingredient = await Repository.GetByName(name);

            if (ingredient == null)
            {
                var newIngredient = new Ingredient
                {
                    Name = name
                };

                Repository.Add(newIngredient);

                await DbContextProvider.SaveChangesAsync();

                ingredient = await Repository.GetSingle(newIngredient.Id);
            }

            var ingredientDto = DtoMapper.ToDto(ingredient);

            return(ingredientDto);
        }