Beispiel #1
0
        public IEnumerable <Questions> GetAll()
        {
            List <Questions> QuestionList = new List <Questions>();
            NlogerConfig     config       = new NlogerConfig();
            DataTable        data         = new DataTable();
            Logger           logger       = LogManager.GetLogger("Question");
            SqlConnection    con          = new SqlConnection(connection.ConnectionString);

            try
            {
                using (con)
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection  = con;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "Select * from Question";
                        if (con.State != ConnectionState.Open)
                        {
                            con.Open();
                        }
                        using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                        {
                            da.Fill(data);
                        }
                        QuestionList = data.ToList <Questions>();
                        if (con.State != ConnectionState.Closed)
                        {
                            con.Close();
                        }
                    }
                }
                return(QuestionList);
            }
            catch (Exception ex)
            {
                if (con.State != ConnectionState.Closed)
                {
                    con.Close();
                }
                logger.Error(ex, "An error occured fetching Questions.");
                return(QuestionList);
            }
        }
Beispiel #2
0
        public int validateUser(UserTable model)
        {
            int           value  = 99;
            NlogerConfig  config = new NlogerConfig();
            Logger        logger = LogManager.GetLogger("User");
            SqlConnection conn   = new SqlConnection(connection.ConnectionString);

            try
            {
                using (conn)
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = "Select dbo.f_ValidateUser(@Username,@Password)";
                        cmd.Parameters.AddWithValue("@Username", model.Username);
                        cmd.Parameters.AddWithValue("@Password", model.Password);
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        value = (int)cmd.ExecuteScalar();
                        if (conn.State != ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                logger.Error(ex, "An error occured when validating user.");
                throw;
            }

            return(value);
        }
Beispiel #3
0
        public void insertLoginSuccess(string Username, string UserAgent)
        {
            NlogerConfig  config = new NlogerConfig();
            Logger        logger = LogManager.GetLogger("User");
            SqlConnection conn   = new SqlConnection(connection.ConnectionString);

            try
            {
                using (conn)
                {
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection  = conn;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "s_LoginSuccess";
                        cmd.Parameters.AddWithValue("@Username", Username);
                        cmd.Parameters.AddWithValue("@userAgent", UserAgent);
                        if (conn.State != ConnectionState.Open)
                        {
                            conn.Open();
                        }
                        cmd.ExecuteNonQuery();
                        if (conn.State != ConnectionState.Closed)
                        {
                            conn.Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (conn.State != ConnectionState.Closed)
                {
                    conn.Close();
                }
                logger.Error(ex, "Error occured when inserting LoginSucess");
            }
        }