Beispiel #1
0
        public tblRecipe AddNewRecipe(tblRecipe recipe)
        {
            try
            {
                using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1())
                {
                    tblRecipe newRecipe = new tblRecipe
                    {
                        RecipeName  = recipe.RecipeName,
                        RecipeType  = recipe.RecipeType,
                        IntendedFor = recipe.IntendedFor,
                        Author      = recipe.Author,
                        Description = recipe.Description,
                        DateCreated = recipe.DateCreated,
                    };
                    context.tblRecipes.Add(newRecipe);
                    context.SaveChanges();

                    return(newRecipe);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #2
0
        public int Update()
        {
            int result = 0;

            try
            {
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    tblRecipe recipe = dc.tblRecipes.Where(r => r.rc_Id == this.Id).FirstOrDefault();
                    if (recipe != null)
                    {
                        recipe.rc_Name        = this.Name;
                        recipe.rc_Description = this.Description;
                        recipe.rc_Directions  = this.Directions;
                        recipe.rc_Image       = ConvertImage(this.Image);
                        recipe.rc_Ingredients = this.Ingredients;
                        result = dc.SaveChanges();
                    }
                }
                return(result);
            }
            catch (Exception e)
            {
                return(0);

                throw e;
            }
        }
Beispiel #3
0
        public int Insert()
        {
            // Declare result variable for this method (int)
            int result = 0;

            try
            {
                // Using statement for connection string, and create a new instance of it
                using (ChefsCornerEntities dc = new ChefsCornerEntities())
                {
                    // Create new instance of tblRecipe called recipe
                    tblRecipe recipe = new tblRecipe();

                    recipe.rc_Id = 1;
                    if (dc.tblRecipes.Any())
                    {
                        recipe.rc_Id = dc.tblRecipes.Max(r => r.rc_Id) + 1;
                    }
                    this.Id               = recipe.rc_Id;
                    recipe.rc_Name        = this.Name;
                    recipe.rc_Description = this.Description;
                    recipe.rc_Directions  = this.Directions;
                    recipe.rc_Image       = ConvertImage(this.Image);
                    recipe.us_Id          = this.UserId;
                    recipe.rc_Ingredients = this.Ingredients;
                    dc.tblRecipes.Add(recipe);
                    result = dc.SaveChanges();
                }
                return(result);
            }
            catch (Exception e)
            {
                throw e;
            }
        }
 public EditRecipeViewModel(EditRecipe editView, tblUser user, tblRecipe recipeToEdit)
 {
     this.editView   = editView;
     recipe          = recipeToEdit;
     author          = user;
     recipe.authorId = recipeToEdit.authorId;
 }
Beispiel #5
0
 public tblRecipe UpdateRecipe(tblRecipe Updated)
 {
     try
     {
         using (CookbookDatabaseEntities1 context = new CookbookDatabaseEntities1())
         {
             tblRecipe recipe = (from x in context.tblRecipes
                                 where x.RecipeID == Updated.RecipeID
                                 select x).First();
             recipe.RecipeName     = Updated.RecipeName;
             recipe.DateCreated    = Updated.DateCreated;
             recipe.IntendedFor    = Updated.IntendedFor;
             recipe.Description    = Updated.Description;
             recipe.RecipeType     = Updated.RecipeType;
             recipe.tblIngredients = Updated.tblIngredients;
             recipe.Author         = Updated.Author;
             context.SaveChanges();
             MessageBox.Show("Recipe successfully updated!", "Updated", MessageBoxButton.OK, MessageBoxImage.Information);
             return(recipe);
         }
     }
     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;
 }
Beispiel #7
0
 public AddRecipeViewModel(AddRecipe open, tblUser user)
 {
     addRecipe       = open;
     recipe          = new tblRecipe();
     author          = user;
     recipe.authorId = user.userId;
 }
        private void DeleteRecipeExecute()
        {
            try
            {
                MessageBoxResult result = MessageBox.Show("Are you sure?", "Confirm Deleting", MessageBoxButton.YesNo);
                switch (result)
                {
                case MessageBoxResult.Yes:
                    using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                    {
                        tblRecipe deleteRecipe = new tblRecipe();
                        deleteRecipe = db.tblRecipes.Where(r => r.RecipeID == Recipe.RecipeID).FirstOrDefault();

                        db.tblRecipes.Remove(deleteRecipe);
                        db.SaveChanges();
                    }
                    MessageBox.Show("Recipe Deleted Successfully!");
                    AllRecipes = GetAllRecipes();
                    break;

                case MessageBoxResult.No:
                    break;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
 public CalculateQuantityViewModel(CalculateQuantity open, tblRecipe rec)
 {
     view           = open;
     recipe         = rec;
     allIngredients = service.AllIngredientForRecipe(rec.recipeId);
     list           = new List <Quantity>();
 }
Beispiel #10
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);
     }
 }
Beispiel #11
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);
     }
 }
Beispiel #12
0
        public IHttpActionResult PuttblRecipe(int id, tblRecipe tblRecipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblRecipe.Recipe_Id)
            {
                return(BadRequest());
            }

            db.Entry(tblRecipe).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblRecipeExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
 private void SaveExecute()
 {
     try
     {
         MessageBoxResult result = MessageBox.Show("Are you sure you want to save edits to the recipe?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (result == MessageBoxResult.Yes)
         {
             recipe.type     = selectedType;
             recipe.authorId = author.userId;
             service.AddRecipe(recipe);
             tblRecipe editedRecipe = service.AddRecipe(recipe);
             MessageBox.Show("Recipe has been edited.");
             editView.Close();
             MessageBoxResult result2 = MessageBox.Show("Do you want to change ingredients too?", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);
             if (result2 == MessageBoxResult.Yes)
             {
                 EditIngredients editIngredients = new EditIngredients(editedRecipe);
                 editIngredients.ShowDialog();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        /// <summary>
        /// Deletes recipe
        /// </summary>
        /// <param name="recipeID">the recipe that is being deleted</param>
        public void DeleteRecipe(int recipeID)
        {
            try
            {
                using (CakeRecipesDBEntities context = new CakeRecipesDBEntities())
                {
                    for (int i = 0; i < GetAllRecipes().Count; i++)
                    {
                        if (GetAllRecipes().ToList()[i].RecipeID == recipeID)
                        {
                            // Remove all recipe ingredients before the recipe
                            int selectedRecipeIngrediantAmountCount = GetAllSelectedRecipeIngrediantAmount(recipeID).Count;

                            for (int j = 0; j < selectedRecipeIngrediantAmountCount; j++)
                            {
                                tblIngredientAmount ingAmountToDelete = (from ss in context.tblIngredientAmounts where ss.RecipeID == recipeID select ss).First();
                                context.tblIngredientAmounts.Remove(ingAmountToDelete);
                                context.SaveChanges();
                            }

                            tblRecipe recipeToDelete = (from r in context.tblRecipes where r.RecipeID == recipeID select r).First();
                            context.tblRecipes.Remove(recipeToDelete);
                            context.SaveChanges();

                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
 public UserViewModel(UserView userView, tblUserData user)
 {
     recipe        = new tblRecipe();
     this.userView = userView;
     RecipesData   = new RecipesData();
     this.user     = user;
 }
 public AddRecipe(tblRecipe recipeEdit)
 {
     InitializeComponent();
     this.Name        = "AddRecipe";
     this.DataContext = new AddRecipeViewModel(this, recipeEdit);
     this.Language    = XmlLanguage.GetLanguage("sr-SR");
 }
 public UpdateRecipeViewModel(UpdateRecipeView updateViewOpen, tblRecipe recipe, tblUser user)
 {
     updateView  = updateViewOpen;
     Recipe      = recipe;
     RecipeTypes = GetRecipeTypes();
     User        = user;
     EmptyTxtFile();
 }
Beispiel #18
0
 public AddIngredientsViewModel(AddIngredientsView aiv, tblRecipe rec)
 {
     view            = aiv;
     Recipe          = rec;
     IngredientsList = ingredientService.GetAllIngredients();
     newIngredient   = new tblIngredient();
     Ingredient      = new tblIngredient();
 }
 public AddRecipeViewModel(AddRecipeView addRecipeOpen, tblUser user)
 {
     addRecipe   = addRecipeOpen;
     User        = user;
     Recipe      = new tblRecipe();
     RecipeTypes = GetRecipeTypes();
     EmptyTxtFile();
 }
 public EditIngredientsViewModel(EditIngredients editOpen, tblRecipe recipeForEdit)
 {
     editIngView         = editOpen;
     recipe              = recipeForEdit;
     Ingredient          = new tblIngredient();
     ingredient.recipeId = recipeForEdit.recipeId;
     IngredientList      = service.AllIngredientForRecipe(recipe.recipeId);
 }
Beispiel #21
0
        /// <summary>
        /// Method for edit the selected item from the list
        /// </summary>
        public void EditRecipeExecute()
        {
            tblRecipe tempRecipe = new tblRecipe
            {
                RecipeID          = 0,
                RecipeName        = Recipe.RecipeName,
                RecipeType        = Recipe.RecipeType,
                NoPeople          = Recipe.NoPeople,
                RecipeDescription = Recipe.RecipeDescription,
                CreationDate      = Recipe.CreationDate,
                UserID            = Recipe.UserID,
                Changed           = Recipe.Changed
            };

            List <tblIngredientAmount> tempRecipeIngrediantAmountList = recipeData.GetAllSelectedRecipeIngrediantAmount(recipe.RecipeID).ToList();

            try
            {
                MessageBoxResult dialogDelete = Xceed.Wpf.Toolkit.MessageBox.Show($"Da li zelite da azurirate ovaj recept iz liste?\n\nRecept: {Recipe.RecipeName}", "Azuriraj recept", MessageBoxButton.YesNo, MessageBoxImage.Warning);

                if (dialogDelete == MessageBoxResult.Yes)
                {
                    if (Recipe != null)
                    {
                        AddRecipe addRecipeWindow = new AddRecipe(Recipe);
                        addRecipeWindow.ShowDialog();

                        // Checks if the recipe did not get updated
                        if (isRecipeNotUpdated == true)
                        {
                            recipeData.AddRecipe(tempRecipe);
                            for (int i = 0; i < tempRecipeIngrediantAmountList.Count; i++)
                            {
                                tempRecipeIngrediantAmountList[i].IngredientAmountID = 0;
                                tempRecipeIngrediantAmountList[i].RecipeID           = tempRecipe.RecipeID;
                                recipeData.AddIngredientAmount(tempRecipeIngrediantAmountList[i]);
                            }
                            isRecipeNotUpdated = false;
                        }
                        else
                        {
                            // Save recipe changes
                            recipeData.AddRecipe(Recipe);
                        }

                        RecipeList = recipeData.GetAllRecipes().ToList();
                        allReciperWindow.DataGridOrder.ItemsSource = RecipeList;
                        AllRecipesWindow.filteredList    = new List <tblRecipe>();
                        allReciperWindow.filteredRecipes = new List <tblRecipe>();
                    }
                }
            }
            catch (Exception)
            {
                MessageBoxResult dialog = Xceed.Wpf.Toolkit.MessageBox.Show("Trenutno je nemoguce obrisati recept...", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #22
0
        public IHttpActionResult GettblRecipe(int id)
        {
            tblRecipe tblRecipe = db.tblRecipes.Find(id);

            if (tblRecipe == null)
            {
                return(NotFound());
            }

            return(Ok(tblRecipe));
        }
        public ActionResult AddRecipe(tblRecipe r)
        {
            int kq = xuLyRecipes.AddRecipe(r);

            if (kq == 0)
            {
                ViewBag.TrungMa = "Mã công thức trùng";
                return(View(r));
            }
            return(RedirectToAction("Index", "Recipe"));
        }
Beispiel #24
0
        public int AddRecipe(tblRecipe r)
        {
            tblRecipe reptk = db.tblRecipes.Where(x => x.RecipeID == r.RecipeID).FirstOrDefault();

            if (reptk != null)
            {
                return(0);
            }
            db.tblRecipes.Add(r);
            db.SaveChanges();
            return(1);
        }
Beispiel #25
0
        public IHttpActionResult PosttblRecipe(tblRecipe tblRecipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tblRecipes.Add(tblRecipe);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tblRecipe.Recipe_Id }, tblRecipe));
        }
Beispiel #26
0
        public int DeleteRecipe(int ID)
        {
            tblRecipe reptk = db.tblRecipes.Where(x => x.RecipeID == ID).FirstOrDefault();

            if (reptk == null)
            {
                return(0);
            }
            db.tblRecipes.Remove(reptk);
            db.SaveChanges();
            return(1);
        }
        public IHttpActionResult DeletetblRecipe(int id)
        {
            tblRecipe tblRecipe = db.tblRecipes.Find(id);

            if (tblRecipe == null)
            {
                return(NotFound());
            }
            db.tblRecipes.Remove(tblRecipe);
            db.SaveChanges();
            return(Ok(tblRecipe));
        }
Beispiel #28
0
        public int UpdateRecipe(tblRecipe r)
        {
            tblRecipe rtk = db.tblRecipes.Where(x => x.RecipeID == r.RecipeID).FirstOrDefault();

            if (rtk == null)
            {
                return(0);
            }
            rtk.Title   = r.Title;
            rtk.Content = r.Content;
            db.SaveChanges();
            return(1);
        }
        /// <summary>
        /// Gets the value of each ingredient in the recipe and multiplies with the user inserted value
        /// </summary>
        /// <param name="recipe">The recipe we are checking for</param>
        /// <param name="value">The value we vant to multipy the ingredients with</param>
        /// <returns>A dictionary with ingredient type and amount for that recipe</returns>
        public Dictionary <string, double> CountRecipeValue(tblRecipe recipe, int value)
        {
            List <tblIngredientAmount>  allIngredients = GetAllSelectedRecipeIngrediantAmount(recipe.RecipeID);
            Dictionary <string, double> ingredientDict = new Dictionary <string, double>();
            IngredientService           ingData        = new IngredientService();

            for (int i = 0; i < allIngredients.Count; i++)
            {
                ingredientDict[ingData.FindIngredient(allIngredients[i].IngredientID).IngredientName] = Math.Ceiling((double)allIngredients[i].Amount / recipe.NoPeople * value);
            }

            return(ingredientDict);
        }
        private void SaveExecute()
        {
            try
            {
                Ingredients = GetAllIngredients();
                using (RecipeDatabaseEntities db = new RecipeDatabaseEntities())
                {
                    tblRecipe oldRecipe = new tblRecipe();
                    oldRecipe = db.tblRecipes.Where(r => r.RecipeID == Recipe.RecipeID).FirstOrDefault();

                    oldRecipe.RecipeName           = Recipe.RecipeName;
                    oldRecipe.Portions             = Recipe.Portions;
                    oldRecipe.RecipeType           = Type;
                    oldRecipe.RecipeDateOfCreation = DateTime.Now;
                    oldRecipe.RecipeText           = AllIngredientsToString(Ingredients);

                    if (oldRecipe.RecipeText == "")
                    {
                        MessageBox.Show("Please choose ingredients.");
                        return;
                    }
                    else
                    {
                        if (User.UserName == "Admin")
                        {
                            oldRecipe.UserID = User.UserID;
                        }
                        if (Ingredients != null)
                        {
                            foreach (tblIngredient ingredient in Ingredients)
                            {
                                tblRecipeIngredient recipeIngredient = new tblRecipeIngredient();
                                recipeIngredient.RecipeID     = Recipe.RecipeID;
                                recipeIngredient.IngredientID = ingredient.IngredientID;
                                db.tblRecipeIngredients.Add(recipeIngredient);
                            }
                        }

                        db.SaveChanges();
                    }
                }
                MessageBox.Show("Recipe Updated Successfully!");
                updateView.Close();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }