Esempio n. 1
0
        public bool editProduct(Product product)
        {
            ProductContext db = new ProductContext();
            if(product != null)
            {
                db.Entry(product).State = EntityState.Modified;
                //db.SaveChanges();
                bool saveFailed;
                do
                {
                    saveFailed = false;

                    try
                    {
                       db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException ex)
                    {
                        saveFailed = true;

                        // Update the values of the entity that failed to save from the store
                        ex.Entries.Single().Reload();
                    }

                } while (saveFailed);
                return true;
            }
            else
            {
                return false;
            }
        }
        public bool AddToCart(Product product, ShoppingCart cart)
        {
            if(product != null && cart != null)
            {
                var cartItem = storeDB.Carts.SingleOrDefault(
                c => c.CartId == cart.ShopCartId
                && c.ProductId == product.ProductId);

                if (cartItem == null)
                {

                    cartItem = new Cart
                    {
                        ProductId = product.ProductId,
                        CartId = cart.ShopCartId,
                        Count = 1,
                        DateCreated = DateTime.Now
                    };
                    storeDB.Carts.Add(cartItem);
                }
                else
                {
                    cartItem.Count++;
                }

                storeDB.SaveChanges();
                return true;
            }
            else
            {
                return false;
            }
        }
 public ActionResult Create(Product product)
 {
     if (ModelState.IsValid)
     {
         db.addProduct(product);
         return RedirectToAction("Index");
     }
     CategoryBLL catBLL = new CategoryBLL();
     ViewBag.CategoryId = catBLL.getCatList();
     return View(product);
 }
 public bool AddToCart(Product product, ShoppingCart cart)
 {
     if(product != null && cart != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 5
0
 public bool editProduct(Product product)
 {
     if (product != null)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 6
0
 public bool addProduct(Product product)
 {
     ProductContext db = new ProductContext();
     if(product != null)
     {
         db.Products.Add(product);
         db.SaveChanges();
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 7
0
 public IEnumerable<Product> getAllProducts()
 {
     var list = new List<Product>();
     var prod = new Product()
     {
         ProductId = 1,
         CategoryId = 1,
         Name = "lololo",
         Price = 123,
         ProductPicUrl = "/Content/Images/placeholder.gif"
     };
     list.Add(prod);
     list.Add(prod);
     list.Add(prod);
     return list;
 }
        public void test_edit1()
        {
            var controller = new ProductsController(new ProductBLL(new ProductStub()));

            var prod = new Product()
            {
                ProductId = 1,
                CategoryId = 1,
                Name = "lololo",
                Price = 123,
                ProductPicUrl = "/Content/Images/placeholder.gif"
            };

            var result = (ViewResult)controller.Edit(1);
            var resultProd = (Product)result.Model;

            Assert.AreEqual(resultProd.Name, prod.Name);
            Assert.AreEqual(result.ViewName, "");
        }
Esempio n. 9
0
 public Product getProd(int id)
 {
     if (id != 0)
     {
         var prod = new Product()
         {
             ProductId = 1,
             CategoryId = 1,
             Name = "lololo",
             Price = 123,
             ProductPicUrl = "/Content/Images/placeholder.gif"
         };
         return prod;
     }
     else
     {
         var prod = new Product();
         prod.ProductId = 0;
         return prod;
     }
 }
Esempio n. 10
0
 public bool editProduct(Product product)
 {
     return prod.editProduct(product);
 }
Esempio n. 11
0
 public bool addProduct(Product product)
 {
     return prod.addProduct(product);
 }
Esempio n. 12
0
 public bool AddToCart(Product product, ShoppingCart cart)
 {
     return temp.AddToCart(product, cart);
 }
        public void test_index()
        {
            var controller = new ProductsController(new ProductBLL(new ProductStub()));

            var list = new List<Product>();
            var prod = new Product()
            {
                ProductId = 1,
                CategoryId = 1,
                Name = "lololo",
                Price = 123,
                ProductPicUrl = "/Content/Images/placeholder.gif"
            };
            list.Add(prod);
            list.Add(prod);
            list.Add(prod);

            var result = (ViewResult)controller.Index();
            var resultList = (List<Product>)result.Model;

            Assert.AreEqual(result.ViewName, "");

            for(var i = 0; i < resultList.Count; i++)
            {
                Assert.AreEqual(list[i].ProductId, resultList[i].ProductId);
                Assert.AreEqual(list[i].CategoryId, resultList[i].CategoryId);
                Assert.AreEqual(list[i].Name, resultList[i].Name);
                Assert.AreEqual(list[i].Price, resultList[i].Price);
                Assert.AreEqual(list[i].ProductPicUrl, resultList[i].ProductPicUrl);
            }
        }
        public void test_post_edit()
        {
            var controller = new ProductsController(new ProductBLL(new ProductStub()));

            var prod = new Product()
            {
                ProductId = 1,
                CategoryId = 1,
                Name = "llll",
                Price = 213,
                ProductPicUrl = "/Content/Images/placeholder.gif"
            };

            var result = (RedirectToRouteResult)controller.Edit(prod);

            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "Index");
        }
        public void test_post_create2()
        {
            var controller = new ProductsController(new ProductBLL(new ProductStub()));

            var prod = new Product();
            controller.ViewData.ModelState.AddModelError("prouctname", "No product name");

            var result = (ViewResult)controller.Create(prod);

            Assert.IsTrue(result.ViewData.ModelState.Count == 1);
            Assert.AreEqual(result.ViewName, "");
        }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid || product != null)
     {
         db.editProduct(product);
         return RedirectToAction("Index");
     }
     CategoryBLL catBLL = new CategoryBLL();
     ViewBag.CategoryId = catBLL.getCatList();
     return View(product);
 }