public virtual JsonResult AddProductToCart_Details(int productId, int shoppingCartTypeId, int qty) { if (Session[SessionConstants.SESSION_CONTEXT_INSTANCE] != null) { CartServices service = new CartServices(); //check seesion is available, only logged in users can add to cart/wishlist User user = (User)(Session[SessionConstants.SESSION_CONTEXT_INSTANCE]); //add to shopping cart if (shoppingCartTypeId == 1) { CartItem item = new CartItem(); int cartId = 0; item.Id = productId; item.UserId = user.UserId; item.Qty = qty; List <CartItem> list = service.GetCartItems(item.UserId); //check item is already exists in cart foreach (var cartItem in list) { if (cartItem.Id == item.Id) { cartId = cartItem.cartId; break; } } if (cartId > 0) { //add new items to the cart int id = service.EditCartItems(item); return(Json(new { Status = true, Message = "Succesfully updated the shopping cart..." }, JsonRequestBehavior.AllowGet)); } else { //update the cart with new quantitiesS int id = service.AddCartItems(item); return(Json(new { Status = true, Message = "Succesfully added to the shopping cart..." }, JsonRequestBehavior.AllowGet)); } } //add to wishlist else { wishListItem item = new wishListItem(); item.UserId = user.UserId; item.Id = productId; List <wishListItem> list = service.GetWishListItems(item.UserId); //check item is already exists in wishlist foreach (var wishItem in list) { if (wishItem.Id == item.Id) { //if already item exists alret user return(Json(new { Status = true, Message = "Item already exists in wishlist..." }, JsonRequestBehavior.AllowGet)); } } //if item not in wishlist,add item to the user's wishlist int id = service.AddWishListItems(item); return(Json(new { Status = true, Message = "Succesfully added to the wishlist..." }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { Status = false, Message = "Not logged-in..." }, JsonRequestBehavior.AllowGet)); } }