Example #1
0
        public Task <List <T> > GetItemsByCommandAsync <T>(string connectionString, string command, List <SqlParameter> parameters)
        {
            return(Task.Run(() =>
            {
                SQL_Service sql = new SQL_Service(connectionString);
                List <T> items = null;

                using (IDbConnection db = sql.CreationConnection())
                {
                    db.Open();

                    SqlCommand cmd = sql.CreateCommand((SqlConnection)db, command);

                    cmd.Parameters.Add(parameters);

                    SqlDataReader rdr = null;
                    using (rdr = sql.ExecuteReader(cmd))
                    {
                        items = sql.GetObjectsFromExecuteReader <T>(rdr);
                    }

                    sql.CloseConnection(db);
                }
                return items;
            }));
        }
Example #2
0
        public Task PerformCommandAsync(string connectionstring, string command)
        {
            return(Task.Run(() =>
            {
                SQL_Service sql = new SQL_Service(connectionstring);

                using (IDbConnection db = sql.CreationConnection())
                {
                    db.Open();

                    SqlCommand cmd = sql.CreateCommand((SqlConnection)db, command);

                    SqlDataReader rdr = null;
                    sql.ExecuteReader(cmd);
                    sql.CloseConnection(db);
                }
                return;
            }));
        }
Example #3
0
        public Task <T> GetItemAsync <T>(string connectionstring, string storedProcedure, List <SqlParameter> sqlParameters)
        {
            return(Task.Run(() =>
            {
                SQL_Service sql = new SQL_Service(connectionstring);
                List <T> items = null;

                using (IDbConnection db = sql.CreationConnection())
                {
                    db.Open();

                    SqlCommand cmd = sql.CreateStoredProcedureCommand((SqlConnection)db, storedProcedure, sqlParameters.ToArray());

                    SqlDataReader rdr = null;
                    using (rdr = sql.ExecuteReader(cmd))
                    {
                        items = sql.GetObjectsFromExecuteReader <T>(rdr);
                    }

                    sql.CloseConnection(db);
                }
                return items.FirstOrDefault();
            }));
        }