Example #1
0
        public IHttpActionResult Postingredients_recipe(ingredients_recipe ingredients_recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.ingredients_recipe.Add(ingredients_recipe);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException)
            {
                if (ingredients_recipeExists(ingredients_recipe.id_recipe))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = ingredients_recipe.id_recipe }, ingredients_recipe));
        }
Example #2
0
        public IHttpActionResult Putingredients_recipe(decimal id, ingredients_recipe ingredients_recipe)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ingredients_recipe.id_recipe)
            {
                return(BadRequest());
            }

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

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

            return(StatusCode(HttpStatusCode.NoContent));
        }
Example #3
0
        public ActionResult Step3(mycook.Models.recipe usermode, FormCollection fc)
        {
            mycookEntities me = new mycookEntities();


            string test  = fc["txttest"];
            string test2 = fc["txttestnumber"];

            List <ingredient> ingredients = new List <ingredient>();

            //foreach(String s in fc)
            //{

            //    ingredient i = new ingredient();
            //    i.name_ingredient = fc[s];
            //    ingredients.Add(i);

            //}

            List <String> names = test.Split(',').ToList();

            if (names.Count == 1 && names[0] == "")
            {
                ViewData["Success"] = "Data was saved successfully.";
                return(View("CreateRecipeStep2"));
            }
            else
            {
                List <int> quantities = test2.Split(',').Select(int.Parse).ToList();
                List <ingredients_recipe> all_ingredients = new List <ingredients_recipe>();

                int contador = 0;
                foreach (String s in names)
                {
                    ingredient         i  = new ingredient();
                    ingredients_recipe ir = new ingredients_recipe();

                    i.name_ingredient       = s;
                    ir.ingredient           = i;
                    ir.quantity_per_portion = quantities[contador];
                    ingredients.Add(i);
                    me.ingredients.Add(i);


                    all_ingredients.Add(ir);

                    contador++;
                }

                me.SaveChanges();



                int x = ingredients.Count();

                Session["all_ingridients"] = all_ingredients;
                return(View("CreateRecipeStep3"));
            }
        }
Example #4
0
        public IHttpActionResult Getingredients_recipe(decimal id)
        {
            ingredients_recipe ingredients_recipe = db.ingredients_recipe.Find(id);

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

            return(Ok(ingredients_recipe));
        }
Example #5
0
        public IHttpActionResult Deleteingredients_recipe(decimal id)
        {
            ingredients_recipe ingredients_recipe = db.ingredients_recipe.Find(id);

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

            db.ingredients_recipe.Remove(ingredients_recipe);
            db.SaveChanges();

            return(Ok(ingredients_recipe));
        }
Example #6
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"));
            }
        }