public Note GetById(int id) { using (var db = new SampleServiceEntities()) { return(db.Notes.FirstOrDefault(x => x.Id == id)); } }
public int Add(Note note) { using (var db = new SampleServiceEntities()) { db.Notes.Add(note); db.SaveChanges(); return(note.Id); } }
public IHttpActionResult Delete() { if (!EnableTestingApi) { return(NotFound()); } using (var db = new SampleServiceEntities()) { db.Database.ExecuteSqlCommand("DELETE FROM dbo.Notes;"); } return(Ok()); }
public bool CheckStatus() { try { using (var db = new SampleServiceEntities()) { db.Database.ExecuteSqlCommand("SELECT 1"); } } catch { return(false); } return(true); }
public bool Delete(int id) { using (var db = new SampleServiceEntities()) { var note = db.Notes.FirstOrDefault(x => x.Id == id); if (note == null) { return(false); } db.Notes.Remove(note); db.SaveChanges(); return(true); } }