Ejemplo n.º 1
0
        public Boolean checkAnswer(int id, QueryResponse response)
        {
            People  currentStudent = _context.People.FirstOrDefault(p => p.PinCode == response.pinCode);
            Queries currentQuery   = _context.Queries.FirstOrDefault(q => q.Id == id);

            if (currentStudent == null || currentQuery == null)
            {
                return(false);
            }
            Scores score = _context.Scores.FirstOrDefault(s => s.PeopleId == currentStudent.Id && s.QuerieId == currentQuery.Id);

            // Check if response is good
            if (score == null)
            {
                score        = new Scores();
                score.People = currentStudent;
                score.Querie = currentQuery;
            }

            score.Attempts += 1;
            score.Success   = currentQuery.checkStatement(response.query, _configuration["ConnectionStrings:ExerciseConnection"]);
            _context.Update(score);
            _context.SaveChanges();
            return(score.Success);
        }
Ejemplo n.º 2
0
 //[ValidateAntiForgeryToken]
 public int Create([FromBody] Exercises exercises)
 {
     if (ModelState.IsValid)
     {
         _context.Add(exercises);
         _context.SaveChanges();
         return(_context.Exercises.Max(item => item.Id));
     }
     return(0);
 }
Ejemplo n.º 3
0
 public Boolean CreateFromExercise([FromBody] List <Queries> queries)
 {
     foreach (Queries querie in queries)
     {
         if (ModelState.IsValid)
         {
             _context.Add(querie);
         }
     }
     _context.SaveChanges();
     return(true);
 }