Exemplo n.º 1
0
 void ExcludedIngredientsRemoveAt(int index)
 {
     ExcludedIngredients.RemoveAt(index);
     if (!InSearchWindow)
     {
         ExcludedIngredientModels.RemoveAt(index);
         Sorting.ResizeListView(ListView_excludedIngredients, ExcludedIngredients.Count);
     }
     SaveExcludedIngredients(ExcludedIngredients);
 }
Exemplo n.º 2
0
        public void addToExcludedIngredients(int ingredientID, int userID)
        {
            ExcludedIngredients excludedIngredients = new ExcludedIngredients();

            excludedIngredients.ingredientID = ingredientID;
            excludedIngredients.userID       = userID;
            _context.ExcludedIngredients.Add(excludedIngredients);
            _context.SaveChanges();
            //return new CreatedResult($"/api/recipe/{excludedIngredients.userID}/{excludedIngredients.ingredientID}", excludedIngredients);
        }
Exemplo n.º 3
0
 void ExcludedIngredientsAdd(IngredientDtoV2 ingredient)
 {
     ingredient.Role = IngredientRole.Exclude;
     ExcludedIngredients.Insert(0, ingredient);
     if (!InSearchWindow)
     {
         Sorting.ResizeListView(ListView_excludedIngredients, ExcludedIngredients.Count);
         ExcludedIngredientModels.Insert(0, new IngredientListModel()
         {
             Ingredient = ingredient
         });
     }
     SaveExcludedIngredients(ExcludedIngredients);
 }
Exemplo n.º 4
0
        // --------------------------------------------- EVENTS ---------------------------------------------------


        // Klicked ingredient in search window
        private void ListView_SearchIngredients_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (ListView_SearchIngredients.SelectedItem == null)
            {
                return;
            }

            int index = ((ObservableCollection <IngredientListModel>)ListView_SearchIngredients.ItemsSource).IndexOf((IngredientListModel)e.SelectedItem);

            ((ListView)sender).SelectedItem = null;
            IngredientDtoV2 selectedIngredient = SearchIngredients[index];

            SearchIngredientModels[index] = new IngredientListModel()
            {
                Ingredient = SearchIngredientModels[index].Ingredient,
                IsAdded    = !SearchIngredientModels[index].IsAdded,
                AddedColor = SearchIngredientModels[index].AddedColor,
                AddedIcon  = SearchIngredientModels[index].AddedIcon
            };

            if (SearchModeIncluded)
            {
                if (MyIngredients.Any(p => p.IngredientId == selectedIngredient.IngredientId))
                {
                    MyIngredientsRemoveAt(MyIngredients.FindIndex(p => p.IngredientId == selectedIngredient.IngredientId));
                }

                else
                {
                    MyIngredientsAdd(selectedIngredient);
                }
            }
            else
            {
                if (ExcludedIngredients.Any(p => p.IngredientId == selectedIngredient.IngredientId))
                {
                    ExcludedIngredientsRemoveAt(ExcludedIngredients.FindIndex(p => p.IngredientId == selectedIngredient.IngredientId));
                }

                else
                {
                    ExcludedIngredientsAdd(selectedIngredient);
                }
            }
        }
Exemplo n.º 5
0
        // --------------------------------------------- REQUESTS ---------------------------------------------------


        // Recive ingredentDtos from the server and update lists
        async void GET_ingredientDtos(string search)
        {
            bool isLoading = true;

            ActivityIndicator_Ingredients.IsRunning = true;
            await Task.Factory.StartNew(() => SearchIngredients = ingredientsSearching.Search(search, out isLoading));

            SearchIngredientModels.Clear();

            if (SearchModeIncluded)
            {
                foreach (var ingredient in SearchIngredients)
                {
                    SearchIngredientModels.Add(new IngredientListModel()
                    {
                        Ingredient = ingredient,
                        IsAdded    = (MyIngredients.Any(p => p.IngredientId == ingredient.IngredientId)) ? true : false
                    });
                }
            }
            else
            {
                foreach (var ingredient in SearchIngredients)
                {
                    SearchIngredientModels.Add(new IngredientListModel()
                    {
                        Ingredient = ingredient,
                        IsAdded    = (ExcludedIngredients.Any(p => p.IngredientId == ingredient.IngredientId)) ? true : false,
                        AddedIcon  = Constants.ExcludeIngredientCheckIcon,
                        AddedColor = Color.Red
                    });
                }
            }

            if (!isLoading)
            {
                ActivityIndicator_Ingredients.IsRunning = false;
            }
        }
Exemplo n.º 6
0
 public IActionResult Add([FromBody] ExcludedIngredients excludedIngredients)
 {
     _context.ExcludedIngredients.Add(excludedIngredients);
     _context.SaveChanges();
     return(new CreatedResult($"/api/recipe/{excludedIngredients.userID}/{excludedIngredients.ingredientID}", excludedIngredients));
 }