change SQLiteRepository to update last used property against the Identifiers in database (CardUniqueId table).

updated LogEventTime method to update the last used time in the db.
changed LogEventTime method to not store timelogs against unassigned cards.
updated GetUnassignedIdentifierList method to populate the Identifier LastUsed property.
#56
This commit is contained in:
chris.watts90@outlook.com 2017-03-03 21:39:31 +00:00
parent d55a1ed817
commit d41b5c528c

View File

@ -242,7 +242,8 @@ namespace SQLiteRepository
{
Id = card.Id,
IsAssociatedToUser = card.UserId_FK != Constants.UNASSIGNED_CARD_USER_ID,
UniqueId = card.CardUId
UniqueId = card.CardUId,
LastUsed = card.LastUsed.DateTime
});
}
return ret;
@ -350,6 +351,10 @@ namespace SQLiteRepository
ident.UserId_FK = -1;
ident.CardUId = identifier.UniqueId;
_connection.Insert(ident);
UpdateIdentifierLastUsed(DateTimeOffset.UtcNow, ident.Id);
logId = -1;
//dont try to log any timelogs against this card, as it is unassigned to a user.
return OperationResponse.SUCCESS;
}
else
{
@ -387,9 +392,6 @@ namespace SQLiteRepository
var year = logTime.Year;
#endregion
//TODO: Handle When the identifier is assigned to a user (identifier has -1)
//when identifier not assigned to user, just store it anyway and carry on, can update later.
var timeLog = new TimeLogDb
{
SwipeEventDateTime = DateTime.UtcNow,
@ -401,6 +403,8 @@ namespace SQLiteRepository
};
_connection.Insert(timeLog);
UpdateIdentifierLastUsed(timeLog.SwipeEventDateTime, timeLog.IdentifierId);
logId = timeLog.Id;
return OperationResponse.SUCCESS;
@ -540,6 +544,13 @@ namespace SQLiteRepository
return null;
}
private void UpdateIdentifierLastUsed(DateTimeOffset dt, int cardId)
{
var res = _connection.ExecuteScalar<CardUniqueId>("update CardUniqueId set LastUsed = ? where Id = ?",
dt,
cardId);
}
private List<Identifier> GetAssociatedIdentifiers(int userId)
{
var cards = _connection.Query<CardUniqueId>(