// GET: api/Students/5 public Student Get(int id) { using (db = new AppDbContextDataContext()) { return(db.Students.FirstOrDefault(s => s.Id == id)); } }
// GET: api/Student public IEnumerable <Student> Get() { using (db = new AppDbContextDataContext()) { return(db.Students.ToList()); } }
// DELETE: api/Students/5 public void Delete(int id) { using (db = new AppDbContextDataContext()) { var student = db.Students.FirstOrDefault(s => s.Id == id); db.Students.DeleteOnSubmit(student); db.SubmitChanges(); } }
// POST: api/Students public void Post([FromBody] Student student) { using (db = new AppDbContextDataContext()) { student.TimeStamp = UnixTimeNow; db.Students.InsertOnSubmit(student); db.SubmitChanges(); } }
// PUT: api/Students/5 public void Put(int id, [FromBody] Student student) { using (db = new AppDbContextDataContext()) { var studentOld = db.Students.FirstOrDefault(s => s.Id == id); studentOld.Grade = student.Grade; studentOld.Name = student.Name; studentOld.TimeStamp = UnixTimeNow; db.SubmitChanges(); } }