public async Task <IActionResult> Edit(int id, [Bind("Id,DbScript,Title")] Exercises exercises) { if (id != exercises.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(exercises); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ExercisesExists(exercises.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(exercises)); }
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); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Statement,Formulation,Rank,ExerciseId")] Queries queries) { if (id != queries.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(queries); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!QueriesExists(queries.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ExerciseId"] = new SelectList(_context.Exercises, "Id", "Title", queries.ExerciseId); return(View(queries)); }