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; })); }
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; })); }
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(); })); }