Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created June 20, 2011 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/1036199 to your computer and use it in GitHub Desktop.
Save einarwh/1036199 to your computer and use it in GitHub Desktop.
Dry data: Final version of the client
public class Client5
{
private readonly Database _db;
public Client5(Database db)
{
_db = db;
}
public IEnumerable<User> GetCompanyUsers(string company)
{
return _db.ExecuteReader(
"spGetCompanyUsers",
sp => sp["@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",
sp => sp["@userId", userId],
o => o as string);
}
public void StoreUser(User u)
{
_db.ExecuteNonQuery(
"spInsertOrUpdateUser",
sp => sp["@userId", u.Id]
["@user", u.UserName]
["@name", u.Name]
["@emailAddress", u.Email]
["@cellPhone", u.Phone]
["@zip", u.ZipCode]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment