public async Task<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 { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Products.Add(product); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = product.Id }, product); }
public ActionResult SaveModifiedProduct(Product product) { // This search will be far less ugly when we'll have a db foreach (Product p in HomeController.products) if (p.id == product.id) { p.name = product.name; p.price = product.price; return View("SaveProduct", p); } return new HttpStatusCodeResult(HttpStatusCode.BadRequest); }
public ActionResult NewProduct() { Product product = new Product(); return View(product); }
public ActionResult SaveProduct(Product product) { //Save the product products.Add(product); return View(product); }