public IHttpActionResult PutCard(int id, CardModel card) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != card.CardID) { return BadRequest(); } db.Entry(card).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!CardExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostCard(CardModel card) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbCard = new Card(card); db.Cards.Add(dbCard); db.SaveChanges(); card.CreatedDate = dbCard.CreatedDate; card.CardID = dbCard.CardID; return CreatedAtRoute("DefaultApi", new { id = card.CardID }, card); }