public IHttpActionResult PutFact(int id, Fact fact) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != fact.Id) { return BadRequest(); } db.Entry(fact).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FactExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult PostFact(Fact fact) { //if (!ModelState.IsValid) //{ // return BadRequest(ModelState); //} fact.CreatedAt = DateTime.Now; fact.UpdatedAt = DateTime.Now; db.Facts.Add(fact); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = fact.Id }, fact); }