/// <summary>
 /// Opens the Add ingredient amount to shopping basket window
 /// </summary>
 /// <param name="addIngrediwntOpen">Window that we open</param>
 /// <param name="ingredientEdit">ingredient that we are showing</param>
 public AddIngredientToBasketViewModel(AddIngredientAmountToRecipe addIngredientAmountOpen, tblIngredient ingredientEdit)
 {
     ItemAmount = new tblShoppingBasket();
     addIngredientAmountToShoppingBasket = addIngredientAmountOpen;
     IngredientList = ingrediantsData.GetAllIngredients().ToList();
     Ingredient     = ingredientEdit;
 }
        public int Insert()
        {
            // Create result variable for this method (int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // Create new instance of tblIngredient
                    tblIngredient ingredient = new tblIngredient();

                    ingredient.in_Id = 1;
                    if (dc.tblIngredients.Any())
                    {
                        ingredient.in_Id = dc.tblIngredients.Max(i => i.in_Id) + 1;
                    }
                    this.Id = ingredient.in_Id;
                    ingredient.in_Description = this.Description;
                    dc.tblIngredients.Add(ingredient);
                    result = dc.SaveChanges();
                    return(result);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        public int Update()
        {
            // Create result variable for this method(int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // If ingredient is selected, update the description. Otherwise, throw an exception.
                    tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == this.Id).FirstOrDefault();
                    if (ingredient != null)
                    {
                        ingredient.in_Description = this.Description;
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 /// <summary>
 /// Opens the Add ingredient to Shopping Basket window
 /// </summary>
 /// <param name="addIngredientOpen">Window that we open</param>
 public AddIngredientToBasketViewModel(AddIngredientToRecipe addIngredientOpen)
 {
     ingredient            = new tblIngredient();
     addIngredientToRecipe = addIngredientOpen;
     IngredientList        = ingrediantsData.GetAllIngredients().ToList();
     IngrediantAmountList  = shoppingData.GetAllSelectedShoppingBasketItems(LoggedGuest.ID).ToList();
 }
Exemple #5
0
        /// <summary>
        /// Method to add or edit ingredient into db
        /// </summary>
        /// <param name="ingredient"></param>
        /// <returns></returns>
        public tblIngredient AddIngredient(tblIngredient ingredient)
        {
            try
            {
                using (RecipeKeeperEntities context = new RecipeKeeperEntities())
                {
                    if (ingredient.ingridientId == 0)
                    {
                        //add
                        tblIngredient newIng = new tblIngredient();
                        newIng.name     = ingredient.name;
                        newIng.quantity = ingredient.quantity;
                        newIng.recipeId = ingredient.recipeId;
                        context.tblIngredients.Add(newIng);
                        context.SaveChanges();
                        ingredient.ingridientId = newIng.ingridientId;
                        return(ingredient);
                    }
                    else
                    {
                        tblIngredient ingToEdit = (from x in context.tblIngredients where x.ingridientId == ingredient.ingridientId select x).FirstOrDefault();

                        ingToEdit.name     = ingredient.name;
                        ingToEdit.quantity = ingredient.quantity;
                        context.SaveChanges();
                        return(ingredient);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
                return(null);
            }
        }
 public AddIngredientsViewModel(AddIngredients addIngredientsOpen, tblRecipe recipeCreated)
 {
     addIngredientsView  = addIngredientsOpen;
     recipe              = recipeCreated;
     Ingredient          = new tblIngredient();
     ingredient.recipeId = recipeCreated.recipeId;
 }
        /// <summary>
        /// Adds an ingredient to the database
        /// </summary>
        /// <param name="ingredient">The ingredient ID we are adding or editing</param>
        /// <returns>The new or edited ingredient</returns>
        public tblIngredient AddIngredient(tblIngredient ingredient)
        {
            try
            {
                using (PizzaPanDBEntities context = new PizzaPanDBEntities())
                {
                    tblIngredient newIngredient = new tblIngredient
                    {
                        IngredientName  = ingredient.IngredientName,
                        IngredientPrice = ingredient.IngredientPrice,
                    };

                    context.tblIngredients.Add(newIngredient);
                    context.SaveChanges();
                    ingredient.IngredientID = newIngredient.IngredientID;

                    return(ingredient);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
        public int Delete(int id)
        {
            // Create result variable for this method(int)
            int result = 0;

            try
            {
                //Using connection string statement and creating new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // If ingredient is selected, delete the ingredient along with the Id associated with it. Otherwise, throw an exception.
                    tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == id).FirstOrDefault();
                    if (ingredient != null)
                    {
                        dc.tblIngredients.Remove(ingredient);
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #9
0
 /// <summary>
 /// This method add ingredient of recipe.
 /// </summary>
 /// <param name="ingredient">Ingredient to be added.</param>
 /// <returns>True if created, false if not.</returns>
 public bool AddIngredient(vwIngredient ingredientToAdd, out int ingredientId)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             tblIngredient ingredient = new tblIngredient
             {
                 IngredientName = ingredientToAdd.IngredientName,
                 Quantity       = ingredientToAdd.Quantity,
                 RecipeId       = ingredientToAdd.RecipeId
             };
             context.tblIngredients.Add(ingredient);
             context.SaveChanges();
             ingredientId = ingredient.IngredientId;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         ingredientId = 0;
         return(false);
     }
 }
 public EditIngredientsViewModel(EditIngredients editOpen, tblRecipe recipeForEdit)
 {
     editIngView         = editOpen;
     recipe              = recipeForEdit;
     Ingredient          = new tblIngredient();
     ingredient.recipeId = recipeForEdit.recipeId;
     IngredientList      = service.AllIngredientForRecipe(recipe.recipeId);
 }
Exemple #11
0
 public AddIngredientsViewModel(AddIngredientsView aiv, tblRecipe rec)
 {
     view            = aiv;
     Recipe          = rec;
     IngredientsList = ingredientService.GetAllIngredients();
     newIngredient   = new tblIngredient();
     Ingredient      = new tblIngredient();
 }
 public AddIngredientToRecipeWindowViewModel(AddIngredientToRecipeWindow addIngredientToRecipeWindow)
 {
     this.addIngredientToRecipeWindow = addIngredientToRecipeWindow;
     ingredient           = new tblIngredient();
     ItemAmount           = new tblShoppingBasket();
     IngredientList       = ingrediantsData.GetAllIngredients().ToList();
     IngrediantAmountList = shoppingData.GetAllSelectedShoppingBasketItems(LoggedGuest.ID).ToList();
 }
 /// <summary>
 /// Opens the Add ingredient to recipe window
 /// </summary>
 /// <param name="addIngredientOpen">Window that we open</param>
 public AddIngredientToRecipeViewModel(AddIngredientToRecipe addIngredientOpen, int recipeIDEdit)
 {
     ingredient            = new tblIngredient();
     addIngredientToRecipe = addIngredientOpen;
     IngredientList        = ingrediantsData.GetAllIngredients().ToList();
     RecipeID             = recipeIDEdit;
     IngrediantAmountList = recipeData.GetAllSelectedRecipeIngrediantAmount(recipeIDEdit).ToList();
 }
        /// <summary>
        /// Fills up the ingredients database
        /// </summary>
        /// <param name="list"></param>
        public void FillUpDatabase(List <string> list, List <string> price)
        {
            if (GetAllIngredients().Count == 0)
            {
                for (int i = 0; i < list.Count; i++)
                {
                    tblIngredient ing = new tblIngredient
                    {
                        IngredientName  = list[i],
                        IngredientPrice = price[i]
                    };

                    AddIngredient(ing);
                }
            }
        }
Exemple #15
0
 /// <summary>
 /// Print the appropriate message depending how the worker finished.
 /// </summary>
 /// <param name="sender">object sender</param>
 /// <param name="e">worker completed event</param>
 private void WorkerOnRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         progressBarInfoLabel = e.Error.Message;
         _isRunning           = false;
     }
     else
     {
         tblIngredient ing = ingredientData.FindIngredient(ShoppingBasket.IngredientID);
         allShoppingListWindow.Successfuly.Message.Content = "Uspesno izvrsena porudzbina sastojka " + ing.IngredientName.ToString();
         SnackSuccessfuly();
         ProgressBarVisibility = Visibility.Collapsed;
         ButtonVisibility      = Visibility.Visible;
     }
 }
Exemple #16
0
 /// <summary>
 /// This method deletes ingredient.
 /// </summary>
 /// <param name="ingredient">Ingredient to be deleted.</param>
 public bool DeleteIngredient(tblIngredient ingredient)
 {
     try
     {
         using (RecipeKeeperEntities context = new RecipeKeeperEntities())
         {
             tblIngredient ingredientToDelete = context.tblIngredients.Where(x => x.ingridientId == ingredient.ingridientId).FirstOrDefault();
             context.tblIngredients.Remove(ingredientToDelete);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Exemple #17
0
 /// <summary>
 /// This method edits data of ingredient.
 /// </summary>
 /// <param name="ingredientToEdit">Ingredient to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditIngredient(vwIngredient ingredientToEdit)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             tblIngredient ingredient = context.tblIngredients.Where(x => x.IngredientId == ingredientToEdit.IngredientId).FirstOrDefault();
             ingredient.IngredientName = ingredientToEdit.IngredientName;
             ingredient.Quantity       = ingredientToEdit.Quantity;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
 public void RemoveIngredientExecute()
 {
     try
     {
         if (Ingredient != null)
         {
             //invokes method to delete ingredient
             service.DeleteIngredient(Ingredient);
             //invokes method to update list of ingredients
             IngredientList      = service.AllIngredientForRecipe(Recipe.recipeId);
             Ingredient          = new tblIngredient();
             Ingredient.recipeId = Recipe.recipeId;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        /// <summary>
        /// Method for deleting the selected item from the list
        /// </summary>
        public void DeleteExecute()
        {
            tblIngredient ing = ingrediantsData.FindIngredient(ItemAmount.IngredientID);

            try
            {
                MessageBoxResult dialogDelete = Xceed.Wpf.Toolkit.MessageBox.Show($"Da li zelite da obrisete ovaj sastojak iz liste?\n\nSastojak: {ing.IngredientName}", "Obrisi sastojak", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                if (dialogDelete == MessageBoxResult.Yes)
                {
                    if (ItemAmount != null)
                    {
                        shoppingData.DeleteShoppingBasket(ItemAmount.ShoppingBasketID);
                        IngrediantAmountList = shoppingData.GetAllSelectedShoppingBasketItems(LoggedGuest.ID);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxResult dialog = Xceed.Wpf.Toolkit.MessageBox.Show("Trenutno je nemoguce obrisati sastojak..." + ex, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private List <tblIngredient> GetAllIngredients()
        {
            List <string> allIngredients = new List <string>();
            string        _location      = @"~/../../../ingredients.txt";

            try
            {
                if (File.Exists(_location))
                {
                    string[] allLines = File.ReadAllLines(_location);
                    foreach (string line in allLines)
                    {
                        if (line == "")
                        {
                            continue;
                        }
                        allIngredients.Add(line);
                    }
                }

                List <tblIngredient> realIngredients = new List <tblIngredient>();
                using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                {
                    foreach (string ing in allIngredients)
                    {
                        tblIngredient i = new tblIngredient();
                        i = db.tblIngredients.Where(ingr => ingr.IngredientName == ing).FirstOrDefault();
                        realIngredients.Add(i);
                    }
                }

                return(realIngredients);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                return(null);
            }
        }
        /// <summary>
        /// This method invokes method for adding ingredient to recipe.
        /// </summary>
        public void AddIngredientExecute()
        {
            if (String.IsNullOrEmpty(Ingredient.name) || String.IsNullOrEmpty(Ingredient.name.ToString()) || Ingredient.quantity == 0)
            {
                MessageBox.Show("Please fill all fields.", "Notification");
            }
            else
            {
                try
                {
                    service.AddIngredient(Ingredient);

                    //invokes method to update a list of ingredients
                    IngredientList      = service.AllIngredientForRecipe(Recipe.recipeId);
                    Ingredient          = new tblIngredient();
                    Ingredient.recipeId = Recipe.recipeId;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
 public void LoadById(int id)
 {
     try
     {
         //Using connection string statement and creating new instance of it
         using (ChefsCornerEntities dc = new ChefsCornerEntities())
         {
             tblIngredient ingredient = dc.tblIngredients.Where(i => i.in_Id == id).FirstOrDefault();
             if (ingredient != null)
             {
                 this.Id          = ingredient.in_Id;
                 this.Description = ingredient.in_Description;
             }
             else
             {
                 throw new Exception("Ingredient not found.");
             }
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemple #23
0
        /// <summary>
        /// Search if ingredient with that ID exists in the ingredient table
        /// </summary>
        /// <param name="id">Takes the id that we want to search for</param>
        /// <returns>The ingredient</returns>
        public tblIngredient FindIngredient(int id)
        {
            try
            {
                using (CakeRecipesDBEntities context = new CakeRecipesDBEntities())
                {
                    tblIngredient result = (from x in context.tblIngredients where x.IngredientID == id select x).FirstOrDefault();

                    if (result != null)
                    {
                        return(result);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception " + ex.Message.ToString());
                return(null);
            }
        }
 public AddIngredientAmountToRecipe(tblIngredient ingredient)
 {
     InitializeComponent();
     this.DataContext = new AddIngredientToBasketViewModel(this, ingredient);
 }
Exemple #25
0
        private void SaveExecute()
        {
            try
            {
                if (Milk == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Milk");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Sugar == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Sugar");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Mayo == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Mayonnaise");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Ketchup == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Ketchup");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Egg == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Egg");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Flour == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Flour");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Salt == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Salt");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Tomato == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Tomato");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Mushrooms == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Mushroom");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Cheese == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Cheese");
                    Recipe.tblIngredients.Add(ingredient);
                }
                if (Ham == true)
                {
                    tblIngredient ingredient = ingredientService.GetIngredientByName("Ham");
                    Recipe.tblIngredients.Add(ingredient);
                }

                IngredientsAdded = true;
                MessageBox.Show("Intgredients Choosed Successfully!");


                view.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
Exemple #26
0
 /// <summary>
 /// Opens the Add ingredient window
 /// </summary>
 /// <param name="addIngredientOpen">Window that we open</param>
 /// <param name="recipeID">recipe id</param>
 public AddIngredientViewModel(AddIngredient addIngredientOpen)
 {
     ingredient    = new tblIngredient();
     addIngredient = addIngredientOpen;
 }
 public AddIngredientAmountToRecipe(tblIngredient ingredient, int RecipeID)
 {
     InitializeComponent();
     this.DataContext = new AddIngredientToRecipeViewModel(this, ingredient, RecipeID);
 }
        /// <summary>
        /// Opens the Add ingredient to recipe window
        /// </summary>
        /// <param name="addIngrediwntOpen">Window that we open</param>

        public AddIngredientMenuViewModel(AddIngredientMenu addIngredientMenu)
        {
            this.addIngredientMenu = addIngredientMenu;
            ingredient             = new tblIngredient();
            IngredientList         = ingrediantsData.GetAllIngredients().ToList();
        }