//private DBingredient db = new DBingredient();

        // GET: Boodschap
        public ActionResult Index()
        {
            User user = (User)Session["user"];

            if (user == null)
            {
                return(RedirectToAction("Index", "User"));
            }
            //DBingredient context = new DBingredient();
            using (DBingredient context = new DBingredient())
            {
                int            boodschapLijstID = user.boodschapLijst.BoodschapLijstID;
                BoodschapLijst boodschapLijst   = context.BoodschapLijsts.Find(boodschapLijstID);
                //List<BoodschapIngredient> lijst = context.BoodschapIngredients.ToList();

                if (boodschapLijst != null)
                {
                    foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients)
                    {
                        int        ingredientID = boodschapIngredient.ingredient.ingredientID;
                        Ingredient ig           = context.Ingredients.Find(ingredientID);
                        boodschapIngredient.ingredient = ig;
                    }
                    return(View(boodschapLijst.BoodschapIngredients));
                }

                return(View());
            }
        }
示例#2
0
        // GET api/values/5
        public IEnumerable <BoodschapIngredientModel> Get(int id)
        {
            List <BoodschapIngredient>      boodschapLijst      = new List <BoodschapIngredient>();
            List <BoodschapIngredientModel> boodschapModelLijst = new List <BoodschapIngredientModel>();

            using (DBingredient context = new DBingredient())
            {
                User           user               = context.Users.Find(id);
                int            boodschapLijstID   = user.boodschapLijst.BoodschapLijstID;
                BoodschapLijst boodschaplijstUser = context.BoodschapLijsts.Find(boodschapLijstID);
                boodschapLijst = boodschaplijstUser.BoodschapIngredients;

                foreach (BoodschapIngredient boodschapIngredient in boodschapLijst)
                {
                    BoodschapIngredientModel model = new BoodschapIngredientModel();
                    model.BoodschapIngredientID = boodschapIngredient.BoodschapIngredientID;
                    model.naam        = boodschapIngredient.ingredient.name;
                    model.merk        = boodschapIngredient.ingredient.merk;
                    model.Hoeveelheid = boodschapIngredient.Hoeveelheid;
                    model.Eenheid     = boodschapIngredient.Eenheid;
                    boodschapModelLijst.Add(model);
                }
            }



            return(boodschapModelLijst);
        }
        public ActionResult PrintConfirmed()
        {
            using (DBingredient context = new DBingredient())
            {
                User user = (User)Session["user"];

                int            boodschapLijstID = user.boodschapLijst.BoodschapLijstID;
                BoodschapLijst boodschapLijst   = context.BoodschapLijsts.Find(boodschapLijstID);

                string filePath = @"C:\Users\Public\BoodschappenLijst.txt";


                string[] lijnen     = new string[boodschapLijst.BoodschapIngredients.Count + 1];
                int      arraycount = 0;


                if (boodschapLijst != null)
                {
                    lijnen[0] = "Naam Merk Hoeveelheid Eenheid";


                    foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients)
                    {
                        arraycount         = arraycount + 1;
                        lijnen[arraycount] = $"{boodschapIngredient.ingredient.name} {boodschapIngredient.ingredient.merk} {boodschapIngredient.Hoeveelheid} {boodschapIngredient.Eenheid}";
                        //int ingredientID = boodschapIngredient.ingredient.ingredientID;
                        //Ingredient ig = context.Ingredients.Find(ingredientID);
                        //boodschapIngredient.ingredient = ig;
                    }

                    try
                    {
                        System.IO.File.WriteAllLines(filePath, lijnen);
                    }
                    catch
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                    }

                    return(RedirectToAction("Index"));
                }

                return(View());
            }
        }
示例#4
0
        public ActionResult Create([Bind(Include = "UserID,inlognaam,wachtwoord")] User user)
        {
            using (DBingredient context = new DBingredient())
            {
                if (ModelState.IsValid)
                {
                    Inventory      inventory      = new Inventory();
                    BoodschapLijst boodschapLijst = new BoodschapLijst();
                    user.inventory      = inventory;
                    user.boodschapLijst = boodschapLijst;
                    context.Users.Add(user);
                    context.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                return(View(user));
            }
        }
        public ActionResult Index(string input)
        {
            User user = (User)Session["user"];

            if (user == null)
            {
                return(RedirectToAction("Index", "User"));
            }
            using (DBingredient context = new DBingredient())
            {
                int boodschapLijstID = user.boodschapLijst.BoodschapLijstID;

                BoodschapLijst boodschapLijst = context.BoodschapLijsts.Find(boodschapLijstID);
                //List<InventoryIngredient> lijst = context.Users.Fin;
                if (boodschapLijst != null)
                {
                    foreach (BoodschapIngredient boodschapIngredient in boodschapLijst.BoodschapIngredients)
                    {
                        int        ingredientID = boodschapIngredient.ingredient.ingredientID;
                        Ingredient ig           = context.Ingredients.Find(ingredientID);
                        boodschapIngredient.ingredient = ig;
                    }

                    List <BoodschapIngredient> filterNaam = boodschapLijst.BoodschapIngredients.Where(e => e.ingredient.name.Contains(input)).ToList();

                    List <BoodschapIngredient> filterMerk = boodschapLijst.BoodschapIngredients.Where(e => e.ingredient.merk.Contains(input)).ToList();

                    foreach (BoodschapIngredient boodschapIngredient2 in filterMerk)
                    {
                        int ID = boodschapIngredient2.BoodschapIngredientID;


                        if (!filterNaam.Exists(x => x.BoodschapIngredientID == ID))
                        {
                            filterNaam.Add(boodschapIngredient2);
                        }
                    }

                    return(View(filterNaam));
                }

                return(View());
            }
        }
        public ActionResult Gekocht(int?id)
        {
            using (DBingredient context = new DBingredient())
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                BoodschapIngredient boodschapIngredient = context.BoodschapIngredients.Find(id);
                if (boodschapIngredient == null)
                {
                    return(HttpNotFound());
                }

                User user = (User)Session["user"];

                InventoryIngredient inventoryIngredient = new InventoryIngredient();
                inventoryIngredient.ingredient  = boodschapIngredient.ingredient;
                inventoryIngredient.Hoeveelheid = boodschapIngredient.Hoeveelheid;
                inventoryIngredient.Eenheid     = boodschapIngredient.Eenheid;

                int            inventoryID      = user.inventory.InventoryID;
                Inventory      inventory        = context.Inventories.Find(inventoryID);
                int            boodschapLijstID = user.boodschapLijst.BoodschapLijstID;
                BoodschapLijst boodschapLijst   = context.BoodschapLijsts.Find(boodschapLijstID);

                inventory.InventoryIngredients.Add(inventoryIngredient);
                //context.Entry(inventory.InventoryIngredients).State = EntityState.Modified;

                boodschapLijst.BoodschapIngredients.Remove(boodschapIngredient);
                //context.Entry(user.boodschapLijst).State = EntityState.Modified;

                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
示例#7
0
        public ActionResult Index(string id)
        {
            using (DBingredient context = new DBingredient())
            {
                int    ID;
                string message    = "";
                bool   isParsable = Int32.TryParse(id, out ID);

                if (isParsable == false)
                {
                    message = "Invalid number";
                }
                else
                {
                    ID   = Int32.Parse(id);
                    user = context.Users.Find(ID);

                    if (user == null)
                    {
                        message = "user is not in the database";
                    }
                    else
                    {
                        int       inventoryID = user.inventory.InventoryID;
                        Inventory inventory   = context.Inventories.Find(inventoryID);
                        user.inventory = inventory;
                        int            boodschapID    = user.boodschapLijst.BoodschapLijstID;
                        BoodschapLijst boodschapLijst = context.BoodschapLijsts.Find(boodschapID);
                        user.boodschapLijst = boodschapLijst;
                        Session["user"]     = user;
                        message             = $"Welkom {user.inlognaam}";
                    }
                }
                ViewBag.Message = message;
                return(View());
            }
        }