public HttpResponseMessage InsertIntoCart(string useremail, int productid, int cartquantity) { var cartProduct = entities.tblCarts.Where(c => c.useremail == useremail && c.productid == productid).FirstOrDefault(); var productquantity = entities.tblProducts.Where(p => p.productid == productid) .Select(p => p.productquantity).FirstOrDefault(); if ((cartProduct == null && cartquantity <= productquantity) || (cartProduct != null && cartProduct.cartquantity + cartquantity <= productquantity)) { if (cartProduct == null) { entities.proc_Insert_Into_Cart(useremail, productid, cartquantity); entities.SaveChanges(); } else { cartProduct.cartquantity = cartProduct.cartquantity + cartquantity; entities.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.OK, "Success")); } return(Request.CreateResponse(HttpStatusCode.OK, "not available")); }