public IHttpActionResult PostEntry(EntriesModel entry) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var dbPostEntry = new Entry(); dbPostEntry.Update(entry); db.Entries.Add(dbPostEntry); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = dbPostEntry.EntryId }, entry); }
public IHttpActionResult GetEntry(int id) { Entry dbEntry = db.Entries.Find(id); if (dbEntry == null) { return NotFound(); } EntriesModel modelEntry = new EntriesModel { CreatedDate = dbEntry.CreatedDate, Name = dbEntry.Name, EntryContent = dbEntry.EntryContent }; return Ok(modelEntry); }
public IHttpActionResult PutEntry(int id, EntriesModel entry) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != entry.EntryId) { return BadRequest(); } var dbPutEntry = db.Entries.Find(entry.EntryId); dbPutEntry.Update(entry); db.Entry(dbPutEntry).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!EntryExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }