Example #1
0
        public static bool AddCompletedDrill(Drill drill, Student student)
        {
            DateTime currentDateTime = new DateTime();

            currentDateTime = DateTime.UtcNow;

            SqlConnection connection      = MathWizzDB.GetConnection();
            String        selectStatement = "INSERT INTO ActivityHistory (StudentId, DateTime, TotalQuestions, CorrectAnswers, SkillLevel, ActivityType)" +
                                            "VALUES (@StudentId, @DateTime, @TotalQuestions, @CorrectAnswers, @SkillLevel, @ActivityType)";
            SqlCommand command = new SqlCommand(selectStatement, connection);

            command.Parameters.AddWithValue("@StudentId", student.UserId);
            command.Parameters.AddWithValue("@DateTime", currentDateTime);
            command.Parameters.AddWithValue("@TotalQuestions", drill.NumberOfQuestions);
            command.Parameters.AddWithValue("@CorrectAnswers", drill.NumberOfCorrectAnswers);
            command.Parameters.AddWithValue("@SkillLevel", student.StudentLevel);
            command.Parameters.AddWithValue("@ActivityType", "Drill");

            try
            {
                connection.Open();

                int rowsAffected = command.ExecuteNonQuery();
                if (rowsAffected > 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }
        }
Example #2
0
        public static bool AddToStudentInfo(Student student)
        {
            bool          success    = false;
            SqlConnection connection = MathWizzDB.GetConnection();
            SqlCommand    command    = new SqlCommand("INSERT INTO StudentInfo (StudentId, SkillLevel, ClassId)" +
                                                      "VALUES(@StudentId, @SkillLevel, @ClassId)", connection);


            command.Parameters.AddWithValue("@StudentId", student.userId);
            command.Parameters.AddWithValue("@SkillLevel", student.StudentLevel);
            command.Parameters.AddWithValue("@ClassId", student.ClassID);


            try
            {
                connection.Open();
                int rowsAffected = command.ExecuteNonQuery();
                if (rowsAffected > 0)
                {
                    success = true;
                }
                else
                {
                    success = false;
                }

                // for testing
                Console.WriteLine("RowsAffected: {0}", rowsAffected);
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                connection.Close();
            }

            return(success);
        }