public void WriteToPanel(UpdatedCart currCart, int currNum)
        {
            TextBox txtChain = (TextBox)Controls.Find($"compChain{currNum}", true).FirstOrDefault();

            txtChain.Text = currCart.ChainName;
            TextBox txtStore = (TextBox)Controls.Find($"compStore{currNum}", true).FirstOrDefault();

            txtStore.Text = currCart.StoreName;
            TextBox txtTotal = (TextBox)Controls.Find($"compTotal{currNum}", true).FirstOrDefault();

            txtTotal.Text = currCart.TotalPrice.ToString();
            for (int i = 1; i <= currCart.CheapItems.Count; i++)
            {
                TextBox txtItem = (TextBox)Controls.Find($"compItem{i}Ch{currNum}", true).FirstOrDefault();
                txtItem.Text = currCart.CheapItems[i - 1].ItemName;
                TextBox txtPrice = (TextBox)Controls.Find($"compPrice{i}Ch{currNum}", true).FirstOrDefault();
                txtPrice.Text = currCart.CheapItems[i - 1].Price.ToString();
            }
            for (int i = 1; i <= currCart.ExpensiveItems.Count; i++)
            {
                TextBox txtItem = (TextBox)Controls.Find($"compItem{i}Ex{currNum}", true).FirstOrDefault();
                txtItem.Text = currCart.ExpensiveItems[i - 1].ItemName;
                TextBox txtPrice = (TextBox)Controls.Find($"compPrice{i}Ex{currNum}", true).FirstOrDefault();
                txtPrice.Text = currCart.ExpensiveItems[i - 1].Price.ToString();
            }
            string[] missingItems = currCart.Items.Where(i => i.Price == 0).Select(i => i.ItemName).ToArray();
            ComboBox comMissing   = (ComboBox)Controls.Find($"compCombo{currNum}", true).FirstOrDefault();

            comMissing.Items.AddRange(missingItems);
        }
Exemple #2
0
        public string EditQuantity(int keynum, int userid, int productid, int quantity, bool IncrementOrNah, UpdatedCart myCart)
        {
            Dictionary <int, string> newCustomerCart = new Dictionary <int, string>();
            User user = dbContext.Users.FirstOrDefault(u => u.UserId == userid);

            Console.WriteLine(myCart.cart);
            string packagedCart = JsonConvert.SerializeObject(newCustomerCart);

            user.ShoppingCart = myCart.cart;
            Console.WriteLine(user.ShoppingCart);
            Console.WriteLine("To increment or not to increment?....", IncrementOrNah);
            Product product = dbContext.Products.FirstOrDefault(j => j.ProductId == productid);

            if (IncrementOrNah == true)
            {
                product.Quantity += 1;
            }
            else if (IncrementOrNah == false)
            {
                product.Quantity -= 1;
            }

            Console.WriteLine("Quantity adjusted product", product);


            dbContext.SaveChanges();

            //foreach (KeyValuePair<int, string> entry in JsonConvert.DeserializeObject<Dictionary<int, string>>(user.ShoppingCart))
            //{
            //    //newCustomerCart.Add(entry.Key, entry.Value);
            //    if(entry.Key == keynum)
            //    {
            //        var CartDetails = JsonConvert.DeserializeObject(entry.Value);
            //        Console.WriteLine(entry.Key + "%%%%%%%^^^^^^^^ EditQuantityRouteCheck2 ^^^^^^^%%%%%%% " + CartDetails);
            //        Console.WriteLine(entry.Key + "%%%%%%%^^^^^^^^ EditQuantityRouteCheck ^^^^^^^%%%%%%% " + entry.Value);
            //    }
            //}



            var success = new { ShoppingCartTest = user.ShoppingCart, ProductTest = product, BooleanTest = IncrementOrNah };

            return(JsonConvert.SerializeObject(success));
        }