예제 #1
0
        public async Task Create(Recipe recipe, IFormFile RecipeImage)
        {
            recipe.LastViewed = DateTime.Now;

            Image image = new Image()
            {
                DataUrl = GetImage(recipe.Name)
            };

            image.Recipes.Add(recipe);

            using MealPlannerContext context = new MealPlannerContext(_dbOptions);
            if (RecipeImage != null)
            {
                using var stream = new MemoryStream();
                RecipeImage.CopyTo(stream);
                Image recipeImage = new Image()
                {
                    Data = stream.ToArray()
                };
                recipeImage.RecipeLists.Add(recipe);
                context.Images.Add(recipeImage);
            }

            context.Images.Add(image);
            context.Add(recipe);
            await context.SaveChangesAsync();
        }
예제 #2
0
        public async Task CreateIngredient(Ingredient ingredient)
        {
            using MealPlannerContext context = new MealPlannerContext(_dbOptions);
            ingredient.Order = await GetMaxOrder() + 1;

            context.Add(ingredient);
            await context.SaveChangesAsync();
        }
예제 #3
0
        public async Task <IActionResult> Create([Bind("Title,Description,PrepTime,CookTime,Calories,NumServings,Course,Cuisine,Author,Ingredients_Quantity,Ingredients_Unit,Ingredient,Id,TotalTime")] Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                _context.Add(recipe);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }