public void callback(recipe result, string url)
 {
     if (result != null)
     {
         ingredients = result.ingredients.ToArray();
         directions = result.directions;
         name = result.name;
     }
 }
 private void buttonClickCallback(recipe result, string url)
 {
     if (result == null)
         Application.OpenURL(url);
     else
     {
         recipeViewer.Instance.draw(result);
     }
 }
 public void draw(recipe result)
 {
     main.Instance.openPanel(panel);
     if (result.img != null) setImage(result.img);
     numLines = 0;
     recipeInstructions.text = "";
     addLine(result.name);
     addNewLine();
     addLine("Ingredients:");
     foreach(string ing in result.ingredients)
     {
         addLine(" - " + ing);
     }
     addNewLine();
     addLine("Directions:");
     addLine(result.directions);
     addNewLine();
     addLine("Source: " + result.url);
     toTop();
     toTop();
 }
    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");
            }
        }
    }
    IEnumerator desserts()                                                                                                                      //desserts subroutine
    {
        CurrSel = 1;
        yield return(StartCoroutine(selectDes()));

        if (CurrSel == 1)
        {
            CurrRec = de1;
        }
        if (CurrSel == 2)
        {
            CurrRec = de2;
        }
        if (CurrSel == 3)
        {
            CurrRec = de3;
        }
        if (CurrSel == 4)
        {
            CurrRec = de4;
        }
        yield return(StartCoroutine(cook(CurrRec)));
    }
    IEnumerator appetizers()                                                                                                                    //appetizers subroutine
    {
        CurrSel = 1;
        yield return(StartCoroutine(selectApp()));

        if (CurrSel == 1)
        {
            CurrRec = app1;
        }
        if (CurrSel == 2)
        {
            CurrRec = app2;
        }
        if (CurrSel == 3)
        {
            CurrRec = app3;
        }
        if (CurrSel == 4)
        {
            CurrRec = app4;
        }
        yield return(StartCoroutine(cook(CurrRec)));
    }
Example #7
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            recipe recipeItem = new recipe();
            recipeItem.Name        = txtName.Text;
            recipeItem.SubmittedBy = txtSubmit.Text;
            recipeItem.PrepTime    = Convert.ToInt32(txtTime.Text);
            recipeItem.Servings    = Convert.ToInt32(txtServings.Text);
            recipeItem.Description = txtDescription.Text;
            recipeItem.Category    = txtCategory.Text;


            RecipeModel recipeModel = new RecipeModel();
            recipeModel.InsertRecipe(recipeItem);



            int ingamount = Convert.ToInt32(numberIngredients.SelectedValue);

            IngredientModel       ingModel = new IngredientModel();
            ingredient            ingItem;
            RecipeIngredientModel recIngModel = new RecipeIngredientModel();
            recipeingredient      recIngItem;

            string[] ingredName = { ingredientName1.Text, ingredientName2.Text, ingredientName3.Text,  ingredientName4.Text,  ingredientName5.Text,  ingredientName6.Text,  ingredientName7.Text,
                                    ingredientName8.Text, ingredientName9.Text, ingredientName10.Text, ingredientName11.Text, ingredientName12.Text, ingredientName13.Text, ingredientName14.Text, ingredientName15.Text };

            string[] unitType = { units1.Text,  units2.Text,  units3.Text, units4.Text, units5.Text, units6.Text, units7.Text, units8.Text, units9.Text, units10.Text, units11.Text, units12.Text,
                                  units13.Text, units14.Text, units15.Text };

            string[] ingQuant = { ingredientQuantity1.Text,  ingredientQuantity2.Text, ingredientQuantity3.Text, ingredientQuantity4.Text,  ingredientQuantity5.Text,  ingredientQuantity6.Text,
                                  ingredientQuantity7.Text,  ingredientQuantity8.Text, ingredientQuantity9.Text, ingredientQuantity10.Text, ingredientQuantity11.Text, ingredientQuantity12.Text,ingredientQuantity13.Text,
                                  ingredientQuantity14.Text, ingredientQuantity15.Text };

            for (int i = 0; i < ingamount; i++)
            {
                ingItem      = new ingredient();
                recIngItem   = new recipeingredient();
                ingItem.Name = ingredName[i];
                ingModel.InsertIngredient(ingItem);
                recIngItem.Recipe     = recipeModel.GetRecipeIDByName(txtName.Text);
                testLabel.Text        = Convert.ToString(recIngItem.Recipe);
                recIngItem.Ingredient = ingModel.getIngredientIDByName(ingredName[i]);
                testLabel.Text       += Convert.ToString(recIngItem.Ingredient) + " ";
                recIngItem.UM         = unitType[i];
                recIngItem.Quantity   = Convert.ToInt32(ingQuant[i]);
                testLabel.Text       += recIngItem.UM + " ";
                testLabel.Text       += recIngItem.ToString();
                recIngModel.InsertRecipeIngredient(recIngItem);
            }

            if (flImage.HasFile)
            {
                try
                {
                    string filename = Path.GetFileName(flImage.FileName);
                    flImage.SaveAs(Server.MapPath("~/") + filename);
                    StatusLabel.Text = "Upload status: File uploaded!";
                }
                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
        }
    }
Example #8
0
        private const double KGtoOZ = KGtoLB * 16;//35.71428571428571;

        public recipe ParseBeerXML(string xml)
        {
            //All the converted items
            RECIPE recipeFromXML = new RECIPE();
            List <fermentableObj> Fermentables = new List <fermentableObj>();
            List <hopObj>         Hops         = new List <hopObj>();
            List <yeastObj>       Yeasts       = new List <yeastObj>();
            List <miscObj>        Miscs        = new List <miscObj>();
            styleObj Style = new styleObj();

            //Load the string into an xml object
            XmlDocument   xdoc       = new XmlDocument();
            XmlSerializer serializer = new XmlSerializer((typeof(RECIPE)));

            xdoc.LoadXml(xml);

            //convert the xml object to json
            string  json = JsonConvert.SerializeXmlNode(xdoc);
            JObject recipeInfoFromXML = JObject.Parse(json);

            // get the recipe info
            JToken results = recipeInfoFromXML["RECIPES"]["RECIPE"];

            recipeFromXML = results.ToObject <RECIPE>();

            //same with style
            results = recipeInfoFromXML["RECIPES"]["RECIPE"]["STYLE"];
            Style   = results.ToObject <styleObj>();

            /*
             * When it converts xml to json, due to the way that Json uses list objects and XML does not
             * the parser can't tell the difference between a list and not a list...
             *
             * So we come to this...
             *
             * The try catches handle list vs not list.
             *
             * For example
             * recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().Children()
             *
             * retrieves items if they are encapsulated in a json list.
             *
             * recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children()
             *
             * retrieves items if they are not encapsulated in a list.
             *
             * So this should handle both instances because if you parse too deep it can't figure out what object you're
             * trying to map into and it throws an exception.
             *
             * */
            try
            {
                IList <JToken> fermentablesList = recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().Children().ToList();
                foreach (JToken result in fermentablesList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    fermentableObj searchResult = result.ToObject <fermentableObj>();
                    Fermentables.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> fermentablesList = recipeInfoFromXML["RECIPES"]["RECIPE"]["FERMENTABLES"].Children().Children().ToList();
                foreach (JToken result in fermentablesList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    fermentableObj searchResult = result.ToObject <fermentableObj>();
                    Fermentables.Add(searchResult);
                }
            }

            try
            {
                IList <JToken> hopsList = recipeInfoFromXML["RECIPES"]["RECIPE"]["HOPS"].Children().Children().Children().ToList();
                foreach (JToken result in hopsList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    hopObj searchResult = result.ToObject <hopObj>();
                    Hops.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> hopsList = recipeInfoFromXML["RECIPES"]["RECIPE"]["HOPS"].Children().Children().ToList();
                foreach (JToken result in hopsList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    hopObj searchResult = result.ToObject <hopObj>();
                    Hops.Add(searchResult);
                }
            }


            try
            {
                IList <JToken> yeastList = recipeInfoFromXML["RECIPES"]["RECIPE"]["YEASTS"].Children().Children().Children().ToList();
                foreach (JToken result in yeastList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    yeastObj searchResult = result.ToObject <yeastObj>();
                    Yeasts.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> yeastList = recipeInfoFromXML["RECIPES"]["RECIPE"]["YEASTS"].Children().Children().ToList();
                foreach (JToken result in yeastList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    yeastObj searchResult = result.ToObject <yeastObj>();
                    Yeasts.Add(searchResult);
                }
            }

            try
            {
                IList <JToken> miscList = recipeInfoFromXML["RECIPES"]["RECIPE"]["MISCS"].Children().Children().Children().ToList();
                foreach (JToken result in miscList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    miscObj searchResult = result.ToObject <miscObj>();
                    Miscs.Add(searchResult);
                }
            }
            catch (Exception e)
            {
                IList <JToken> miscList = recipeInfoFromXML["RECIPES"]["RECIPE"]["MISCS"].Children().Children().ToList();
                foreach (JToken result in miscList)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    miscObj searchResult = result.ToObject <miscObj>();
                    Miscs.Add(searchResult);
                }
            }

            recipe final = MapRecipeInfo(recipeFromXML, Fermentables, Hops, Yeasts, Miscs, Style);

            final.equipmentProfile = getDefaultEquipmentProfile();
            final.recipeStats      = makeEmptyRecipeStats();
            final.recipeStats      = MathFunctions.GlobalFunctions.updateStats(final);
            DataAccess accessor = new DataAccess();

            accessor.PostRecipe(final);

            return(final);
        }
Example #9
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        int txt14 = Convert.ToInt32(TextBox14.Text);

        if (txt14 <= 0)
        {
            string display = "Quantity should be more than 0";
            ClientScript.RegisterStartupScript(this.GetType(), "yourMessage", "alert('" + display + "');", true);
        }
        else
        {
            ((List <recipe>)Application["recipes"]).Add
            (
                new recipe
            {
                Name        = nameOfRecipe.Text,
                SubmittedBy = submittedBy.Text,
                Category    = category.Text,
                CookTime    = cookingTime.Text,
                Serving     = Convert.ToInt32(numberOfServing.Text),
                Desc        = recipeDesc.Text,
                Ing1        = TextBox7.Text,
                Ing2        = TextBox8.Text,
                Ing3        = TextBox9.Text,
                Ing4        = TextBox10.Text,
                Ing5        = TextBox11.Text,
                Ing6        = TextBox12.Text,
                Ing7        = TextBox20.Text,
                Ing8        = TextBox21.Text,
                Ing9        = TextBox24.Text,
                Ing10       = TextBox25.Text,
                Ing11       = TextBox26.Text,
                Ing12       = TextBox27.Text,
                Ing13       = TextBox28.Text,
                Ing14       = TextBox29.Text,
                Ing15       = TextBox30.Text,
                Qnty1       = Convert.ToInt32(TextBox14.Text),
                Qnty2       = Convert.ToInt32(TextBox15.Text),
                Qnty3       = Convert.ToInt32(TextBox16.Text),
                Qnty4       = Convert.ToInt32(TextBox17.Text),
                Qnty5       = Convert.ToInt32(TextBox18.Text),
                Qnty6       = Convert.ToInt32(TextBox19.Text),
                Qnty7       = Convert.ToInt32(TextBox22.Text),
                Qnty8       = Convert.ToInt32(TextBox23.Text),
                Qnty9       = Convert.ToInt32(TextBox31.Text),
                Qnty10      = Convert.ToInt32(TextBox32.Text),
                Qnty11      = Convert.ToInt32(TextBox33.Text),
                Qnty12      = Convert.ToInt32(TextBox34.Text),
                Qnty13      = Convert.ToInt32(TextBox35.Text),
                Qnty14      = Convert.ToInt32(TextBox36.Text),
                Qnty15      = Convert.ToInt32(TextBox37.Text),
                Unit1       = DropDownList7.Text,
                Unit2       = DropDownList8.Text,
                Unit3       = DropDownList9.Text,
                Unit4       = DropDownList10.Text,
                Unit5       = DropDownList11.Text,
                Unit6       = DropDownList12.Text,
                Unit7       = DropDownList13.Text,
                Unit8       = DropDownList14.Text,
                Unit9       = DropDownList15.Text,
                Unit10      = DropDownList16.Text,
                Unit11      = DropDownList17.Text,
                Unit12      = DropDownList18.Text,
                Unit13      = DropDownList19.Text,
                Unit14      = DropDownList20.Text,
                Unit15      = DropDownList21.Text
            }
            );
            Application["recipe"] = new recipe
            {
                Name        = nameOfRecipe.Text,
                SubmittedBy = submittedBy.Text,
                Category    = category.Text,
                CookTime    = cookingTime.Text,
                Serving     = Convert.ToInt32(numberOfServing.Text),
                Desc        = recipeDesc.Text,
                Ing1        = TextBox7.Text,
                Ing2        = TextBox8.Text,
                Ing3        = TextBox9.Text,
                Ing4        = TextBox10.Text,
                Ing5        = TextBox11.Text,
                Ing6        = TextBox12.Text,
                Ing7        = TextBox20.Text,
                Ing8        = TextBox21.Text,
                Ing9        = TextBox24.Text,
                Ing10       = TextBox25.Text,
                Ing11       = TextBox26.Text,
                Ing12       = TextBox27.Text,
                Ing13       = TextBox28.Text,
                Ing14       = TextBox29.Text,
                Ing15       = TextBox30.Text,
                Qnty1       = Convert.ToInt32(TextBox14.Text),
                Qnty2       = Convert.ToInt32(TextBox15.Text),
                Qnty3       = Convert.ToInt32(TextBox16.Text),
                Qnty4       = Convert.ToInt32(TextBox17.Text),
                Qnty5       = Convert.ToInt32(TextBox18.Text),
                Qnty6       = Convert.ToInt32(TextBox19.Text),
                Qnty7       = Convert.ToInt32(TextBox22.Text),
                Qnty8       = Convert.ToInt32(TextBox23.Text),
                Qnty9       = Convert.ToInt32(TextBox31.Text),
                Qnty10      = Convert.ToInt32(TextBox32.Text),
                Qnty11      = Convert.ToInt32(TextBox33.Text),
                Qnty12      = Convert.ToInt32(TextBox34.Text),
                Qnty13      = Convert.ToInt32(TextBox35.Text),
                Qnty14      = Convert.ToInt32(TextBox36.Text),
                Qnty15      = Convert.ToInt32(TextBox37.Text),
                Unit1       = DropDownList7.Text,
                Unit2       = DropDownList8.Text,
                Unit3       = DropDownList9.Text,
                Unit4       = DropDownList10.Text,
                Unit5       = DropDownList11.Text,
                Unit6       = DropDownList12.Text,
                Unit7       = DropDownList13.Text,
                Unit8       = DropDownList14.Text,
                Unit9       = DropDownList15.Text,
                Unit10      = DropDownList16.Text,
                Unit11      = DropDownList17.Text,
                Unit12      = DropDownList18.Text,
                Unit13      = DropDownList19.Text,
                Unit14      = DropDownList20.Text,
                Unit15      = DropDownList21.Text
            };
            Response.Redirect("summary.aspx");
        }
    }
 public void callback(recipe r, string url){
     if (expected == null) {
         scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Failed");
     }
     else if (r == null)
     {
         scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Website is necessary");
     }
     else if (r.name.IndexOf(expected.name) < 0)
     {
         scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Names do not match");
     }
     else if (Regex.Replace(r.directions.ToLower(), @"\s+", "") != Regex.Replace(expected.directions.ToLower(), @"\s+", ""))
     {
         Debug.Log(Regex.Replace(r.directions.ToLower(), @"\s+", "") + "," + Regex.Replace(expected.directions.ToLower(), @"\s+", ""));
         scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Directions do not match");
     }
     else if (r.ingredients.Count != expected.ingredients.Count)
     {
         scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Ingredient Count does not match");
     }
     else
     {
         bool passed = true;
         for(int i=0;i<r.ingredients.Count;i++) {
             string s1 = Regex.Replace(r.ingredients[i].ToLower(), @"\s+", "");
             string s2 = Regex.Replace(expected.ingredients[i].ToLower(), @"\s+", "");
             if (Regex.Replace(s1.ToLower(), @"\t|\n|\r", "") != Regex.Replace(s2.ToLower(), @"\t|\n|\r", "") && s1.IndexOf("&nbsp") < 0 && s2.IndexOf('/') < 0)
             {
                 Debug.Log(Regex.Replace(s1.ToLower(), @"\t|\n|\r", "") + ";" + Regex.Replace(s2.ToLower(), @"\t|\n|\r", ""));
                 passed = false;
                 break;
             }
         }
         if (passed)
             scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Succeeded");
         else
         {
             Debug.Log(string.Join(",", r.ingredients.ToArray()) + ";" + string.Join(",", expected.ingredients.ToArray()));
             scenarioProgram.e.websitesParsed.Add(webParser.getURLBase(url) + ": Ingredients do not match");
         }
     }
     scenarioProgram.runNextWebParsingTests();
 }
 private bool tester(string testUrl, string realName, string[] realIng, string realDir) {
     expected = new recipe(realName, new List<string>(realIng), realDir, null);
     // Parse the website
     webParser.Instance.parse(testUrl, callback);
     return true;
 }
Example #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            recipe fm = new recipe();

            fm.Show();
        }
Example #13
0
    public override string ToString()
    {
        recipe item = new recipe();

        return(string.Format("{0} {1} {2} {3} {4}", item.Name, item.SubmittedBy, item.Description, item.PrepTime, item.Servings));
    }
Example #14
0
 public void Update(recipe aRecipe)
 {
 }
Example #15
0
 public RecipeStatsResponse Post([FromBody] recipe value, string id)
 {
     return(Post(value, id, true));
 }
Example #16
0
        public static recipe initializeBlankRecipe()
        {
            recipe newRecipe = new recipe();

            currentRecipeId = "-1";

            newRecipe.name        = "";
            newRecipe.description = "";

            newRecipe.style = new style();

            newRecipe.recipeStats = new RecipeStatistics
            {
                abv = 0,
                fg  = 0,
                og  = 0,
                srm = 0,
                ibu = 0
            };

            RecipeParameters rp = new RecipeParameters
            {
                fermentableCalcType = "basic",
                ibuBoilTimeCurveFit = -0.04F,
                ibuCalcType         = "basic",
                intoFermenterVolume = 0
            };

            newRecipe.recipeParameters = rp;

            newRecipe.equipmentProfile = RecipeTools.getDefaultEquipmentProfile();

            newRecipe.adjuncts     = new List <adjunctAddition>();
            newRecipe.fermentables = new List <fermentableAddition>();
            newRecipe.hops         = new List <hopAddition>();
            newRecipe.yeasts       = new List <yeastAddition>();
            //hopAddition a = new hopAddition();
            //a.hopID = "";
            //a.type = "";
            //a.additionGuid = "";
            //a.amount = 0;
            //a.time = 0;
            //hopbase b = new hopbase();
            //b.aau = 1;
            //b.type = "idk";
            //b.substitutes = "";
            //b.createdByUserId = "";
            //b.idString = "";
            //b.name = "Centennial";
            //b.notes = "";
            //b.origin = "";
            //a.hop = b;
            //newRecipe.hops.Add(a);


            //    fermentable f = new fermentable
            //    {
            //        color = 6,
            //        name = "2 Row",
            //        yield = 14.65F,
            //        maltster = "Breiss"
            //    };

            //    fermentableAddition fa = new fermentableAddition
            //    {
            //        use = "Mash",
            //        weight = 12.5F,
            //        fermentable = f
            //    };

            //    yeast y = new yeast
            //    {
            //        attenuation = 1.05F,
            //        lab = "Wyeast",
            //        name = "Wheat"
            //    };

            //    yeastAddition ya = new yeastAddition
            //    {
            //        yeast = y
            //};

            //    adjunct ad = new adjunct
            //    {
            //        name = "Cocoa nibs"
            //    };

            //    adjunctAddition aa = new adjunctAddition
            //    {
            //        adjunct = ad,
            //        amount = 2,
            //        time = 60,
            //        timeUnit = "min",
            //        type = "boil",
            //        unit = "oz"
            //    };

            //    newRecipe.fermentables.Add(fa);
            //    newRecipe.yeasts.Add(ya);
            //    newRecipe.adjuncts.Add(aa);

            return(newRecipe);
        }
Example #17
0
        public ActionResult StepFinal(mycook.Models.recipe usermode)
        {
            mycookEntities me = new mycookEntities();

            int controlo = me.recipes.Count();



            recipe nova = new recipe();

            nova.name_recipe = (String)Session["name_of_recipe"];


            String aux = (String)Session["calories_per_portion"];
            int    x   = Int32.Parse(aux);

            nova.calories_portion = x;

            nova.portions = convert((String)Session["portions"]);

            Decimal aux2 = (Decimal)Session["fat"];
            decimal x2   = aux2;

            nova.fat_per_portion = x2;


            Decimal aux3 = (Decimal)Session["cholesterol"];
            decimal x3   = aux3;

            nova.cholesterol_per_portion = x3;



            Decimal aux4 = (Decimal)Session["saturated"];
            decimal x4   = aux4;

            nova.saturatedfat_per_portion = x4;



            Decimal aux5 = (Decimal)Session["carbohydrate"];
            decimal x5   = aux5;

            nova.carbs_per_portion = x5;


            Decimal aux6 = (Decimal)Session["protein"];
            decimal x6   = aux6;

            nova.protein_per_portion = x6;



            Decimal aux7 = (Decimal)Session["fibre"];
            decimal x7   = aux7;

            nova.fibre_per_portion = x7;



            Decimal aux8 = (Decimal)Session["sodium"];
            decimal x8   = aux8;

            nova.sodium_per_portion = x8;

            Decimal aux9 = (Decimal)Session["sugars"];
            decimal x9   = aux9;

            nova.sugar_per_portion = x9;


            me.recipes.Add(nova);

            me.SaveChanges();


            //STEPS

            List <step> recipe_steps = (List <step>)Session["steps"];

            foreach (step s in recipe_steps)
            {
                step new_step = new step();
                new_step.id_recipe    = nova.id_recipe;
                new_step.recipe       = nova;
                new_step.number_order = s.number_order;
                new_step.description  = s.description;
                me.steps.Add(new_step);
            }


            //INGREDIENTS_RECIPE
            List <ingredients_recipe> ir  = (List <ingredients_recipe>)Session["all_ingridients"];
            List <ingredient>         all = me.ingredients.ToList();



            foreach (ingredients_recipe iee in ir)
            {
                iee.id_recipe = nova.id_recipe;
                iee.recipe    = nova;
                me.ingredients_recipe.Add(iee);
            }
            me.SaveChanges();



            foreach (ingredients_recipe ingrec in ir)
            {
                ingredients_recipe novo = new ingredients_recipe();
                novo.id_recipe = nova.id_recipe;
            }


            me.SaveChanges();


            int controlo2 = me.recipes.Count();


            if (controlo2 == controlo + 1)
            {
                return(RedirectToAction("Index", "Recipes"));
            }
            else
            {
                ViewData["WRONG"] = "Data was saved successfully.";
                return(View("CreateRecipeStep6"));
            }
        }
Example #18
0
        private async Task AddRecipe(AddArguments a, Message message)
        {
            using (var db = new Database())
            {
                // Checking user autorization
                if (message.User.Id != 136856172203474944 && await db.users.FindAsync(message.User.Id) == null)
                {
                    await message.Channel.SendMessage("You do not have permission to use that command.");

                    return;
                }

                // Getting items
                foreach (var stack in a.Inputs)
                {
                    await stack.GetItemFromDb(db);
                }

                var snowflake = TimeUtil.GenerateSnowflake(0, (ushort)(message.User.Id % 4095));

                // Doing the stuff, the good stuff
                await db.Database.Transaction(async() =>
                {
                    var recipe   = new recipe();
                    var itemVoid = new item {
                        Id = 0
                    };

                    // Putting in dummy for inputs and putputs
                    if (!a.Inputs.Any())
                    {
                        a.Inputs.Add(new AddArguments.Stack {
                            Item = itemVoid, Quantity = 0
                        });
                    }
                    if (!a.Outputs.Any())
                    {
                        a.Outputs.Add(new AddArguments.Stack {
                            Item = itemVoid, Quantity = 0
                        });
                    }

                    foreach (var i in a.Inputs)
                    {
                        recipe.inputs.Add(new input {
                            ItemId = i.Item.Id, recipe = recipe, Quantity = i.Quantity
                        });
                    }

                    foreach (var o in a.Outputs)
                    {
                        recipe.outputs.Add(new output {
                            ItemId = o.Item.Id, recipe = recipe, Quantity = o.Quantity
                        });
                    }

                    recipe.Id     = snowflake;
                    recipe.UserId = message.User.Id;
                    recipe.Name   = a.Name;
                    recipe.Exp    = a.Exp;
                    recipe.Units  = a.Units;
                    recipe.Level  = a.Level;
                    recipe.Skill  = (sbyte)a.Type;
                    recipe.Extra  = a.Extra;
                    db.recipes.Add(recipe);

                    if (await db.SaveChangesAsync() <= 0)
                    {
                        throw new Exception("Recipe could not be saved.");
                    }
                });

                await message.Channel.SendMessage($"Recipe **{a.Name}** has been successfully added.");
            }
        }