コード例 #1
0
        public HttpResponseMessage add(ProductReview post)
        {
            // Check for errors
            if (post == null)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The post is null"));
            }
            else if (Product.MasterPostExists(post.product_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The product does not exist"));
            }
            else if (Customer.MasterPostExists(post.customer_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The customer does not exist"));
            }
            else if (Language.MasterPostExists(post.language_id) == false)
            {
                return(Request.CreateResponse <string>(HttpStatusCode.BadRequest, "The language does not exist"));
            }

            // Make sure that the data is valid
            post.review_date = AnnytabDataValidation.TruncateDateTime(post.review_date);
            post.rating      = AnnytabDataValidation.TruncateDecimal(post.rating, 0, 999999.99M);

            // Add the post
            ProductReview.Add(post);

            // Return the success response
            return(Request.CreateResponse <string>(HttpStatusCode.OK, "The post has been added"));
        } // End of the add method