Пример #1
0
        // PUT api/product/5
        public HttpResponseMessage Put([FromUri]Guid id, Product product)
        {
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest);
            if (product == null)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound);
            }
            else
            {
                if (ModelState.IsValid && id == product.ID)
                {
                    ProductServiceClient productService = new iSnackServiceReference.ProductServiceClient();
                    var mapper = ObjectMapperManager.DefaultInstance.GetMapper<Product, ProductEntity>();
                    var newProduct = mapper.Map(product);
                    bool isSucc = productService.Update(newProduct);
                    if (isSucc)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK, product);
                    }
                }
            }

            return response;
        }