implement GetUsers with a groupId filter applied.

implement GetGroup by Id method.
#64
This commit is contained in:
chris.watts90@outlook.com 2017-03-17 23:53:47 +00:00
parent eb239d0458
commit 4e3319ef69

View File

@ -35,22 +35,30 @@ namespace SQLiteRepository
_logger.Trace("Initialised SQLite Repository"); _logger.Trace("Initialised SQLite Repository");
} }
public UserList GetUsers(int pageNumber = -1, int pageSize = -1) public UserList GetUsers(int pageNumber = -1, int pageSize = -1, int groupId = -1)
{ {
var ret = new UserList(); var ret = new UserList();
List<UserIdentity> users; List<UserIdentity> users;
int userCount; int userCount;
if (pageNumber == -1 && pageSize == -1) if (pageNumber != -1 && pageSize != -1)
{
users = _connection.Query<UserIdentity>(SQLiteProcedures.GET_ALL_USERS);
userCount = users.Count;
}
else
{ {
users = _connection.Query<UserIdentity>(SQLiteProcedures.GET_ALL_USERS_PAGINATE, users = _connection.Query<UserIdentity>(SQLiteProcedures.GET_ALL_USERS_PAGINATE,
pageSize, (pageNumber - 1) * pageSize); pageSize, (pageNumber - 1) * pageSize);
userCount = _connection.ExecuteScalar<int>(SQLiteProcedures.GET_TOTAL_USER_COUNT); userCount = _connection.ExecuteScalar<int>(SQLiteProcedures.GET_TOTAL_USER_COUNT);
} }
else if (groupId != -1)
{
users =
_connection.Query<UserIdentity>(
"select u.Id, u.FirstName, u.LastName, u.HoursPerWeek, u.IsContractor from UserIdentity u left join UserGroupJoinDb ugj on ugj.UserId_FK = u.Id where ugj.GroupId_FK=?",
groupId);
userCount = users.Count;
}
else
{
users = _connection.Query<UserIdentity>(SQLiteProcedures.GET_ALL_USERS);
userCount = users.Count;
}
if (!users.Any()) if (!users.Any())
{ {
@ -473,6 +481,22 @@ namespace SQLiteRepository
return ret; return ret;
} }
public Group GetGroup(int groupId)
{
var query = _connection.Query<GroupDb>("select * from GroupDb where GroupId = ?", groupId);
if (query.Any())
{
var group = query.First();
return new Group
{
Id = group.GroupId,
Name = group.GroupName,
UserCount = 0
};
}
return new Group();
}
public OperationResponse UpdateGroup(Group group) public OperationResponse UpdateGroup(Group group)
{ {
//TODO: I would probably prefer to do this manually.... //TODO: I would probably prefer to do this manually....