Ejemplo n.º 1
0
        public ActionResult testeEdit([Bind(Include = "id_user,username,password,role, subscription")] user user, mycook.Models.user usermodel)
        {
            mycookEntities me = new mycookEntities();



            var userDetails = me.users.Where(x => x.id_user == usermodel.id_user).FirstOrDefault();

            if (userDetails != null)
            {
                user editado = userDetails;
                editado.username     = usermodel.username;
                editado.password     = usermodel.password;
                editado.subscription = usermodel.subscription;
                editado.role         = usermodel.role;


                ;
                me.SaveChanges();
                db.Entry(user).State = EntityState.Modified;
                db.SaveChanges();
                // return RedirectToAction("Index");
                TempData["msg"] = "Record Saved Successfully.";
                // ViewBag.DataExists = true;
                // ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Data Already Exists');</script>";

                return(RedirectToAction("admins"));
            }
            else
            {
                usermodel.LoginErrorMessage = "Error";
            }
            return(RedirectToAction("admins"));
        }
Ejemplo n.º 2
0
        public ActionResult testeEdit(preference p, mycook.Models.preference usermodel)
        {
            mycookEntities me = new mycookEntities();



            var prefDetails = me.preferences.Where(x => x.id_preference == usermodel.id_preference).FirstOrDefault();

            if (prefDetails != null)
            {
                preference editado = prefDetails;
                editado.description = usermodel.description;
                editado.type        = usermodel.type;


                ;
                me.SaveChanges();
                db.Entry(p).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Preferences"));
            }
            else
            {
            }
            return(RedirectToAction("Preferences"));
        }
Ejemplo n.º 3
0
        public ActionResult teste(mycook.Models.user usermodel)
        {
            mycookEntities me = new mycookEntities();



            var userDetails = me.users.Where(x => x.username == usermodel.username).FirstOrDefault();

            if (userDetails == null)
            {
                user newAdmin = new user();
                newAdmin.username     = usermodel.username;
                newAdmin.password     = usermodel.password;
                newAdmin.subscription = usermodel.subscription;
                newAdmin.role         = "Admin";


                me.users.Add(newAdmin);
                me.SaveChanges();

                TempData["msg"] = "Record Saved Successfully.";
                // ViewBag.DataExists = true;
                // ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Data Already Exists');</script>";

                return(RedirectToAction("admins"));
            }
            else
            {
                usermodel.LoginErrorMessage = "Error";
            }
            return(View("create"));
        }
Ejemplo n.º 4
0
        public ActionResult testeEdit(preference p, mycook.Models.preference usermodel)
        {
            mycookEntities me = new mycookEntities();



            var prefDetails = me.preferences.Where(x => x.id_preference == usermodel.id_preference).FirstOrDefault();

            if (prefDetails != null)
            {
                preference editado = prefDetails;
                editado.description = usermodel.description;
                editado.type        = usermodel.type;

                if (usermodel.type.ToLower().Equals("free") || usermodel.type.ToLower().Equals("paid"))
                {
                    me.SaveChanges();
                    db.Entry(p).State = EntityState.Modified;
                    db.SaveChanges();
                    return(RedirectToAction("Preferences"));
                }
                else
                {
                    ViewData["TYPE"] = "Data was saved successfully.";
                    return(View("Edit", usermodel));
                }
            }
            else
            {
            }
            return(RedirectToAction("Preferences"));
        }
Ejemplo n.º 5
0
        public ActionResult testeEdit([Bind(Include = "id_user,username,password,role, subscription")] ingredient i, mycook.Models.ingredient usermodel)
        {
            mycookEntities me = new mycookEntities();



            var ingDetails = me.ingredients.Where(x => x.id_ingredient == usermodel.id_ingredient).FirstOrDefault();

            if (ingDetails != null)
            {
                ingredient editado = ingDetails;
                editado.name_ingredient = usermodel.name_ingredient;
                editado.status          = "ON";
                usermodel.status        = "ON";

                i.status = "ON";

                me.SaveChanges();
                db.Entry(i).State = EntityState.Modified;
                //db.SaveChanges();
                // return RedirectToAction("Index");
                TempData["msg"] = "Record Saved Successfully.";
                // ViewBag.DataExists = true;
                // ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Data Already Exists');</script>";

                return(RedirectToAction("Index"));
            }
            else
            {
                usermodel.ErrorMessage = "Error";
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
0
        public ActionResult CreateINGREDIENT(mycook.Models.ingredient usermodel)
        {
            mycookEntities me = new mycookEntities();



            var ingDetails = me.ingredients.Where(x => x.name_ingredient == usermodel.name_ingredient).FirstOrDefault();

            if (ingDetails == null)
            {
                ingredient newING = new ingredient();
                newING.name_ingredient = usermodel.name_ingredient;
                newING.status          = "ON";

                me.ingredients.Add(newING);
                me.SaveChanges();

                TempData["msg"] = "Record Saved Successfully.";
                // ViewBag.DataExists = true;
                // ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Data Already Exists');</script>";

                return(RedirectToAction("Index"));
            }
            else
            {
                usermodel.ErrorMessage = "Error";
            }


            return(View("Create"));
        }
Ejemplo n.º 7
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"));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Edit(mycook.Models.user usermodel, decimal id, [Bind(Include = "id_user,username,password,role, subscription")] user user)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            user u = db.users.Find(id);

            if (u == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.id_user = new SelectList(db., "id_recipe", "name_recipe", step.id_recipe);

            String username = usermodel.username;

            String role = usermodel.role;

            // String pass = usermodel.

            String password = usermodel.password;

            String subscription = usermodel.subscription;

            user nv = u;

            ViewBag.role_user = new SelectList(db.users, "role", user.role);

            //u.username = username;
            //u.role = role;
            //u.password = password;
            //u.subscription = subscription;



            db.SaveChanges();

            //update_user(u, password, role, username, subscription);

            return(View(u));
        }
Ejemplo n.º 9
0
        public ActionResult Edit(mycook.Models.preference usermodel, decimal id, [Bind(Include = "id_user,username,password,role, subscription")] preference pref)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            preference u = db.preferences.Find(id);

            if (u == null)
            {
                return(HttpNotFound());
            }
            //ViewBag.id_user = new SelectList(db., "id_recipe", "name_recipe", step.id_recipe);

            String descr = usermodel.description;
            String type  = usermodel.type;



            preference nv = u;

            ViewData["TYPE"] = null;

            //u.username = username;
            //u.role = role;
            //u.password = password;
            //u.subscription = subscription;



            db.SaveChanges();

            //update_user(u, password, role, username, subscription);

            return(View(u));
        }
Ejemplo n.º 10
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"));
            }
        }
Ejemplo n.º 11
0
        public ActionResult CreateAdmin(mycook.Models.user usermodel)
        {
            mycookEntities me = new mycookEntities();



            var userDetails = me.users.Where(x => x.username == usermodel.username).FirstOrDefault();

            if (userDetails == null)
            {
                user newAdmin = new user();
                newAdmin.username     = usermodel.username;
                newAdmin.password     = usermodel.password;
                newAdmin.subscription = usermodel.subscription;
                newAdmin.role         = "Admin";
                newAdmin.status       = "ON";

                me.users.Add(newAdmin);
                me.SaveChanges();

                TempData["msg"] = "Record Saved Successfully.";
                // ViewBag.DataExists = true;
                // ViewBag.Javascript = "<script language='javascript' type='text/javascript'>alert('Data Already Exists');</script>";

                return(RedirectToAction("admins"));
            }
            else
            {
                usermodel.LoginErrorMessage = "Error";
            }



            /*
             * mycookEntities me = new mycookEntities();
             *
             * List<user> aux = me.users.ToList();
             *
             * // userDetails = me.users.Where(x => x.username == usermodel.username && x.password == usermodel.password).FirstOrDefault();
             * var userDetails = me.users.Where(x => x.username == usermodel.username).FirstOrDefault();
             *
             * if (userDetails == null)
             * {
             *
             *  if (usermodel.username == null && usermodel.password == null)
             *  {
             *      usermodel.LoginErrorMessage = "Fill both fields please";
             *  }
             *
             *  if (usermodel.username != null && usermodel.password != null)
             *  {
             *      usermodel.LoginErrorMessage = "Wrong username and/or password";
             *  }
             *
             *
             *  return View("Index", usermodel);
             * }
             * else
             * {
             *  return Content("<script language='javascript' type='text/javascript'>alert('Thanks for Feedback!');</script>");
             *
             * }
             *
             */

            return(View("create"));
        }