Esempio n. 1
0
        public void GetAllProducts_ShouldReturnAllProducts()
        {
            // Arrange
            ProductDAO productDAO = new ProductDAO();
            Product    product1   = new Product("Fanta", 2);

            productDAO.AddProduct(product1);
            Product product2 = new Product("Cola", 2.5m);

            productDAO.AddProduct(product2);
            Product product3 = new Product("Bier", 1.8m);

            productDAO.AddProduct(product3);
            Product product4 = new Product("Cava glas", 4);

            productDAO.AddProduct(product4);
            Product product5 = new Product("Koffie", 2);

            productDAO.AddProduct(product5);

            // Act
            IReadOnlyList <Product> products = productDAO.GetAllProducts();

            // Assert
            products.Count.Should().Be(5);

            products.First().Name.Should().Be("Fanta");
            products.First().Price.Should().Be(2);
        }
 public ActionResult AddProduct(ProductModel model, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         var producDao = new ProductDAO();
         var product   = new Product();
         product.Name        = model.Name;
         product.IDCategory  = model.IDCategory;
         product.IDTradeMark = model.IDTradeMark;
         product.Description = model.Description;
         product.Price       = model.Price;
         product.CreateDate  = DateTime.Now;
         var    fileName = Path.GetFileName(file.FileName);
         var    filePath = fileName;
         string path     = Path.Combine(Server.MapPath("~/Content/Images"), fileName);
         file.SaveAs(path);
         model.Image   = filePath;
         product.Image = model.Image;
         producDao.AddProduct(product);
         return(RedirectToAction("Index"));
     }
     model.Categories = GetCategorySelectList(0);
     model.TradeMarks = GetTradeMarkSelectList(0);
     return(View(model));
 }
Esempio n. 3
0
        private void btnAddProduct_Click(object sender, EventArgs e)
        {
            try{
                if (txtProductName.Text.Length > 3)
                {
                    ProductDAO.AddProduct(Convert.ToInt32(cmbBusinessName.SelectedValue), txtProductName.Text);

                    MessageBox.Show("Se agrego el producto correctamente!", "HUGO DELIVERY",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);

                    txtProductName.Clear();
                    RefreshControl2();
                }
                else
                {
                    MessageBox.Show("No se pudo ingresar el producto!, intentelo más tarde", "HUGO DELIVERY",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error al ingresar el producto!, intentelo después", "HUGO DELIVERY",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 4
0
        public void GetProductByName_ShouldReturnCorrectProduct()
        {
            // Arrange
            ProductDAO productDAO = new ProductDAO();
            Product    product1   = new Product("Fanta", 2);

            productDAO.AddProduct(product1);
            Product product2 = new Product("Cola", 2.5m);

            productDAO.AddProduct(product2);
            // Act
            Product productInDb = productDAO.GetProductByName("Fanta");

            // Assert
            productInDb.Name.Should().Be("Fanta");
            productInDb.Price.Should().Be(2);
            productInDb.Id.Should().Be(1);
            productInDb.Should().NotBeEquivalentTo(product2);
        }
Esempio n. 5
0
 public static void AddProduct(SAN_PHAM_DTO proDTO)
 {
     try
     {
         ProductDAO.AddProduct(proDTO);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 6
0
        public void RemoveProduct_ShouldDeleteProductInDb_IfProductExists()
        {
            // Arrange
            ProductDAO productDAO = new ProductDAO();
            Product    product    = new Product("Fanta", 2);

            productDAO.AddProduct(product);

            // Act
            productDAO.RemoveProduct(1);

            // Assert
            productDAO.GetProduct(1).Should().BeNull();
        }
Esempio n. 7
0
        public bool AddProduct(Product product)        //增加
        {
            bool flag = false;

            if (pDAO.SelectProduct(product.ProductType) == null)
            {
                pDAO.AddProduct(product);
                flag = true;
            }
            else
            {
                flag = false;
            }

            return(flag);
        }
Esempio n. 8
0
        public bool AddProduct(CreateProduct product)
        {
            if (product == null)
            {
                return(false);
            }

            var result = _productDAO.AddProduct(product.Code, product.Name, product.UnitPrice);

            if (result)
            {
                return(result);
            }

            return(false);
        }
Esempio n. 9
0
        //#################### PRODUCT FUNCTIONS ###########################
        //#################### PRODUCT FUNCTIONS ###########################
        #region PRODUCT_FUNCTIONS

        //returnt false als de gegevens niet kloppen
        //returnt true als de gegevens wel kloppen en de klant is toegevoegd
        public bool AddProduct(Product product)
        {
            ProductDAO dao = daoFactory.GetProductDAO();

            try
            {
                return(dao.AddProduct(product));
            }
            catch (DatabaseException ex)
            {
                throw ex;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 10
0
        public void AddProduct_ShouldAddProduct()
        {
            // Arrange
            ProductDAO productDAO = new ProductDAO();
            Product    product    = new Product("Fanta", 2.5m);

            // Act
            productDAO.AddProduct(product);

            // Assert
            Product productInDb = productDAO.GetProduct(1);

            productInDb.Should().BeOfType <Product>();
            productInDb.Name.Should().Be("Fanta");
            productInDb.Price.Should().Be(2.5m);
            productInDb.Id.Should().Be(1);
        }
Esempio n. 11
0
 public static bool AddProduct(Product entity)
 {
     // 新产品入库的时候,产品已销售数量均为0
     entity.ProductSellNumber = 0;
     return(ProductDAO.AddProduct(entity));
 }
Esempio n. 12
0
 public bool AddProduct(Product product)
 {
     return(productDAO.AddProduct(product));
 }
Esempio n. 13
0
 public static int AddProduct(ModelView.PView item)
 {
     return(ProductDAO.AddProduct(item));
 }