Ejemplo n.º 1
0
    private void GetRecipes()
    {
        COMP229S17S2Entities dbconnection = new COMP229S17S2Entities();
        var recipes = (from allRecipes in dbconnection.recipes select allRecipes);

        RecipesGridView.DataSource = recipes.ToList();
        RecipesGridView.DataBind();
    }
Ejemplo n.º 2
0
 public int getIngredientIDByName(string Name)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         List <int>           item         = (from x in dbConnection.ingredients where x.Name == Name select x.ID).ToList();
         return(item[0]);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
Ejemplo n.º 3
0
 public string getIngredientByID(int ID)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         List <string>        item         = (from x in dbConnection.ingredients where x.ID == ID select x.Name).ToList();
         return(item[0]);
     }
     catch (Exception e)
     {
         return("");
     }
 }
Ejemplo n.º 4
0
 public int GetRecipeIDByName(string name)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         List <int>           ID           = (from x in dbConnection.recipes where x.Name == name select x.ID).ToList();
         return(ID[0]);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
 // write a method that takes an ingredient and returns a collection
 // of recipes that use that ingredient
 public List <recipeingredient> getIngredientDetailByRecipeID(int RecipeNumber)
 {
     try
     {
         COMP229S17S2Entities    dbConnection = new COMP229S17S2Entities();
         List <recipeingredient> ID           = (from x in dbConnection.recipeingredients where x.Recipe == RecipeNumber select x).ToList();
         return(ID);
     }
     catch (Exception e)
     {
         return(new List <recipeingredient>());
     }
 }
 public int CheckIngredient(int recipeID, int ingredientID)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         List <int>           ID           = (from x in dbConnection.recipeingredients where x.Ingredient == ingredientID & x.Recipe == recipeID select x.ID).ToList();
         return(ID[0]);
     }
     catch (Exception e)
     {
         return(-1);
     }
 }
Ejemplo n.º 7
0
 public string getIngredientByName(string name)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         //instead of an sql query we are building a LINQ query
         List <string> nameOfIngre = (from x in dbConnection.recipes where x.Name == name select x.Name).ToList();
         return(nameOfIngre[0]);
     }
     catch (Exception e)
     {
         return("");
     }
 }
Ejemplo n.º 8
0
 public recipe GetRecipeByRecipeID(int ID)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         //instead of an sql query we are building a LINQ query
         List <recipe> result = (from x in dbConnection.recipes where x.ID == ID select x).ToList();
         return(result[0]);
     }
     catch (Exception e)
     {
         return(new recipe());
     }
 }
Ejemplo n.º 9
0
 public List <recipe> GetRecipeByRecipeName(string name)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         //instead of an sql query we are building a LINQ query
         List <recipe> result = (from x in dbConnection.recipes where x.Name == name select x).ToList();
         return(result);
     }
     catch (Exception e)
     {
         return(new List <recipe>());
     }
 }
Ejemplo n.º 10
0
 public string InsertRecipeIngredient(recipeingredient item)
 {
     try
     {
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         dbConnection.recipeingredients.Add(item);
         Console.WriteLine("<p>" + item.ToString() + "</p>");
         dbConnection.SaveChanges();
         return("Item " + item.Recipe + " was saved.");
     }
     catch (Exception ex)
     {
         return(ex.ToString());
     }
 }
Ejemplo n.º 11
0
 public string InsertIngredient(ingredient item)
 {
     try
     {
         //Create database connection
         COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
         //Add item of ingredients to database
         dbConnection.ingredients.Add(item);
         dbConnection.SaveChanges();
         return("Item " + item.Name + " was saved");
     }
     catch (Exception e)
     {
         return(e.ToString());
     }
 }
Ejemplo n.º 12
0
    public List <int> GetRecipeIDByIngredient(string name)
    {
        int ingridientID = GetIngredientIdByName(name);

        try
        {
            COMP229S17S2Entities dbConnection = new COMP229S17S2Entities();
            //instead of an sql query we are building a LINQ query
            List <int> result = (from x in dbConnection.recipeingredients where x.Ingredient == ingridientID select x.Recipe).ToList();
            return(result);
        }
        catch (Exception e)
        {
            return(new List <int>());
        }
    }
Ejemplo n.º 13
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (Request.Cookies["RecipeID"] != null)
        {
            int RecipeID = Convert.ToInt32(Server.HtmlEncode(Request.Cookies["RecipeID"].Value));
            using (COMP229S17S2Entities dbConnection = new COMP229S17S2Entities())
            {
                /*
                 * recipe deletedRecipe = (from recipeRecords in dbConnection.recipes
                 *                      where recipeRecords.ID == RecipeID
                 *                      select recipeRecords).FirstOrDefault();
                 *
                 * dbConnection.recipes.Remove(deletedRecipe);
                 * dbConnection.SaveChanges();
                 * Response.Redirect("~/pages/Recipes.aspx");
                 */

                RecipeIngredientModel a = new RecipeIngredientModel();
                List <int>            b = a.getReInIDbyRecipe(RecipeID);
                for (int i = 0; i < b.Count; i++)
                {
                    int c = b[i];
                    recipeingredient combine = (from mix in dbConnection.recipeingredients
                                                where mix.ID == c
                                                select mix).FirstOrDefault();
                    dbConnection.recipeingredients.Remove(combine);
                    dbConnection.SaveChanges();
                }
                recipe deletedRecipe = (from recipeRecords in dbConnection.recipes
                                        where recipeRecords.ID == RecipeID
                                        select recipeRecords).FirstOrDefault();

                dbConnection.recipes.Remove(deletedRecipe);
                dbConnection.SaveChanges();
                Response.Redirect("Recipes.aspx");
            }
        }
    }
Ejemplo n.º 14
0
    List <recipe> GetRecipesSubmittedBy_Category_Ingredient(string submittedby, string category, string ingredient)
    {
        IngredientModel       inModel   = new IngredientModel();
        RecipeIngredientModel reInModel = new RecipeIngredientModel();
        RecipeModel           reModel   = new RecipeModel();

        using (COMP229S17S2Entities dbConnection = new COMP229S17S2Entities())
        {
            if (submittedby == "All")
            {
                if (category == "All")
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                result.Add(a[0]);
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
                else
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.Category == category
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.Category == category)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
            }
            else
            {
                if (category == "All")
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.SubmittedBy == submittedby
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.SubmittedBy == submittedby)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
                else
                {
                    if (ingredient == "All")
                    {
                        try
                        {
                            List <recipe> result = (from x in dbConnection.recipes
                                                    where x.Category == category && x.SubmittedBy == submittedby
                                                    select x).ToList();
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                    else
                    {
                        try
                        {
                            List <int>    RecipeID = reInModel.GetRecipeIDByIngredient(ingredient);
                            List <recipe> result   = new List <recipe>();
                            for (int i = 0; i < RecipeID.Count; i++)
                            {
                                int           b = RecipeID[i];
                                List <recipe> a = (from x in dbConnection.recipes
                                                   where x.ID == b
                                                   select x).ToList();
                                foreach (recipe x in a)
                                {
                                    if (x.SubmittedBy == submittedby && x.Category == category)
                                    {
                                        result.Add(a[0]);
                                    }
                                }
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(new List <recipe>());
                        }
                    }
                }
            }
        }
    }
Ejemplo n.º 15
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        int RecipeID = Convert.ToInt32(Server.HtmlEncode(Request.Cookies["RecipeID"].Value));

        if (txtCategory.Visible == false)
        {
            string query = "UPDATE Recipe SET Name='" + txtName.Text + "',Category='" + DropDownList1.SelectedValue.ToString() +
                           "',Description='" + txtDescription.Text + "',PrepTime=" + Convert.ToInt32(txtTime.Text) + ",Servings = " + Convert.ToInt32(this.txtNumOfServing.Text) + " WHERE ID =" + RecipeID + ";";

            using (SqlConnection db = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
            {
                SqlCommand command = new SqlCommand(query, db);
                db.Open();
                SqlDataReader reader = command.ExecuteReader();
            }
        }
        else
        {
            string query = "UPDATE Recipe SET Name='" + txtName.Text + "',Category='" + txtCategory.Text +
                           "',Description='" + txtDescription.Text + "',PrepTime=" + Convert.ToInt32(txtTime.Text) + ",Servings = " + Convert.ToInt32(this.txtNumOfServing.Text) + " WHERE ID =" + RecipeID + ";";

            using (SqlConnection db = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
            {
                SqlCommand command = new SqlCommand(query, db);
                db.Open();
                SqlDataReader reader = command.ExecuteReader();
            }
        }
        using (COMP229S17S2Entities db = new COMP229S17S2Entities())
        {
            List <ListOfIngredients> ingredientList = new List <ListOfIngredients>();
            foreach (GridViewRow row in grd.Rows)
            {
                TextBox ingNameTB = (TextBox)row.FindControl("txtIngredient");
                string  ingName   = ingNameTB.Text;


                TextBox unitTB  = (TextBox)row.FindControl("txtUnit");
                string  ingUnit = unitTB.Text;

                TextBox quantityTB  = (TextBox)row.FindControl("txtQuantity");
                int     ingQuantity = Convert.ToInt32(quantityTB.Text);

                ingredientList.Add(new ListOfIngredients(ingName, ingQuantity, ingUnit));
            }
            db.SaveChanges();

            foreach (ListOfIngredients item in ingredientList)
            {
                recipeingredient      newRepIng     = new recipeingredient();
                IngredientModel       ingModel      = new IngredientModel();
                RecipeIngredientModel ReInModel     = new RecipeIngredientModel();
                RecipeModel           recipeModel   = new RecipeModel();
                ingredient            newIngredient = new ingredient();
                if (ReInModel.CheckIngredient(RecipeID, ingModel.getIngredientIDByName(item.Name)) < 0)
                {
                    if (ingModel.getIngredientIDByName(item.Name) < 0)
                    {
                        newIngredient.Name = item.Name;
                        ingModel.InsertIngredient(newIngredient);
                    }
                    newRepIng.Ingredient = ingModel.getIngredientIDByName(item.Name);
                    newRepIng.Recipe     = RecipeID;
                    newRepIng.Quantity   = item.Quantity;
                    newRepIng.UM         = item.Unit;

                    ReInModel.InsertRecipeIngredient(newRepIng);
                }
                else
                {
                    string query1 = "UPDATE recipeingredients SET UM='" + item.Unit + "',Quantity="
                                    + item.Quantity + "WHERE Recipe = " + RecipeID + "AND Ingredient = "
                                    + ingModel.getIngredientIDByName(item.Name) + ";";
                    using (SqlConnection db1 = new SqlConnection("Data Source=DESKTOP-FOJ2HKK;Initial Catalog=COMP229S17S2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"))
                    {
                        SqlCommand command = new SqlCommand(query1, db1);
                        db1.Open();
                        SqlDataReader reader = command.ExecuteReader();
                    }
                }
            }

            List <recipeingredient> freshest = (from recipeIngItems in db.recipeingredients
                                                where recipeIngItems.Recipe == RecipeID
                                                select recipeIngItems).ToList();
            List <int> recipeIngIdsToDelete = new List <int>();

            try
            {
                for (int i = 0; i < ingredientList.Count; i++)
                {
                    freshest[i].Quantity = ingredientList[i].Quantity;
                    freshest[i].UM       = ingredientList[i].Unit;

                    if (freshest[i].Quantity == 0)
                    {
                        //recipeIngIdsToDelete.Add(freshest[i].id);
                        db.recipeingredients.Remove(freshest[i]);
                    }
                }
            }
            catch (Exception ed)
            {
            }
            db.SaveChanges();
            //Redirect bact to the updated recipes page
            Response.Redirect("Recipes.aspx");
        }

        Label1.Text = TextBox1.Text;
    }