Beispiel #1
0
        public void ProductsDbAddProductReturnsFalse()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.IsFalse(productsDb.AddProduct(product));
        }
Beispiel #2
0
        public void ProductsDbContainsProductReturnsTrue()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.IsTrue(productsDb.ContainsProduct(product.Id));
        }
Beispiel #3
0
        public void ProductsDbChangeProductInfoReturnsTrue()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.IsTrue(productsDb.ChangeProductInfo(product.Id, new Product(), 0));
        }
Beispiel #4
0
        public void ProductsDbGetProductReturnsProductAndInt()
        {
            //Assign
            var productsDb = new ProductsDB();
            var product    = new Product();

            productsDb.AddProduct(product);
            //Act + Assert
            Assert.AreEqual(productsDb.GetProduct(product.Name).Item1, product);
        }
Beispiel #5
0
 public IActionResult OnPost()
 {
     if (!ModelState.IsValid)
     {
         return(Page());
     }
     else
     {
         ProductsDB.AddProduct(NewProduct, _configuration);
         return(RedirectToPage("/Index"));
     }
 }
Beispiel #6
0
        private void btnProAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (Validator.IsPresent(txtNewProductName, "New Product Name") && Validator.IsCorrectLength(txtNewProductName, "Name", 20) && Validator.IsNameValid(txtNewProductName, "Name"))
                {
                    Products newProduct = productUpdate1(txtNewProductName);


                    newProduct.ProductId = ProductsDB.AddProduct(newProduct);


                    MessageBox.Show("Product is updated :)");
                    UpdateAllInfos();
                    productsDataGridView.DataSource = AllProducts;
                }
            }
            //catch the other error and show the ex error message from db class
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }
Beispiel #7
0
 // btn SAVE: save edit (update) or save add (create)
 private void threeBtnSave_Click(object sender, EventArgs e)
 {
     if (threeTab.SelectedIndex == 1) // EDIT MODE
     {
         // get current displaying product obj
         var currentProd = ProductsDB.GetProducts().
                           SingleOrDefault(p => p.ProductId == Convert.ToInt32(threeTxtEditProdId.Text));
         // initiate new product obj
         Products newProd;
         // validate: product name is empty or duplicated
         if (Validator.TBIsEmpty(threeTxtEditProdName, "Product Name") ||
             FindDuplicatedProductName(threeTxtEditProdName.Text))
         {
             // empty or same, do not perform update
             threeTxtEditProdName.Text = currentProd.ProdName;
             threeTxtEditProdName.SelectAll();
             return;
         }
         else
         {
             // name is valid, create new Product obj
             newProd = new Products {
                 ProdName = threeTxtEditProdName.Text
             }
         };
         // try to perform update
         try
         {
             Console.WriteLine("Old prod name is: " + currentProd.ProdName);
             var rowsAffected = ProductsDB.UpdateProduct(currentProd, newProd);
             MessageBox.Show($"{rowsAffected} record was updated.", "Congratulations");
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
     else if (threeTab.SelectedIndex == 2) // ADD MODE
     {
         // validate input, check if empty or have duplicated name
         if (!Validator.TBIsEmpty(threeTxtAddProdName, "Product Name") &&
             !FindDuplicatedProductName(threeTxtAddProdName.Text))
         {
             // validation passed, create new product using user input
             var newProd = new Products {
                 ProdName = threeTxtAddProdName.Text
             };
             // try to insert into DB
             try
             {
                 var id = ProductsDB.AddProduct(newProd);
                 MessageBox.Show($"New product {newProd.ProdName} is added, product id is: {id}.", "Congratulations");
                 threeTxtAddProdName.Clear();
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }