public ActionResult List(OrderViewModel order, int onhand)
        {
            if (!ModelState.IsValid)
            {
                TempData["error"] = "**invalid quantity!!";
                return(RedirectToAction("Index", "Order", new { id = order.SelectedProduct.ProductID }));
            }
            if (order.SelectedProduct.Quantity > onhand)
            {
                TempData["error"] = "*quantity not available!";
                return(RedirectToAction("Index", "Order", new { id = order.SelectedProduct.ProductID }));
            }
            CartViewModel carta = new CartViewModel();

            if (Session["paymentsucces"] != null && Session["paymentsucces"].ToString() == "true")
            {
                carta = cart.GetEmptyCart(Session["paymentsucces"].ToString());
                Session["paymentsucces"] = null;
            }
            CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID);

            //Assign the quantity of the selected product to the quantity of the added product
            model.AddedProduct.Quantity = order.SelectedProduct.Quantity;
            //Call the method AddtoCart
            cart.AddToCart(model);
            //Assign model to the TempData
            TempData["cart"] = model;
            return(RedirectToAction("List", "Cart"));
        }
 public ActionResult AddToCart(string id, string qty, string size)
 {
     if (qty.ToLower() == "select...")
     {
         qty = "1";
     }
     if (size == "" || size == "0")
     {
         using (var context = new RachnaDBContext())
         {
             int     prdId   = Convert.ToInt32(id);
             Product Product = context.Product.Where(m => m.Product_Id == prdId).FirstOrDefault();
             if (Product.Product_Has_Size)
             {
                 string[] sizes = Product.Product_Size.Split(',');
                 size = sizes[0].ToString();
             }
             else
             {
                 size = "No Size";
             }
         }
     }
     _mcartmdl.AddToCart(id, qty, size);
     return(Redirect(HttpContext.Request.UrlReferrer.AbsoluteUri));
 }
Пример #3
0
        public ActionResult Index(OrderViewModel order)
        {
            CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID);

            model.AddedProduct.Quantity = order.SelectedProduct.Quantity;
            cart.AddToCart(model);
            TempData["cart"] = model;
            return(View(model));
        }
Пример #4
0
        public RedirectToRouteResult List(OrderViewModel order)
        {
            CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID);

            model.AddedProduct.Quantity = order.SelectedProduct.Quantity;
            cart.AddToCart(model);
            TempData["cart"] = model;
            return(RedirectToAction("Index", "Checkout"));
        }
        public RedirectToRouteResult List(OrderViewModel order)
        {
            CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID);

            //Assign the quantity of the selected product to the quantity of the added product
            model.AddedProduct.Quantity = order.SelectedProduct.Quantity;
            //Call the method AddtoCart
            cart.AddToCart(model);
            //Assign model to the TempData
            TempData["cart"] = model;
            return(RedirectToAction("List", "Cart"));
        }
Пример #6
0
        public RedirectToRouteResult List(OrderViewModel order)
        {
            if (order.SelectedProduct.Quantity < 1)
            {
                TempData["invQ"] = order.SelectedProduct.Quantity;
                return(RedirectToAction("Index", "Order", new { id = order.SelectedProduct.ProductID }));
            }


            CartViewModel model = cart.GetCart(order.SelectedProduct.ProductID);

            //Assign the quantity of the selected product to the quantity of the added product
            model.AddedProduct.Quantity = order.SelectedProduct.Quantity;
            //Call the method AddtoCart
            cart.AddToCart(model);
            //Assign model to the TempData
            TempData["cart"] = model;  //data passign from controller to view
            return(RedirectToAction("List", "Cart"));
        }
Пример #7
0
        public IActionResult AddToCart(int id, int quantity)
        {
            var model = new CartModel();
            var cart  = model.AddToCart(id, quantity);
            List <CartModel> list2 = null;

            if (TempData["cart"] == null)
            {
                list.Add(cart);
                TempData["cart"] = JsonConvert.SerializeObject(list);
                list2            = JsonConvert.DeserializeObject <List <CartModel> >(TempData["cart"] as string);
                //list2 = ViewData["cart"] as List<CartModel>;
            }
            else
            {
                list2 = JsonConvert.DeserializeObject <List <CartModel> >(TempData["cart"] as string);
                //list2 = ViewData["cart"] as List<CartModel>;
                int flag = 0;
                foreach (var item in list2)
                {
                    if (item.MedicineId == cart.MedicineId)
                    {
                        item.Quantity   += cart.Quantity;
                        item.TotalPrice += cart.TotalPrice;
                        flag             = 1;
                    }
                }
                if (flag == 0)
                {
                    list2.Add(cart);
                    //new item
                }
                TempData["cart"] = JsonConvert.SerializeObject(list2);
            }
            TempData["item_count"] = JsonConvert.SerializeObject(list2.Count);
            TempData.Keep();
            return(RedirectToAction("Index", "Medicine"));
        }