public ActionResult AddProduct()
        {
            using (IDal dal = new Dal())
            {
               if(Request.HttpMethod == "POST")
               {
                   string name = Request.Form["name"];
                   string description = Request.Form["description"];
                   string level = Request.Form["level"];
                   //string imagePath = Request.Form["imagePath"];
                   string imagePath = "img/Products";
                   string unitPriceString = Request.Form["price"];
                   string categoriesString = Request.Form["categories"];
                   Console.WriteLine(unitPriceString);

                   double unitPrice = Double.Parse(unitPriceString);

                   int categories = Convert.ToInt32(categoriesString);

                    dal.CreateProduct(name, description,  level,  imagePath, unitPrice, categories);
                    return View();
               }
               else
               {
                   string error = "error";
                   string output = new JavaScriptSerializer().Serialize(error);
                   return Content(error);
               }

            }
        }
示例#2
0
        public void CreateProduct_WithNewProducts_GetAllOfProductRightReturnProduct()
        {
            using (IDal dal = new Dal())
            {
                dal.CreateProduct("Boite de 1000 kapla", "img/products/", "Coffret en boit contenant 1000 kapla et un livret de construction", "3 - 6 ans", 145.76, 1);
                List<Product> products = dal.GetAllOfProducts();

                Assert.IsNotNull(products);
                Assert.AreEqual(1, products.Count);
                Assert.AreEqual("Boite de 1000 kapla", products[0].ProductName);
                Assert.AreEqual("Coffret en boit contenant 1000 kapla et un livret de construction", products[0].Description);
                Assert.AreEqual("3 à 6 ans", products[0].Level);
                Assert.AreEqual(145.76, products[0].UnitPrice);
            }
        }