public bool recipeIngredients(object item)
        {
            recipe      = item as vwRecipe;
            ingredients = new List <string>();
            try
            {
                using (RecipesDBEntities context = new RecipesDBEntities())
                {
                    for (int i = 0; i < SearchIngredients.ingredientsToSearch.Count; i++)
                    {
                        ingredient = SearchIngredients.ingredientsToSearch[i];
                        ingredients.Add(ingredient);
                    }
                    List <string> ingredientsInRecipe = context.vwIngredients.Where(x => x.RecipeId == recipe.RecipeId).Select(x => x.IngredientName).ToList();

                    if (ingredients.All((x => ingredientsInRecipe.Contains(x))))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
                return(false);
            }
        }
 public AddIngredientsViewModel(AddIngredientsView addIngredientsOpen, vwRecipe recipeCreated)
 {
     addIngredients      = addIngredientsOpen;
     recipe              = recipeCreated;
     Ingredient          = new vwIngredient();
     ingredient.RecipeId = recipeCreated.RecipeId;
 }
 public EditRecipeViewModel(EditRecipeView editRecipe, vwUser userLogged, vwRecipe recipeToEdit)
 {
     this.editRecipe = editRecipe;
     User            = userLogged;
     Recipe          = recipeToEdit;
     OldAuthor       = recipeToEdit.Author;
 }
Example #4
0
 public AdminMainViewModel(AdminMainView um, tblPerson p)
 {
     view       = um;
     User       = p;
     RecipeList = recipeService.GetAllvwRecipes();
     Recipe     = new vwRecipe();
 }
Example #5
0
 /// <summary>
 /// This method adds new recipe to DbSet and then saves changes to database.
 /// </summary>
 /// <param name="recipeToAdd">Recipe to be added.</param>
 /// <returns>True if created, false if not.</returns>
 public bool CreateRecipe(vwRecipe recipeToAdd, out int recipeId)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             tblRecipe recipe = new tblRecipe
             {
                 Author          = recipeToAdd.Author,
                 DateOfCreation  = DateTime.Now,
                 Description     = recipeToAdd.Description,
                 NumberOfPersons = recipeToAdd.NumberOfPersons,
                 RecipeName      = recipeToAdd.RecipeName,
                 Type            = recipeToAdd.Type,
                 UserId          = recipeToAdd.UserId
             };
             context.tblRecipes.Add(recipe);
             context.SaveChanges();
             recipeId = recipe.RecipeId;
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         recipeId = 0;
         return(false);
     }
 }
Example #6
0
 /// <summary>
 /// This method deletes recipe and every ingredient of that recipe from database.
 /// </summary>
 /// <param name="recipeToDelete">Recipe to be deleted.</param>
 /// <returns>True if deleted, false if not.</returns>
 public bool DeleteRecipe(vwRecipe recipeToDelete)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             //finding recipe with forwarded id
             tblRecipe recipe = context.tblRecipes.Where(x => x.RecipeId == recipeToDelete.RecipeId).FirstOrDefault();
             //finding ingredients with forwarded id
             List <tblIngredient> ingredients = context.tblIngredients.Where(x => x.RecipeId == recipeToDelete.RecipeId).ToList();
             //removing ingredients
             foreach (var item in ingredients)
             {
                 context.tblIngredients.Remove(item);
                 context.SaveChanges();
             }
             context.tblRecipes.Remove(recipe);
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Example #7
0
 public EditIngredientsViewModel(EditIngredientsView editIngredientsOpen, vwRecipe recipeCreated)
 {
     editIngredients     = editIngredientsOpen;
     Recipe              = recipeCreated;
     Ingredient          = new vwIngredient();
     ingredient.RecipeId = recipeCreated.RecipeId;
     IngredientList      = ingredients.GetRecipeIngredients(Recipe);
 }
 public AddRecipeViewModel(AddRecipeView addRecipeOpen, vwUser userLogged)
 {
     addRecipe     = addRecipeOpen;
     user          = userLogged;
     recipes       = new Recipes();
     recipe        = new vwRecipe();
     recipe.UserId = user.UserId;
     recipe.Author = user.NameAndSurname;
 }
Example #9
0
        private tblRecipe ConvertTotblRepcipe(vwRecipe vwRecipe)
        {
            tblRecipe tblRecipe = new tblRecipe();

            tblRecipe.RecipeID    = vwRecipe.RecipeID;
            tblRecipe.RecipeName  = vwRecipe.RecipeName;
            tblRecipe.RecipeType  = vwRecipe.RecipeType;
            tblRecipe.RecipeType  = vwRecipe.RecipeType;
            tblRecipe.IntendedFor = vwRecipe.IntendedFor;
            tblRecipe.Author      = vwRecipe.PersonID;
            tblRecipe.Description = vwRecipe.Description;
            tblRecipe.DateCreated = vwRecipe.DateCreated;

            return(tblRecipe);
        }
Example #10
0
 /// <summary>
 /// This method creates a list of ingredients of recipes.
 /// </summary>
 /// <param name="recipe">Recipe.</param>
 /// <returns>List of ingredients.</returns>
 public List <vwIngredient> GetRecipeIngredients(vwRecipe recipe)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             return(context.vwIngredients.Where(x => x.RecipeId == recipe.RecipeId).ToList());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
        public AdminView()
        {
            InitializeComponent();
            this.DataContext = new AdminViewModel(this);
            ingredient       = "";

            recipe       = new vwRecipe();
            filteredList = new List <vwRecipe>();
            SearchIngredients.ingredientsToSearch = new List <string>();
            items = new List <vwRecipe>();
            Recipes recipes = new Recipes();

            items = recipes.ViewAllRecipes();
            DataGridResults.ItemsSource = items;
            view        = (CollectionView)CollectionViewSource.GetDefaultView(DataGridResults.ItemsSource);
            view.Filter = UserFilter;
        }
Example #12
0
 /// <summary>
 ///  This method changes time of recept creation and saves changes to database.
 /// </summary>
 /// <param name="recipe">Recipe.</param>
 /// <returns>True if recipe is edited, false if not.</returns>
 public bool ConfirmRecipe(vwRecipe recipeToConfirm)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             tblRecipe recipe = context.tblRecipes.Where(x => x.RecipeId == recipeToConfirm.RecipeId).FirstOrDefault();
             recipe.DateOfCreation = DateTime.Now;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Example #13
0
 public List <string> ViewRecipeIngredients(vwRecipe recipe)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             if (recipe != null)
             {
                 return(context.vwIngredients.Where(x => x.RecipeId == recipe.RecipeId).Select(x => x.IngredientName + " " + x.Quantity).ToList());
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Example #14
0
 /// <summary>
 /// This method edits data of recipe and save changes to database..
 /// </summary>
 /// <param name="recipeToEdit">Recipe to be edited.</param>
 /// <returns>True if edited, false if not.</returns>
 public bool EditRecipe(vwRecipe recipeToEdit)
 {
     try
     {
         using (RecipesDBEntities context = new RecipesDBEntities())
         {
             tblRecipe recipe = context.tblRecipes.Where(x => x.RecipeId == recipeToEdit.RecipeId).FirstOrDefault();
             recipe.RecipeName      = recipeToEdit.RecipeName;
             recipe.Author          = recipeToEdit.Author;
             recipe.DateOfCreation  = DateTime.Now;
             recipe.Description     = recipeToEdit.Description;
             recipe.NumberOfPersons = recipeToEdit.NumberOfPersons;
             recipe.Type            = recipeToEdit.Type;
             recipe.UserId          = recipeToEdit.UserId;
             context.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Example #15
0
 public EditIngredientsView(vwRecipe recipeToEdit)
 {
     InitializeComponent();
     this.DataContext = new EditIngredientsViewModel(this, recipeToEdit);
 }
 public EditRecipeView(vwUser user, vwRecipe recipeToEdit)
 {
     InitializeComponent();
     this.DataContext = new EditRecipeViewModel(this, user, recipeToEdit);
 }
 public AddIngredientsView(vwRecipe recipeCreate)
 {
     InitializeComponent();
     this.DataContext = new AddIngredientsViewModel(this, recipeCreate);
 }