Skip to content

Instantly share code, notes, and snippets.

@einarwh
Created June 20, 2011 18:08
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/1036166 to your computer and use it in GitHub Desktop.
Save einarwh/1036166 to your computer and use it in GitHub Desktop.
Dry data: Client using the Database class.
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