public List <User> RetrieveUnAttachedUsers(SearchCriteria criteria) { SqlCommand command = null; SqlDataAdapter adapter = null; try { // Define command. command = mDbConnection.CreateCommand(); command.CommandText = "RetrieveUnAttahcedUserDetails"; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add("@Data", SqlDbType.Xml).Value = criteria.GetXml(); // Execute command. adapter = new SqlDataAdapter(command); DataTable DtUnAttachedUsers = new DataTable("UnAttachedUsers"); adapter.Fill(DtUnAttachedUsers); // Create a list. List <User> LstUnAttachedUsers = null; if (DtUnAttachedUsers.Rows.Count > 0) { LstUnAttachedUsers = new List <User>(); } // Iterate each row. foreach (DataRow row in DtUnAttachedUsers.Rows) { User usr = new User(Int32.Parse(row["UserId"].ToString())); usr.LastName = row["LastName"].ToString(); usr.FirstName = row["FirstName"].ToString(); //usr.CustomData.Add("Designation", row["Designation"].ToString()); usr.CustomData.Add("Role", row["Role"].ToString()); usr.CustomData.Add("EmailId", row["EmailId"].ToString()); // Add to list. LstUnAttachedUsers.Add(usr); } // Return the list. return(LstUnAttachedUsers); } catch { throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }
public List <User> RetrieveChildren(int userId) { SqlCommand command = null; SqlDataAdapter adapter = null; try { // Define command. command = mDbConnection.CreateCommand(); command.CommandText = "RetrieveUnAttahcedUserDetails"; command.CommandType = CommandType.StoredProcedure; // Execute command. adapter = new SqlDataAdapter(command); DataTable DtUnAttachedUsers = new DataTable("UnAttachedUsers"); adapter.Fill(DtUnAttachedUsers); // Create a list. List <User> LstUnAttachedUsers = null; if (DtUnAttachedUsers.Rows.Count > 0) { LstUnAttachedUsers = new List <User>(); } // Iterate each row. foreach (DataRow row in DtUnAttachedUsers.Rows) { // Create an instance of Role. User usr = new User(Int32.Parse(row["UserId"].ToString())); usr.LastName = row["LastName"].ToString(); // Add to list. LstUnAttachedUsers.Add(usr); } // Return the list. return(LstUnAttachedUsers); } catch { throw; } finally { // Dispose. if (adapter != null) { adapter.Dispose(); } if (command != null) { command.Dispose(); } } }