// PUT api/Product/5 public IHttpActionResult PutProduct(int id, Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != product.ID) { return BadRequest(); } db.Entry(product).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public bool EditProduct(Product product) { var p = _productRepository.GetById(product.ID); if (p != null) { _productRepository.Update(p); _productRepository.Save(); return true; } return false; }
public IHttpActionResult PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = product.ID }, product); }
public bool AddProduct(Product product) { try { _productRepository.Add(product); _productRepository.Save(); return true; } catch (Exception) { return false; } }