Esempio n. 1
0
        public bool AnswerQuestion(SecondaryQuestion question, string department, string responseMessage)
        {
            int id = GetDepartmentID(department);

            question.Department = id;
            question.Response   = responseMessage;

            using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["TTdatabase"].ConnectionString))
            {
                try
                {
                    c.Open();
                    string     sql      = "UPDATE SecondaryQuestions SET idDepartment = " + id + ", response = '" + responseMessage + "' WHERE idQuestion = " + question.ID;
                    SqlCommand cmd      = new SqlCommand(sql, c);
                    int        rowCount = cmd.ExecuteNonQuery();
                    return(rowCount >= 1);
                }
                catch (SqlException)
                {
                    return(false);
                }
                finally
                {
                    c.Close();
                }
            }
        }
Esempio n. 2
0
        public List <SecondaryQuestion> MyQuestions(int idSolver, bool type)
        {
            List <SecondaryQuestion> questions = new List <SecondaryQuestion>();

            using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["TTdatabase"].ConnectionString))
            {
                try
                {
                    c.Open();
                    string sql = "";
                    if (type)
                    {
                        sql += "SELECT * FROM SecondaryQuestions WHERE idSender = " + idSolver + "AND idDepartment IS NULL";
                    }
                    else
                    {
                        sql += "SELECT * FROM SecondaryQuestions WHERE idSender = " + idSolver + "AND idDepartment IS NOT NULL";
                    }
                    SqlCommand    cmd    = new SqlCommand(sql, c);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        SecondaryQuestion question = new SecondaryQuestion();
                        question.ID       = reader.GetInt32(0);
                        question.Date     = reader.GetDateTime(6);
                        question.SenderID = reader.GetInt32(2);
                        question.TicketID = reader.GetInt32(1);
                        question.Question = reader.GetString(4);

                        questions.Add(question);
                    }

                    reader.Close();
                }
                catch (SqlException)
                {
                }
                finally
                {
                    c.Close();
                }

                return(questions);
            }
        }
Esempio n. 3
0
        public SecondaryQuestion GetQuestion(int id)
        {
            SecondaryQuestion question = new SecondaryQuestion();

            using (SqlConnection c = new SqlConnection(ConfigurationManager.ConnectionStrings["TTdatabase"].ConnectionString))
            {
                try
                {
                    c.Open();
                    string        sql    = "SELECT * FROM SecondaryQuestions WHERE idQuestion=" + id;
                    SqlCommand    cmd    = new SqlCommand(sql, c);
                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.Read())
                    {
                        question.ID         = id;
                        question.TicketID   = reader.GetInt32(1);
                        question.SenderID   = reader.GetInt32(2);
                        question.Department = reader.GetInt32(3);
                        question.Question   = reader.GetString(4);
                        question.Response   = reader.GetString(5);
                        question.Date       = reader.GetDateTime(6);
                    }

                    reader.Close();
                    return(question);
                }
                catch (SqlException)
                {
                    return(question);
                }
                finally
                {
                    c.Close();
                }
            }
        }