Пример #1
0
        public async Task CreateSampleAsync(int userId, Dictionary <string, string> translations)
        {
            var now = DateTime.UtcNow;

            var recipe = new Recipe
            {
                UserId         = userId,
                Name           = translations["SampleRecipeName"],
                Description    = translations["SampleRecipeDescription"],
                Instructions   = translations["SampleRecipeInstructions"],
                PrepDuration   = TimeSpan.FromMinutes(10),
                CookDuration   = TimeSpan.FromMinutes(15),
                Servings       = 2,
                ImageUri       = _cdnService.GetDefaultRecipeImageUri(),
                LastOpenedDate = now,
                CreatedDate    = now,
                ModifiedDate   = now
            };

            recipe.RecipeIngredients = new List <RecipeIngredient>
            {
                new RecipeIngredient
                {
                    Amount       = 300,
                    Unit         = "g",
                    CreatedDate  = recipe.CreatedDate,
                    ModifiedDate = recipe.CreatedDate,
                    Ingredient   = new Ingredient
                    {
                        UserId       = userId,
                        Name         = translations["SampleRecipeIngredient1"],
                        CreatedDate  = recipe.CreatedDate,
                        ModifiedDate = recipe.CreatedDate
                    }
                },
                new RecipeIngredient
                {
                    Amount       = 300,
                    Unit         = "g",
                    CreatedDate  = recipe.CreatedDate,
                    ModifiedDate = recipe.CreatedDate,
                    Ingredient   = new Ingredient
                    {
                        UserId       = userId,
                        Name         = translations["SampleRecipeIngredient2"],
                        CreatedDate  = recipe.CreatedDate,
                        ModifiedDate = recipe.CreatedDate
                    }
                },
                new RecipeIngredient
                {
                    Amount       = 100,
                    Unit         = "g",
                    CreatedDate  = recipe.CreatedDate,
                    ModifiedDate = recipe.CreatedDate,
                    Ingredient   = new Ingredient
                    {
                        UserId       = userId,
                        Name         = translations["SampleRecipeIngredient3"],
                        CreatedDate  = recipe.CreatedDate,
                        ModifiedDate = recipe.CreatedDate
                    }
                }
            };

            await _recipesRepository.CreateAsync(recipe);
        }