public IHttpActionResult CreateStudent([FromBody] Student student) { using (var db = new NovaStudyModel()) { db.Students.Add(student); db.SaveChanges(); } return(Ok(student)); }
public IHttpActionResult UpdateSightWord(int studentId, [FromBody] SightWord sightWord) { using (var db = new NovaStudyModel()) { var student = db.Students.Include("SightWords").SingleOrDefault(s => s.StudentId == studentId); var sightWordFromDB = student.SightWords.SingleOrDefault(sw => sw.SightWordId == sightWord.SightWordId) ?? throw new Exception("Invalid Sightword"); sightWordFromDB.AnsweredCorrectlyCount = sightWord.AnsweredCorrectlyCount; sightWordFromDB.AnsweredIncorrectlyCount = sightWord.AnsweredIncorrectlyCount; db.SaveChanges(); return(Ok(sightWord)); } }
public IHttpActionResult DeleteStudent(int studentId) { using (var db = new NovaStudyModel()) { var student = db.Students.SingleOrDefault(s => s.StudentId == studentId); if (student == null) { return(NotFound()); } db.Students.Remove(student); db.SaveChanges(); return(Ok()); } }
public IHttpActionResult CreateSightWords(int studentId, [FromBody] List <SightWord> sightWords) { using (var db = new NovaStudyModel()) { var student = db.Students.SingleOrDefault(s => s.StudentId == studentId); if (student == null) { return(NotFound()); } student.SightWords.AddRange(sightWords); db.SaveChanges(); return(Ok(sightWords)); } }
public IHttpActionResult UpdateSightWords(int studentId, [FromBody] List <SightWord> sightWords) { using (var db = new NovaStudyModel()) { var student = db.Students.Include("SightWords").SingleOrDefault(s => s.StudentId == studentId); if (student == null) { return(NotFound()); } foreach (var sightWord in sightWords) { var sightWordFromDB = student.SightWords.SingleOrDefault(sw => sw.SightWordId == sightWord.SightWordId); sightWordFromDB.AnsweredCorrectlyCount = sightWord.AnsweredCorrectlyCount; sightWordFromDB.AnsweredIncorrectlyCount = sightWord.AnsweredIncorrectlyCount; } db.SaveChanges(); } return(Ok(sightWords)); }