// GET api/cartitem/5 public HttpResponseMessage Get(string token, int id) { try { // token correct if (token != null && Common.Token.Equals(token)) { List <CartItemModel> items = new List <CartItemModel>(); DBItem db = new DBItem(token); // Accessing the DB to get the Items bool success = db.GetCartItems(id, out items); if (success) { // HTTP 200 - Cart found if (items.Count() != 0) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(items), System.Text.Encoding.UTF8, "application/json"); return(response); } // HTTP 404 - Cart not found else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "No Cart Items Found")); } } else { // HTTP 500 - Internal Error return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Internal Error")); } } else { new Logging().LogProgress(token, Common.CallerIP, new Exception("Invalid token passed")); // HTTP 400 - Bad Request (token incorrect) return(Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid token passed")); } } catch (Exception ex) { new Logging().LogProgress(token, Common.CallerIP, ex); // HTTP 500 - Internal Error return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Internal Error")); } }