public async Task<IHttpActionResult> PostProduct(Product product) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Product.Add(product); try { await db.SaveChangesAsync(); } catch (DbUpdateException) { if (ProductExists(product.Id)) { return Conflict(); } else { throw; } } return CreatedAtRoute("DefaultApi", new { id = product.Id }, product); }
// PUT api/ProductApi/5 public async Task<IHttpActionResult> PutProduct(Guid 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 Ok(); }
public async Task<ActionResult> Edit(Product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(product); }
public async Task<ActionResult> Create(Product product) { if (ModelState.IsValid) { product.Id = Guid.NewGuid(); db.Product.Add(product); await db.SaveChangesAsync(); return RedirectToAction("Index"); } return View(product); }