public ActionResult AddToCart(int quantity, int Product_Id) { if (HttpContext.Session.GetString("UserName") == null) { return(RedirectToAction("Index", "UserLogin")); } Cart data = _cartRepo.GetbyProductId(Product_Id); if (data != null) { ViewBag.Already = "Product Already Added in Cart."; Product product = _productRepo.GetByeID(Product_Id); return(View(product)); } var prod = _productRepo.GetByeID(Product_Id); // Add cart Cart cart = new Cart(); string UserId = HttpContext.Session.GetString("UserId"); cart.UserId = Convert.ToInt32(UserId); cart.ProductId = Product_Id; cart.Qnt = quantity; int Totalcart = (cart.Qnt) * (Convert.ToInt32(prod.Saleprice)); cart.Total = Totalcart.ToString(); _cartRepo.InsertCart(cart); // Update Product int total; prod.Qnt = (prod.Qnt) - (cart.Qnt); total = Convert.ToInt32(prod.Price) * prod.Qnt; prod.Total = total.ToString(); _productRepo.UpdateProduct(prod); return(RedirectToAction("MyCart")); }