public async Task<IHttpActionResult> PutContact(int id, Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != contact.ID) { return BadRequest(); } db.Entry(contact).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ContactExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public ActionResult Create(Contact contact) { if (ModelState.IsValid) { db.Movies.Add(contact); db.SaveChanges(); return RedirectToAction("Index"); } return View(contact); }
public async Task<IHttpActionResult> PostContact(Contact contact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Contacts.Add(contact); await db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = contact.ID }, contact); }
public ActionResult Edit(Contact contact) { if (ModelState.IsValid) { db.Entry(contact).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(contact); }