private void debug1()
        {
            shopStock example = (from u in db.shopStock where u.owner_id == 2 select u).FirstOrDefault();
            shopStock test    = new shopStock();

            test.owner_id   = 2;
            test.ingredient = "hard_tortilla";
            test.stock      = 333;
            //test.ingredients = (from u in db.ingredients where u.ingredient == "hard_tortilla" select u).FirstOrDefault();
            //test.userData = (from u in db.userData where u.id == 2 select u).FirstOrDefault();
            //test.ingredients = new ingredients();
            //test.userData = new userData();
            db.shopStock.Add(test);
            db.SaveChanges();
        }
Beispiel #2
0
        void UserWindowClose(object sender, EventArgs e) //shows previous window when userWin closes.
        {
            //backup userdata to db.
            //update shopstock
            //update userData
            var q = (from u in db.userData where u.id == user.id select u).SingleOrDefault();

            if (q == null)
            {
                throw new Exception("user is missing from userData.");
            }
            q.money    = user.money;
            q.shopName = shop.ShopName;
            foreach (KeyValuePair <string, int> ingr in shop.StockPrint())
            {
                var stockQ = (from u in db.shopStock where u.owner_id == user.id && u.ingredient == ingr.Key select u).SingleOrDefault();
                if (stockQ == null)
                {
                    shopStock newItem = new shopStock();
                    newItem.owner_id   = user.id;
                    newItem.ingredient = ingr.Key;
                    newItem.stock      = ingr.Value;
                    //newItem.ingredients = (from u in db.ingredients where u.ingredient == ingr.Key select u).FirstOrDefault();
                    //newItem.userData = (from u in db.userData where u.id == user.id select u).FirstOrDefault();
                    shopStock itemTest = (from u in db.shopStock where u.ingredient == "cheese" select u).FirstOrDefault();

                    db.shopStock.Add(newItem);
                    //throw new Exception("error fetching shopStock query.");
                }
                else
                {
                    stockQ.stock = ingr.Value;
                }
            }
            db.SaveChanges();
            prevWin.Show();
        }