Ejemplo n.º 1
0
        public ActionResult AddProduct(Products_Detail pro)
        {
            ViewBag.Type       = "Seller";
            ViewBag.Controller = "Home";
            var seller = (User_Accounts)Session["user"];

            if (pro.Imgage_url == "" || pro.Imgage_url == null)
            {
                pro.Imgage_url = "/Photo/images/drinkDefault.png";
            }
            pro.Seller = seller.Username;
            if (ModelState.IsValid)
            {
                var i = new ProductModel().AddProduct(pro);
                if (i)
                {
                    return(RedirectToAction("Shop"));
                }
                else
                {
                    ModelState.AddModelError("", "Đã xảy ra lỗi");
                }
            }
            else
            {
                ModelState.AddModelError("", "Đã xảy ra lỗi");
            }
            return(View("AddProduct"));
        }
Ejemplo n.º 2
0
 public bool DeleteProduct(int id)
 {
     try
     {
         Products_Detail pro = _context.Products_Detail.Where(x => x.ProductId == id).Single();
         foreach (var u in _context.Orders)
         {
             if (u.ProductId == id)
             {
                 _context.Orders.Remove(u);
             }
         }
         foreach (var u in _context.Carts)
         {
             if (u.ProductId == id)
             {
                 _context.Carts.Remove(u);
             }
         }
         _context.Products_Detail.Remove(pro);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 3
0
 public bool AddProduct(Products_Detail product)
 {
     try
     {
         _context.Products_Detail.Add(product);
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 4
0
        public void Add(Products_Detail products, int amount = 1)
        {
            var item = items.SingleOrDefault(p => p.productsInCart.ProductId == products.ProductId);

            if (item == null)
            {
                items.Add(new CartItem
                {
                    productsInCart = products,
                    amountInCart   = amount
                });
            }
            else
            {
                item.amountInCart += amount;
            }
        }
Ejemplo n.º 5
0
 public bool UpdateProduct(Products_Detail pro)
 {
     try
     {
         var product = _context.Products_Detail.Find(pro.ProductId);
         product.Seller     = pro.Seller;
         product.Name       = pro.Name;
         product.Imgage_url = pro.Imgage_url;
         product.Desciption = pro.Desciption;
         product.CatId      = pro.CatId;
         product.Size       = pro.Size;
         product.Price      = pro.Price;
         product.Quantity   = pro.Quantity;
         _context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
 public ActionResult UpdateProduct(Products_Detail product)
 {
     ViewBag.Type       = "Seller";
     ViewBag.Controller = "Home";
     if (ModelState.IsValid)
     {
         var i = new ProductModel().UpdateProduct(product);
         if (i)
         {
             return(RedirectToAction("Shop"));
         }
         else
         {
             ModelState.AddModelError("", "Đã xảy ra lỗi");
         }
     }
     else
     {
         ModelState.AddModelError("", "Đã xảy ra lỗi");
     }
     return(RedirectToAction("UpdateProduct", new { @productId = product.ProductId }));
 }
Ejemplo n.º 7
0
 public IEnumerable <Order> GetOrderByProduct(Products_Detail pro)
 {
     return(_context.Orders.Where(x => x.ProductId == pro.ProductId).ToList());
 }