Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
34 lines (28 sloc) 807 Bytes
using System.Data.Entity;
using System.Linq;
namespace NuGetGallery
{
public interface IUserByUsernameQuery
{
User Execute(
string username,
bool includeRoles = true);
}
public class UserByUsernameQuery : IUserByUsernameQuery
{
private readonly IEntitiesContext _entities;
public UserByUsernameQuery(IEntitiesContext entities)
{
_entities = entities;
}
public User Execute(
string username,
bool includeRoles = true)
{
var qry = _entities.Users.AsQueryable();
if (includeRoles)
qry = qry.Include(u => u.Roles);
return qry.SingleOrDefault(u => u.Username == username);
}
}
}
Jump to Line
Something went wrong with that request. Please try again.