コード例 #1
0
        public IHttpActionResult CreateStudent([FromBody] Student student)
        {
            using (var db = new NovaStudyModel())
            {
                db.Students.Add(student);
                db.SaveChanges();
            }

            return(Ok(student));
        }
コード例 #2
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));
            }
        }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
        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));
            }
        }
コード例 #5
0
        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));
        }