Esempio n. 1
0
 private void View_ProductChecked(products_in_shop item, int quantity)
 {
     if (quantity > 0 && quantity <= item.Quantity)
     {
         _cart.AddProduct(item, quantity);
     }
     _view.UpdateCart(_cart);
 }
Esempio n. 2
0
 public ProductControl(products_in_shop item, int checkedItemQuantity)
 {
     InitializeComponent();
     this.tbName.Text                   = item.Name;
     this.tbBrand.Text                  = item.Brand;
     this.lbAvailableQuantity.Text      = item.Quantity.ToString();
     this.numericUpDownQuantity.Value   = checkedItemQuantity;
     this.numericUpDownQuantity.Maximum = item.Quantity;
     this.labelPrice.Text               = item.Price.ToString() + ConstantTexts.PLN;
     _item = item;
 }
Esempio n. 3
0
        public static products_in_shop DeepCopy(this products_in_shop source)
        {
            var ser = new DataContractSerializer(typeof(products_in_shop));

            using (var stream = new MemoryStream())
            {
                ser.WriteObject(stream, source);
                stream.Seek(0, SeekOrigin.Begin);
                return((products_in_shop)ser.ReadObject(stream));
            }
        }
Esempio n. 4
0
        public void RemoveProduct()
        {
            //arrange
            products_in_shop product = new products_in_shop();

            product.Id       = 5;
            product.Quantity = 4;

            int quantity = 5;

            ShoppingCart shoppingCart = new ShoppingCart();
            KeyValuePair <products_in_shop, int> expectedKeyValue = new KeyValuePair <products_in_shop, int>(product, quantity);

            int expectedCount = 0;

            //act
            shoppingCart.AddProduct(product, quantity);
            shoppingCart.RemoveProduct(expectedKeyValue.Key);
            //assert
            Assert.AreEqual(expectedCount, shoppingCart.Count);
        }
Esempio n. 5
0
        public void AddNewProduct()
        {
            //arrange
            products_in_shop product = new products_in_shop();

            product.Id       = 5;
            product.Quantity = 4;

            int quantity = 5;

            ShoppingCart shoppingCart = new ShoppingCart();
            KeyValuePair <products_in_shop, int> expectedKeyValue = new KeyValuePair <products_in_shop, int>(product, quantity);

            //act
            shoppingCart.AddProduct(product, quantity);

            //assert
            foreach (var item in shoppingCart)
            {
                Assert.AreEqual(expectedKeyValue, item);
            }
        }
 public void UpdateQuantity(products_in_shop item, int quantity)
 {
     tbItem.Text = item.Name + " - " + item.Brand + " - " + quantity;
 }
 public ShoppingCartControlView(products_in_shop item, int quantity) : this()
 {
     _item       = item;
     tbItem.Text = item.Name + " - " + item.Brand + "   x " + quantity;
 }
Esempio n. 8
0
 public void ProductControl_ProductChecked(products_in_shop item, int quantity)
 {
     ProductAdded?.Invoke(item, quantity);
 }
Esempio n. 9
0
 private void ShoppingCartControl_ProductRemovedFromCart(products_in_shop item)
 {
     ProductRemovedFromCart?.Invoke(item);
 }
Esempio n. 10
0
 private bool IsInCart(products_in_shop item) => _cart.GetProducts().ContainsKey(item);
Esempio n. 11
0
 private void View_ProductRemovedFromCart(products_in_shop item)
 {
     _cart.RemoveProduct(item);
     UpdateProductsList();
     _view.UpdateCart(_cart);
 }