public IHttpActionResult GetStudents()
 {
     using (var db = new NovaStudyModel())
     {
         return(Ok(db.Students.ToList()));
     }
 }
        public IHttpActionResult CreateStudent([FromBody] Student student)
        {
            using (var db = new NovaStudyModel())
            {
                db.Students.Add(student);
                db.SaveChanges();
            }

            return(Ok(student));
        }
示例#3
0
        public IHttpActionResult GetSightWords(int studentId)
        {
            using (var db = new NovaStudyModel())
            {
                var student = db.Students.Include("SightWords").SingleOrDefault(s => s.StudentId == studentId);
                if (student == null)
                {
                    return(NotFound());
                }

                return(Ok(student.SightWords));
            }
        }
示例#4
0
        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));
        }
 public IHttpActionResult Login([FromBody] LoginRequestBody login)
 {
     using (var db = new NovaStudyModel())
     {
     }
 }