public async Task <IActionResult> ModifyRecipe(int id, [FromBody] CollectionRecipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var collection = await db.Collections.FindAsync(recipe.CollectionID);

            if (collection == null)
            {
                ModelState.AddModelError("Collection ID", $"Collection {recipe.CollectionID} does not exist");
                return(BadRequest(ModelState));
            }

            var recipeOld = await db.Recipes.FindAsync(id);

            if (recipeOld == default(CollectionRecipe))
            {
                return(NotFound());
            }
            else
            {
                recipeOld.Name         = recipe.Name;
                recipeOld.CollectionID = recipe.CollectionID;
                recipeOld.RecipeID     = recipe.RecipeID;
                db.Update(recipeOld);
                db.SaveChanges();
                recipe.ID = recipeOld.ID;
                return(Ok(recipe));
            }
        }
Exemple #2
0
        protected void ShowAll(string name, string category)
        {
            CollectionRecipe dishes = new CollectionRecipe();

            Dishes dishesBL = new Dishes(category);

            dishes = dishesBL.ShowAllName();

            Console.WriteLine(name + ", plase write number of " + category + " to see all information");
            Console.WriteLine();

            for (int i = 0; i < dishes.ListRecipe.Count; i++)
            {
                Console.WriteLine(i + 1 + " : " + dishes.ListRecipe[i].Name);
            }
            int choice = Convert.ToInt32(Console.ReadLine());


            if (choice < 0 || choice > dishes.ListRecipe.Count)
            {
                Console.WriteLine("incorrect input");
            }
            else
            {
                ShowRecipe(name, category, choice - 1);
            }
        }
Exemple #3
0
        public async Task <IActionResult> AddToCollection(AddToCollectionViewModel atcvm)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            var member = await _context.Members.SingleOrDefaultAsync(m => m.User == user);

            if (member == null)
            {
                throw new ApplicationException("Failed to find member");
            }

            CollectionRecipe cr = new CollectionRecipe {
                CollectionID = atcvm.ChoiceID, RecipeID = atcvm.RecipeID
            };

            _context.Add(cr);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Display), new { id = atcvm.RecipeID }));
        }
Exemple #4
0
        private int GetLastIdCategory(string path)
        {
            JsonDishRepository dishRepository   = new JsonDishRepository();
            CollectionRecipe   collectionRecipe = new CollectionRecipe();

            collectionRecipe = dishRepository.Read(path);

            int buf = collectionRecipe.ListRecipe.Count - 1;

            return(collectionRecipe.ListRecipe[buf].Id);
        }
        public Recipe ShowOneRecipe(int choise)
        {
            JsonDishRepository fileWork      = new JsonDishRepository();
            CollectionRecipe   collectionBuf = new CollectionRecipe();

            collectionBuf = fileWork.Read(path);

            if (choise < 0 || choise > collectionBuf.ListRecipe.Count)
            {
                throw new Exception("invalid input in ShowOneRecipe.BL");
            }
            else
            {
                return(collectionBuf.ListRecipe[choise]);
            }
        }
        public CollectionRecipe ShowAllName()
        {
            JsonDishRepository fileWork      = new JsonDishRepository();
            CollectionRecipe   collectionBuf = new CollectionRecipe();
            CollectionRecipe   allName       = new CollectionRecipe();

            collectionBuf      = fileWork.Read(path);
            allName.ListRecipe = new List <Recipe>();

            for (int i = 0; i < collectionBuf.ListRecipe.Count; i++)
            {
                Recipe test = new Recipe();
                test.Name = collectionBuf.ListRecipe[i].Name;
                allName.ListRecipe.Add(test);
            }
            return(allName);
        }
        public async Task <IActionResult> AddRecipe([FromBody] CollectionRecipe recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var collection = await db.Collections.FindAsync(recipe.CollectionID);

            if (collection == null)
            {
                ModelState.AddModelError("Collection ID", $"Collection {recipe.CollectionID} does not exist");
                return(BadRequest(ModelState));
            }

            await db.Recipes.AddAsync(recipe);

            await db.SaveChangesAsync();

            return(Ok(recipe));
        }
        public bool AddRecipe(Recipe recipe)
        {
            Console.WriteLine(recipe.Ingredients.Values);
            Console.WriteLine(recipe.Ingredients.Keys);
            //возможность добавить проверки в будущем
            if (true)
            {
                CollectionRecipe   dishes         = new CollectionRecipe();
                JsonDishRepository jsonRepository = new JsonDishRepository();
                Id id = new Id(path);

                recipe.Id = id.id + 1;

                dishes = jsonRepository.Read(path);
                dishes.ListRecipe.Add(recipe);

                jsonRepository.Update(path, dishes);

                return(true);
            }
        }