Refactor code to simplify methods.
This commit is contained in:
parent
7110e3e2fe
commit
b0b1fd4576
@ -67,26 +67,15 @@ namespace SQLiteRepository
|
|||||||
foreach (var user in users)
|
foreach (var user in users)
|
||||||
{
|
{
|
||||||
var userObj = ChangeToUserObject(user);
|
var userObj = ChangeToUserObject(user);
|
||||||
var cards = _connection.Query<CardUniqueId>(
|
|
||||||
SQLiteProcedures.GET_CARDS_BY_USER_ID,
|
|
||||||
user.Id);
|
|
||||||
|
|
||||||
foreach (var card in cards)
|
userObj.AssociatedIdentifiers = GetAssociatedIdentifiers(user.Id);
|
||||||
{
|
|
||||||
userObj.AssociatedIdentifiers.Add(new Identifier()
|
|
||||||
{
|
|
||||||
UniqueId = card.CardUId,
|
|
||||||
IsAssociatedToUser = true,
|
|
||||||
Id = card.Id
|
|
||||||
});
|
|
||||||
}
|
|
||||||
userObj.State = GetUserState(GetLogDirection(user.Id));
|
userObj.State = GetUserState(GetLogDirection(user.Id));
|
||||||
|
userObj.LastEventDateTime = GetLastLogDateTime(GetLastTimeLog(user.Id));
|
||||||
ret.Users.Add(userObj);
|
ret.Users.Add(userObj);
|
||||||
}
|
}
|
||||||
if (pageNumber == -1 && pageSize == -1)
|
if (pageNumber == -1 && pageSize == -1)
|
||||||
{
|
{
|
||||||
ret.PageSize = 1; //TODO: switch to ret.UserCount
|
ret.PageSize = 10;
|
||||||
ret.PageNumber = 1;
|
ret.PageNumber = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -106,6 +95,7 @@ namespace SQLiteRepository
|
|||||||
}
|
}
|
||||||
return DateTime.MinValue;
|
return DateTime.MinValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool GetUserState(LogDirectionDb logDirection)
|
private bool GetUserState(LogDirectionDb logDirection)
|
||||||
{
|
{
|
||||||
switch (logDirection)
|
switch (logDirection)
|
||||||
@ -150,6 +140,7 @@ namespace SQLiteRepository
|
|||||||
Id = card.Id
|
Id = card.Id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
userObj.State = GetUserState(GetLogDirection(user.Id));
|
||||||
ret.Users.Add(userObj);
|
ret.Users.Add(userObj);
|
||||||
}
|
}
|
||||||
//TODO: figure out paging here. - should there be any?
|
//TODO: figure out paging here. - should there be any?
|
||||||
@ -194,7 +185,7 @@ namespace SQLiteRepository
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
//TODO: refac this as it duplicates a lot of code.
|
|
||||||
public TimeLogList GetTimeLogs(int userId)
|
public TimeLogList GetTimeLogs(int userId)
|
||||||
{
|
{
|
||||||
return GetTimeLogs(userId, DateTime.UtcNow);
|
return GetTimeLogs(userId, DateTime.UtcNow);
|
||||||
@ -548,6 +539,25 @@ namespace SQLiteRepository
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Identifier> GetAssociatedIdentifiers(int userId)
|
||||||
|
{
|
||||||
|
var cards = _connection.Query<CardUniqueId>(
|
||||||
|
SQLiteProcedures.GET_CARDS_BY_USER_ID,
|
||||||
|
userId);
|
||||||
|
var ret = new List<Identifier>();
|
||||||
|
foreach (var card in cards)
|
||||||
|
{
|
||||||
|
ret.Add(new Identifier()
|
||||||
|
{
|
||||||
|
UniqueId = card.CardUId,
|
||||||
|
IsAssociatedToUser = true,
|
||||||
|
Id = card.Id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the calendar week of the year according to the ISO8601 standard (starts monday).
|
/// Get the calendar week of the year according to the ISO8601 standard (starts monday).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -76,7 +76,9 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="App.config" />
|
<None Include="App.config">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user