public async Task <IHttpActionResult> AddProduct([System.Web.Http.FromBody] UpdateProductRequest createRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = await _productService.CreateProductAsync(createRequest); var location = string.Format("/api/products/{0}", product.Id); return(Created <Product>(location, product)); }
public async Task <IHttpActionResult> AddProduct([FromBody] UpdateProductRequest createRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var product = await _productService.CreateProductAsync(createRequest); var location = $"/api/products/{product.Id}"; return(Created(location, product)); }
public async Task <IHttpActionResult> AddProductAsync([FromBody] UpdateProductRequest createRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var product = await _productService.CreateProductAsync(createRequest); var location = string.Format("/api/products/{0}", product.Id); return(Created <Product>(location, product)); } catch (RequestedResourceHasConflictException) { return(Conflict()); } }
public async Task <IHttpActionResult> AddProduct([FromBody] UpdateProductRequest createRequest) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var product = await _productService.CreateProductAsync(createRequest); var location = string.Format("/api/products/{0}", product.Id); return(Created <Product>(location, product)); } catch (RequestedResourceHasConflictException ex) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message))); } catch (Exception) { return(this.InternalServerError()); } }