Example #1
0
 //filtrowanie listy przepisow wedlug wyszukiwanej nazwy
 private void Search()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes.Where(x => x.Title.ToUpper().Contains(SearchTxt.ToUpper())));
     }
 }
Example #2
0
    //Dodawanie nowego skladnika do listy
    private void AddIngredient()
    {
        var ingredient = new Ingredient();

        ingredient.Name = IngredientNameTxt;
        if (IngredientNameTxt == null || IngredientNameTxt == "")
        {
            MessageBox.Show("Uzupełnij nazwę składnika");
            return;
        }
        try
        {
            ingredient.Quantity = double.Parse(IngredientQuantityTxt);
        }
        catch (Exception)
        {
            return;
        }

        using (var contex = new CookingBookEntities1())
        {
            ingredient.TypeID = contex.QuantityTypes.Where(x => x.Name == SelectedQuantityCB).First().ID;
        }

        IngredientList.Add(ingredient);
        IngredientNameTxt     = null;
        IngredientQuantityTxt = null;
    }
Example #3
0
 //wyswietlenie wszystkiech pzrepisow
 private void ShowAll()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes);
     }
 }
Example #4
0
 //Wyswietlenie dan glownych
 private void ShowMainDish()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes.Where(x => x.RecipeCategory.Name == "Danie glowne"));
     }
 }
Example #5
0
 //Wyswietlenie zup
 private void ShowSoup()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes.Where(x => x.RecipeCategory.Name == "Zupa"));
     }
 }
Example #6
0
 //wyswietlenie sniadan
 private void ShowBreakfast()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes.Where(x => x.RecipeCategory.Name == "Sniadanie"));
     }
 }
Example #7
0
 //odswiezenie listy przepisow
 public void Refresh()
 {
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes);
     }
 }
Example #8
0
    //Dodawanie nowego przepisu do bazy
    private void AddRecipe()
    {
        if (DescriptionTxt == null || TitleTxt == null || DescriptionTxt == "" || TitleTxt == "") //jeżeli pola opis lub nazwa przepisu są puste
        {
            MessageBox.Show("Uzupełnij puste pola.");
            return;
        }

        if (AuthorTxt == null || AuthorTxt == "") //jeżeli pole autor jest puste
        {
            MessageBoxResult dialogResult = MessageBox.Show("Czy chcesz dodać przepis bez autora?", "Dodawanie przepisu", MessageBoxButton.YesNo);
            if (dialogResult == MessageBoxResult.Yes)
            {
                AuthorTxt = "Anonimowy";
            }
            else
            {
                return;
            }
        }

        if (IngredientList.Count == 0) //jeżeli lista składników = 0
        {
            MessageBoxResult dialogResult = MessageBox.Show("Czy na pewno chcesz dodać przepis nie zawierający składników?", "Dodawanie przepisu", MessageBoxButton.YesNo);
            if (dialogResult == MessageBoxResult.No)
            {
                return;
            }
        }

        using (var contex = new CookingBookEntities1()) //dodawanie przepisu
        {
            Recipe newRecipe = new Recipe();
            newRecipe.Description      = DescriptionTxt;
            newRecipe.Title            = TitleTxt;
            newRecipe.Ingredients      = IngredientList;
            newRecipe.RecipeCategoryID = contex.RecipeCategories.Where(n => n.Name == selectedCategoryCB.Name).First().ID;
            long AuthorID = GetAuthorID();
            if (AuthorID == -1) //jeżeli autor nie istnieje
            {
                Author author = new Author();
                author.Name = AuthorTxt;
                contex.Authors.Add(author);
                newRecipe.Author = author;
            }
            else
            {
                newRecipe.AuthorID = AuthorID;
            }
            contex.Recipes.Add(newRecipe);
            contex.SaveChanges();
            MessageBox.Show("Dodano nowy przepis.");
            ClearPage();
        }
    }
Example #9
0
 //Pobieranie ID autora według nazwy, jeśli nie istnieje zwraca -1
 private long GetAuthorID()
 {
     using (var contex = new CookingBookEntities1())
     {
         try
         {
             return(contex.Authors.Where(x => x.Name == this.AuthorTxt).First().ID);
         }
         catch
         {
             return(-1);
         }
     }
 }
Example #10
0
 //Wypelnianie pol strony danymi do edycji
 public void Fill(long id)
 {
     using (var contex = new CookingBookEntities1())
     {
         var recipe = contex.Recipes.Where(x => x.ID == id).FirstOrDefault();
         TitleTxt = recipe.Title;
         SelectedCategoryIndex = contex.RecipeCategories.ToList().IndexOf(recipe.RecipeCategory);
         SelectedCategoryCB    = recipe.RecipeCategory;
         IngredientList        = new ObservableCollection <Ingredient>(recipe.Ingredients);
         DescriptionTxt        = recipe.Description;
         AuthorTxt             = recipe.Author.Name;
         IsEdit   = true;
         IsAdd    = false;
         RecipeID = recipe.ID;
     }
 }
Example #11
0
    //usuwanie wyswietlanego przepisu
    private void Delete()
    {
        MessageBoxResult dialogResult = MessageBox.Show("Czy na pewno chcesz usunąć przepis?", "Usuwanie przepisu", MessageBoxButton.YesNo);

        if (dialogResult == MessageBoxResult.Yes)
        {
            using (var contex = new CookingBookEntities1())
            {
                contex.Recipes.Remove(contex.Recipes.Where(x => x.ID == id).First());
                contex.Ingredients.RemoveRange(contex.Ingredients.Where(x => x.RecipeID == id));
                contex.SaveChanges();
                SharedVM.MainVM.Home();
                MessageBox.Show("Przepis został usunięty.");
            }
        }
    }
Example #12
0
 public AddRecipePageViewModel()
 {
     IngredientList      = new ObservableCollection <Ingredient>();
     AddIngredientCmd    = new RelayCommand(x => AddIngredient());
     DeleteIngredientCmd = new RelayCommand(DeleteIngredient);
     AddRecipeCmd        = new RelayCommand(x => AddRecipe());
     EditRecipeCmd       = new RelayCommand(x => EditRecipe());
     using (var contex = new CookingBookEntities1())
     {
         CategoriesCB          = new ObservableCollection <RecipeCategory>(contex.RecipeCategories);
         SelectedCategoryCB    = contex.RecipeCategories.First();
         SelectedCategoryIndex = 0;
         QuantityCB            = new ObservableCollection <string>(contex.QuantityTypes.Select(x => x.Name));
         SelectedQuantityCB    = contex.QuantityTypes.Select(x => x.Name).First();
     }
     OnPropertyChanged("IngredientNameTxt");
 }
Example #13
0
 public ShowRecipePageViewModel(long recipeID)
 {
     using (var contex = new CookingBookEntities1())
     {
         id                = recipeID;
         SelectedRecipe    = contex.Recipes.Where(x => x.ID == recipeID).FirstOrDefault();
         RecipeTitle       = SelectedRecipe.Title;
         RecipeDescription = SelectedRecipe.Description;
         EditRecipeCmd     = new RelayCommand(x => Edit());
         DeleteRecipeCmd   = new RelayCommand(x => Delete());
         foreach (var item in SelectedRecipe.Ingredients)
         {
             RecipeIngredients += "•  " + item.ToString() + "\n";
         }
         setQRData();
     }
 }
Example #14
0
 public HomePageViewModel()
 {
     EditCmd = new RelayCommand(x => Edit());
     ShowCmd = new RelayCommand(x => Show());
     DeleteCmd = new RelayCommand(x => Delete());
     SearchCmd = new RelayCommand(x => Search());
     SoupCmd = new RelayCommand(x => ShowSoup());
     DessertCmd = new RelayCommand(x => ShowDessert());
     MainDishCmd = new RelayCommand(x => ShowMainDish());
     BreakfastCmd = new RelayCommand(x => ShowBreakfast());
     OtherCmd = new RelayCommand(x => ShowOther());
     AllRecipesCmd = new RelayCommand(x => ShowAll());
     using (var contex = new CookingBookEntities1())
     {
         RecipeList = new ObservableCollection<Recipe>(contex.Recipes);
     }
 }
Example #15
0
 //wyswietlanie listy przepisow spelniajacych kryteria wyszukiwania
 private void Search()
 {
     using (var contex = new CookingBookEntities1())
     {
         if (SelectedTitle)
         {
             RecipeList = new ObservableCollection <Recipe>(contex.Recipes.Where(x => x.Title.ToUpper().Contains(SearchTxt.ToUpper())));
         }
         else if (SelectedAuthor)
         {
             RecipeList = new ObservableCollection <Recipe>(contex.Recipes.Where(x => x.Author.Name.ToUpper().Contains(SearchTxt.ToUpper())));
         }
         else if (SelectedIngredient)
         {
             RecipeList = new ObservableCollection <Recipe>(contex.Recipes.Where(x => x.Ingredients.Any(v => v.Name.ToUpper().Contains(SearchTxt.ToUpper()))));
         }
     }
 }
Example #16
0
    //usuwanie przepisu z listy
    private void Delete()
    {
        if (SharedVM.HomeVM.SelectedRecipe == null)
        {
            MessageBox.Show("Nie wybrano żadnego przepisu.");
            return;
        }

        MessageBoxResult dialogResult = MessageBox.Show("Czy na pewno chcesz usunąć przepis?", "Usuwanie przepisu", MessageBoxButton.YesNo);
        if (dialogResult == MessageBoxResult.Yes)
        {
            using (var contex = new CookingBookEntities1())
            {
                contex.Recipes.Remove(contex.Recipes.Where(x => x.ID == SelectedRecipe.ID).First());
                contex.Ingredients.RemoveRange(contex.Ingredients.Where(x => x.RecipeID == SelectedRecipe.ID));
                contex.SaveChanges();

                RecipeList.Remove(SelectedRecipe);
            }
        }
    }
Example #17
0
    //Dodanie do bazy zedytowanego przepisu
    private void EditRecipe()
    {
        if (DescriptionTxt == "" || TitleTxt == "") //jeżeli pola opis lub nazwa są puste
        {
            MessageBox.Show("Uzupełnij puste pola.");
            return;
        }

        if (AuthorTxt == "") //jeżeli pole autor jest puste
        {
            MessageBoxResult dialogResult = MessageBox.Show("Czy chcesz dodać przepis bez autora?", "Dodawanie przepisu", MessageBoxButton.YesNo);
            if (dialogResult == MessageBoxResult.Yes)
            {
                AuthorTxt = "Anonimowy";
            }
            else
            {
                return;
            }
        }

        if (IngredientList.Count == 0) //jeżeli lista składników jest pusta
        {
            MessageBoxResult dialogResult = MessageBox.Show("Czy na pewno chcesz dodać przepis nie zawierający składników?", "Dodawanie przepisu", MessageBoxButton.YesNo);
            if (dialogResult == MessageBoxResult.No)
            {
                return;
            }
        }

        using (var contex = new CookingBookEntities1()) //edycja przepisu
        {
            Recipe original = contex.Recipes.Find(RecipeID);

            if (original != null)
            {
                original.Description = DescriptionTxt;
                original.Title       = TitleTxt;
                contex.Ingredients.RemoveRange(original.Ingredients); //usunięcie wszystkich składników
                foreach (var item in IngredientList)                  //zapisanie nowej listy składników
                {
                    item.Recipe = original;
                    contex.Ingredients.Add(item);
                }
                original.RecipeCategoryID = SelectedCategoryCB.ID;
                long AuthorID = GetAuthorID();
                if (AuthorID == -1) //jeżeli autor nie istnieje
                {
                    Author author = new Author();
                    author.Name = AuthorTxt;
                    contex.Authors.Add(author);
                    original.Author = author;
                }
                else
                {
                    original.AuthorID = AuthorID;
                }
                contex.SaveChanges();
                MessageBox.Show("Przepis został zedytowany");
                ClearPage();
                SharedVM.MainVM.Home();
            }
        }
    }