コード例 #1
0
        public HttpResponseMessage Post(VariantModel variant)
        {
            HttpResponseMessage response;
            ModelsValidation    validation = new ModelsValidation();
            VariantData         data       = new VariantData();

            if (ModelState.IsValid)
            {
                if (validation.DoesProductExist(variant.ProductId) == true)
                {
                    data.SaveVariant(variant);
                    response = Request.CreateResponse(HttpStatusCode.Created);
                }
                else
                {
                    response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "There is no product with given Id parameter." });
                }
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, new { Message = "Model is invalid.", ModelValidation = "Product's id must be greater than 0. BasePrice, Tax and InStock must be a positive numbers." });
            }

            return(response);
        }