public ActionResult DeleteConfirmed(int id)
        {
            Painting_Copy painting_Copy = db.Painting_Copies.Find(id);

            db.Painting_Copies.Remove(painting_Copy);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "CopyID,PaintingID,Price,StatusID,SizeID")] Painting_Copy painting_Copy)
 {
     if (ModelState.IsValid)
     {
         db.Entry(painting_Copy).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PaintingID = new SelectList(db.Paintings, "PaintingID", "PaintingTitle", painting_Copy.PaintingID);
     ViewBag.SizeID     = new SelectList(db.Sizes, "SizeID", "SizeName", painting_Copy.SizeID);
     ViewBag.StatusID   = new SelectList(db.Status, "StatusID", "StatusName", painting_Copy.StatusID);
     return(View(painting_Copy));
 }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Painting_Copy painting_Copy = db.Painting_Copies.Find(id);

            if (painting_Copy == null)
            {
                return(HttpNotFound());
            }
            return(View(painting_Copy));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Painting_Copy painting_Copy = db.Painting_Copies.Find(id);

            if (painting_Copy == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PaintingID = new SelectList(db.Paintings, "PaintingID", "PaintingTitle", painting_Copy.PaintingID);
            ViewBag.SizeID     = new SelectList(db.Sizes, "SizeID", "SizeName", painting_Copy.SizeID);
            ViewBag.StatusID   = new SelectList(db.Status, "StatusID", "StatusName", painting_Copy.StatusID);
            return(View(painting_Copy));
        }
        public ActionResult AddToCart(int qty, int paintingID)
        {
            Dictionary <int, CartItemViewModel> shoppingCart = null;

            if (Session["cart"] != null)
            {
                shoppingCart = (Dictionary <int, CartItemViewModel>)Session["cart"]; //unboxing
            }
            else
            {
                shoppingCart = new Dictionary <int, CartItemViewModel>();
            }

            Painting_Copy product = db.Painting_Copies.Where(b => b.PaintingID == paintingID).FirstOrDefault();

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }
            else
            {
                CartItemViewModel item = new CartItemViewModel(qty, product);

                if (shoppingCart.ContainsKey(product.PaintingID))
                {
                    shoppingCart[product.PaintingID].Qty += qty;
                }
                else
                {
                    shoppingCart.Add(product.PaintingID, item);
                }
                Session["cart"] = shoppingCart;

                Session["confirm"] = $"'{product.Painting.PaintingTitle}' (Quantity: {qty}) Added to cart";
            }

            return(RedirectToAction("Index", "ShoppingCart"));
        }
 public CartItemViewModel(int qty, Painting_Copy product)
 {
     Qty     = qty;
     Product = product;
 }