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, Id = card.Id,
IsAssociatedToUser = card.UserId_FK != Constants.UNASSIGNED_CARD_USER_ID, IsAssociatedToUser = card.UserId_FK != Constants.UNASSIGNED_CARD_USER_ID,
UniqueId = card.CardUId UniqueId = card.CardUId,
LastUsed = card.LastUsed.DateTime
}); });
} }
return ret; return ret;
@ -350,6 +351,10 @@ namespace SQLiteRepository
ident.UserId_FK = -1; ident.UserId_FK = -1;
ident.CardUId = identifier.UniqueId; ident.CardUId = identifier.UniqueId;
_connection.Insert(ident); _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 else
{ {
@ -386,10 +391,7 @@ namespace SQLiteRepository
var calendarWeek = GetIso8601CalendarWeek(logTime); var calendarWeek = GetIso8601CalendarWeek(logTime);
var year = logTime.Year; var year = logTime.Year;
#endregion #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 var timeLog = new TimeLogDb
{ {
SwipeEventDateTime = DateTime.UtcNow, SwipeEventDateTime = DateTime.UtcNow,
@ -401,6 +403,8 @@ namespace SQLiteRepository
}; };
_connection.Insert(timeLog); _connection.Insert(timeLog);
UpdateIdentifierLastUsed(timeLog.SwipeEventDateTime, timeLog.IdentifierId);
logId = timeLog.Id; logId = timeLog.Id;
return OperationResponse.SUCCESS; return OperationResponse.SUCCESS;
@ -540,6 +544,13 @@ namespace SQLiteRepository
return null; 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) private List<Identifier> GetAssociatedIdentifiers(int userId)
{ {
var cards = _connection.Query<CardUniqueId>( var cards = _connection.Query<CardUniqueId>(