Esempio n. 1
0
        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;
                }
            }
        }
Esempio n. 2
0
        public void TestFactoryCartFlyweight()
        {
            //arrange
            CartEntity expectedEntity = new CartEntity()
            {
                Id   = 22222,
                name = "name"
            };
            //act
            FlyweightFactory factory = new FlyweightFactory();
            var result1 = factory.flyweightsArr.Exists(r => r.Id == expectedEntity.Id);

            factory.GetCartFlyweight(expectedEntity, 2);
            var result2 = factory.flyweightsArr.Exists(r => r.Id == expectedEntity.Id);

            //assert
            Assert.IsFalse(result1);
            Assert.IsTrue(result2);
        }
Esempio n. 3
0
        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)));
            }
        }