private void med_add_to_cart_Click(object sender, EventArgs e) { //take amount from CartEntity p = new CartEntity(); foreach (var it in medRepos.GetAll()) { if (it.Id == (int)dataGridView1.CurrentCell.Value)//id in row { p.Id = it.Id; p.name = it.name; it.amount = it.amount - int.Parse(med_amount.Text);//amount in text } } //add amount to cart medRepos.Save(); cartRepos.Save(); // if (cartRepos.IsProductExist(factory.GetCartFlyweight(p, int.Parse(med_amount.Text)))) /////////////////////////////////// { factory.GetCartFlyweight(p, int.Parse(med_amount.Text)).amount += int.Parse(med_amount.Text); ///// cartRepos.Update(factory.GetCartFlyweight(p, int.Parse(med_amount.Text))); } else if ((factory.GetCartFlyweight(p, int.Parse(med_amount.Text))).amount == 0) { factory.GetCartFlyweight(p, int.Parse(med_amount.Text)).amount += int.Parse(med_amount.Text); cartRepos.Create(factory.GetCartFlyweight(p, int.Parse(med_amount.Text))); } else { cartRepos.Create(factory.GetCartFlyweight(p, int.Parse(med_amount.Text))); } }
public void OrderProduct() { Console.Write("\n\nChoose amount: "); int amount = int.Parse(Console.ReadLine()); CartEntity cartProduct = TakeAmountFromCurrentProduct(amount); cart.Save();// if (cart.IsProductExist(factory.GetCartFlyweight(cartProduct, amount))) { factory.GetCartFlyweight(cartProduct, amount).amount += amount; cart.Update(factory.GetCartFlyweight(cartProduct, amount)); } else if ((factory.GetCartFlyweight(cartProduct, amount)).amount == 0) { factory.GetCartFlyweight(cartProduct, amount).amount += amount; cart.Create(factory.GetCartFlyweight(cartProduct, amount)); } else { cart.Create(factory.GetCartFlyweight(cartProduct, amount)); } Console.WriteLine("\nProduct successfully added to cart!\n" + "1 : Back to table | 2 : Open cart" ); bool w = true; while (w) { int k = ((int)Console.ReadKey().KeyChar) - 48; if (k == 1) { w = false; } else if (k == 2) { PrintTableForm(); OpenCard(); w = false; } } }