Exemple #1
0
        /// <summary>
        ///  Find all the exercises in the database where the language is JavaScript.
        /// </summary>
        public CreateExercise GetJavaScriptExercises(string JavaScript)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT Id, ExerciseName, ExerciseLanguage FROM Exercise WHERE ExerciseLanguage = 'JavaScript'";
                    cmd.Parameters.Add(new SqlParameter("@ExerciseLanguage", JavaScript));
                    SqlDataReader reader = cmd.ExecuteReader();

                    CreateExercise exercise = null;
                    if (reader.Read())
                    {
                        exercise = new CreateExercise
                        {
                            Id               = reader.GetInt32(reader.GetOrdinal("Id")),
                            ExerciseName     = reader.GetString(reader.GetOrdinal("ExerciseName")),
                            ExerciseLanguage = reader.GetString(reader.GetOrdinal("ExerciseLanguage"))
                        };
                    }

                    reader.Close();

                    return(exercise);
                }
            }
        }
    // Private
    #region Private

    // Spawn an exercise
    private void SpawnExercice()
    {
        // Create NumberSelection exercise
        Exercise exercise = CreateExercise.CreateNewExercise("", Exercise.TypeExercise.NumberSelection, transform);

        exercise.SetProperties(difficulty, animationTime, numberAnswers);
        exercise.StartExercice((isCorrect) =>
        {
            if (isCorrect)
            {
                successes++;
                consecutiveSuccesses++;
                consecutivefaults = 0;
            }
            else
            {
                faults++;
                consecutiveSuccesses = 0;
                consecutivefaults++;
            }
            // Check lastExerciseFault
            results.text = "Results: <#00FF00>" + successes + "</color> / <#FF0000> " + faults + "</color>";
        }, () =>
        {
            Destroy(exercise.gameObject);
            if (automaticDifficulty)
            {
                CheckDifficulty();
            }
            SpawnExercice();
        });
    }
        public void CreateExercise([FromBody] CreateExercise model)
        {
            var      currentUserId = int.Parse(User.Identity.Name);
            Exercise entity        = _mapper.Map <Exercise>(model);

            entity.UserId = currentUserId;
            _db.Exercise.CreateExercise(entity);
            _db.Save();
        }
Exemple #4
0
 /// <summary>
 //Insert a new exercise into the database.
 ///   NOTE: This method sends data to the database,
 ///   it does not get anything from the database, so there is nothing to return.
 /// </summary>
 public void AddExercise(CreateExercise exercise)
 {
     using (SqlConnection conn = Connection)
     {
         conn.Open();
         using (SqlCommand cmd = conn.CreateCommand())
         {
             cmd.CommandText = "INSERT INTO Exercise (ExerciseName, ExerciseLanguage) Values (@ExerciseName, @ExerciseLanguage)";
             cmd.Parameters.Add(new SqlParameter("@ExerciseName", exercise.ExerciseName));
             cmd.Parameters.Add(new SqlParameter("@ExerciseLanguage", exercise.ExerciseLanguage));
             cmd.ExecuteNonQuery();
         }
     }
 }
        public ActionResult <Exercise> CreateExercise([FromBody] CreateExercise model)
        {
            // map model to entity
            var Exercise = _mapper.Map <Exercise>(model);

            try
            {
                // create Exercise
                _ExerciseService.Create(Exercise);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an cexception
                return(BadRequest(new { message = ex.Message }));
            }
        }
Exemple #6
0
        public async Task <ActionResult> Create(CreateExercise exercise)
        {
            if (ModelState.IsValid)
            {
                dynamic result;
                if (string.IsNullOrEmpty(exercise.VerificationQuery))
                {
                    result = (await TestQuery(exercise.SolutionQuery, exercise.Diagram)).Data;
                }
                else
                {
                    result = (await TestQueryDML(exercise.SolutionQuery, exercise.VerificationQuery, exercise.Diagram)).Data;
                }
                if (((string)result.result).StartsWith("ERROR"))
                {
                    return(View(exercise));
                }
                var toInJudge = new Judge
                {
                    VerifyQuery = exercise.VerificationQuery,
                    AnswerQuery = exercise.SolutionQuery,
                    Diagram     = _context.Diagrams.Find(exercise.Diagram)
                };
                var toIn = new Exercise
                {
                    Description = exercise.Description,
                    Difficulty  = exercise.Difficulty,
                    Title       = exercise.Title,
                    Judge       = toInJudge
                };
                await Task.Run(() => _context.Judges.Add(toInJudge));

                await Task.Run(() => _context.Exercises.Add(toIn));

                await _context.SaveAsync();

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(View(exercise));
            }
        }
Exemple #7
0
        /************************************************************************************
        * Exercises
        ************************************************************************************/
        //Query the database for all the Exercises.
        /// <summary>
        ///  Returns a list of all Exercises in the database
        /// </summary>
        public List <CreateExercise> GetAllExercises()
        {
            using (SqlConnection conn = Connection)
            {
                //opens the connection to the database.
                conn.Open();

                // We must "use" commands too.
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    // Here we setup the command with the SQL we want to execute before we execute it.
                    cmd.CommandText = "SELECT Id, ExerciseName, ExerciseLanguage FROM Exercise";

                    // Execute the SQL in the database and get a "reader" that will give us access to the data.
                    SqlDataReader reader = cmd.ExecuteReader();

                    // A list to hold the Exercises we retrieve from the database.
                    List <CreateExercise> Exercise = new List <CreateExercise>();

                    // Read() will return true if there's more data to read
                    while (reader.Read())
                    {
                        // Now let's create a new Exercise object using the data from the database.
                        CreateExercise exercise = new CreateExercise()
                        {
                            Id               = reader.GetInt32(reader.GetOrdinal("Id")),
                            ExerciseName     = reader.GetString(reader.GetOrdinal("ExerciseName")),
                            ExerciseLanguage = reader.GetString(reader.GetOrdinal("ExerciseLanguage"))
                        };

                        // ...and add that department object to our list.
                        Exercise.Add(exercise);
                    }
                    //closes the conncection
                    reader.Close();

                    return(Exercise);
                }
            }
        }
        public IActionResult Post([FromBody] CreateExercise request)
        {
            _exerciseService.Create(request.Name);

            return(StatusCode(201));
        }