public async Task<IHttpActionResult> PostProduct(Product product) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } await _productRepository.AddAsync(product); return CreatedAtRoute("DefaultApi", new { id = product.ProductID }, product); }
public async Task<IHttpActionResult> PutProduct(int id, Product product) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } if (id != product.ProductID) { return this.BadRequest(); } try { await _productRepository.UpdateAsync(product, id); } catch (DbUpdateConcurrencyException) { if (!this.ProductExists(id)) { return this.NotFound(); } else { throw; } } return this.StatusCode(HttpStatusCode.NoContent); }