public async Task<HttpResponseMessage> Post(ProductRequestModel requestModel) { var postResult = await _productService.AddProduct(requestModel.ToProduct()); if (!postResult.IsSuccess) return new HttpResponseMessage(HttpStatusCode.BadRequest); var response = Request.CreateResponse(HttpStatusCode.Created, postResult.Entity.ToProductDto()); response.Headers.Location = new Uri(Url.Link("GetProductById", new { id = postResult.Entity.ProductID })); return response; }
public async Task<HttpResponseMessage> Put(int id, ProductRequestModel requestModel) { var product = await _productService.GetProduct(id); if (product == null) return new HttpResponseMessage(HttpStatusCode.NotFound); var putResult = await _productService.EditProduct(requestModel.ToProduct()); if (!putResult.IsSuccess) return new HttpResponseMessage(HttpStatusCode.BadRequest); var response = Request.CreateResponse(HttpStatusCode.OK, putResult.Entity.ToProductDto()); response.Headers.Location = new Uri(Url.Link("GetProductById", new { id = putResult.Entity.ProductID })); return response; }