Created
June 20, 2011 18:08
-
-
Save einarwh/1036166 to your computer and use it in GitHub Desktop.
Dry data: Client using the Database class.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Client4 | |
{ | |
private readonly Database _db; | |
public Client4(Database db) | |
{ | |
_db = db; | |
} | |
public IEnumerable<User> GetCompanyUsers(string company) | |
{ | |
return _db.ExecuteReader("spGetCompanyUsers", | |
new[] { new SqlParameter("@companyName", company) }, | |
r => new User | |
{ | |
Id = (string)r["id"], | |
UserName = (string)r["user"], | |
Name = (string)r["name"], | |
Email = (string)r["emailAddress"], | |
Phone = (string)r["cellPhone"], | |
ZipCode = (string)r["zip"] | |
}); | |
} | |
public string GetUserEmail(string userId) | |
{ | |
return _db.ExecuteScalar("spGetEmailForUser", | |
new[] { new SqlParameter("@userId", userId) }, | |
o => o as string); | |
} | |
public void StoreUser(User u) | |
{ | |
_db.ExecuteNonQuery("spInsertOrUpdateUser", | |
new[] | |
{ | |
new SqlParameter("@userId", u.Id), | |
new SqlParameter("@user", u.UserName), | |
new SqlParameter("@name", u.Name), | |
new SqlParameter("@emailAddress", u.Email), | |
new SqlParameter("@cellPhone", u.Phone), | |
new SqlParameter("@zip", u.ZipCode) | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment