// POST api/product public HttpResponseMessage Post(Product item) { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest); if (item != null && ModelState.IsValid) { ProductServiceClient productService = new iSnackServiceReference.ProductServiceClient(); var mapper = ObjectMapperManager.DefaultInstance.GetMapper<Product, ProductEntity>(); var product = mapper.Map(item); bool isSucc = productService.Create(product); if (isSucc) { //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, item); //response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = item.ID })); response = Request.CreateResponse(HttpStatusCode.Created, new { success = true }); } } return response; }
// 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; }