public void AddProduct_ShouldReturnProductModel_WhenProductAddedSuccess()
        {
            //Arrange
            var title = "Playstation 5";
            var price = 8499;
            //Act
            var result = _productOperations.AddProduct(title, price);

            //Assert
            Assert.NotNull(result);
        }
Exemplo n.º 2
0
        public void DisplayProductCatalog()
        {
            ProductOperations productOperations = new ProductOperations(ProductFilePath);

            bool ProductStop = false;

            while (ProductStop != true)
            {
                Console.WriteLine("1. Add a Product");
                Console.WriteLine("2. List all Products");
                Console.WriteLine("3. Delete a Product(Enter Short Code or ID to delete)");
                Console.WriteLine("4. Search a Product");
                Console.WriteLine("5. Exit");

                int i = Convert.ToInt32(Console.ReadLine());
                switch (i)
                {
                case 1:
                    Console.WriteLine("Enter a Product Details");
                    productOperations.AddProduct();

                    break;

                case 2:
                    Console.WriteLine("List all Product");
                    productOperations.DisplayProduct();

                    break;

                case 3:
                    Console.WriteLine("Delete a Product");
                    productOperations.DeleteProduct();
                    break;

                case 4:
                    Console.WriteLine("Search a Product");
                    productOperations.findProduct();
                    break;

                case 5:
                    ProductStop = true;
                    Console.WriteLine("Exiting");
                    Console.Clear();
                    // this.DisplayCatalog();
                    break;

                default:
                    Console.WriteLine("Invalid Operation");
                    break;
                }
            }
        }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> AddProduct([FromBody] Product product)
        {
            try
            {
                await productOp.AddProduct(product);

                return(Request.CreateResponse(HttpStatusCode.Created, product));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Exemplo n.º 4
0
        //Method to add new product
        public bool AddProduct(Product pobj)
        {
            bool result = false;

            //checking if the product object is valid
            if (Validate(pobj))
            {
                //Creating DAL class object
                ProductOperations po = new ProductOperations();


                //Invoking its AddProduct method
                return(po.AddProduct(pobj));
            }
            return(result);
        }
        private void btnAddProduct_Click_1(object sender, EventArgs e)
        {
            Product product = new Product();

            product.ID          = Convert.ToInt32(textID.Text);
            product.Title       = textBox1.Text;
            product.Description = textBox2.Text;
            product.Color       = textBox3.Text;
            product.Size        = Convert.ToDouble(textBox4.Text);
            product.Price       = Convert.ToDouble(textBox5.Text);
            product.Stock       = Convert.ToInt32(textBox6.Text);

            ProductOperations bl = new ProductOperations();

            bl.AddProduct(product);

            MessageBox.Show("Operation succesful");
        }
 public void Save()
 {
     try
     {
         var isSaved = productOperationObj.AddProduct(currentProduct);
         LoadData();
         if (isSaved)
         {
             ProductOperationResultMessage = "Product has been added";
         }
         else
         {
             ProductOperationResultMessage = "Product has not been added";
         }
     }
     catch (Exception ex)
     {
         ProductOperationResultMessage = ex.Message;
     }
 }
Exemplo n.º 7
0
        private void buttonAddProduct_Click(object sender, EventArgs e)
        {
            Product product = new Product();

            if (textBoxProductName.Text == string.Empty || textBoxProductDesc.Text == string.Empty || textBoxProductPrice.Text == string.Empty)
            {
                MessageBox.Show("Please fill in the fields!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                Product isRecorded = db.Products.SingleOrDefault(x => x.Name == product.Name);
                if (isRecorded != null)
                {
                    MessageBox.Show("This product is already added.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    product.Name        = textBoxProductName.Text;
                    product.CategoryId  = (int)comboBoxCatOfProd.SelectedValue;
                    product.Description = textBoxProductDesc.Text;
                    product.Price       = Convert.ToDecimal(textBoxProductPrice.Text);
                    int affectedRow = productOperations.AddProduct(product);
                    if (affectedRow > 0)
                    {
                        MessageBox.Show("Product adding is successful!", "Information", MessageBoxButtons.OK);
                        Cleartxt(this);
                        getProducts();
                        FillAllComboBox();
                    }
                    else
                    {
                        MessageBox.Show("Product is couldn't be added!", "Information", MessageBoxButtons.OK);
                    }
                }
            }
        }