From d41b5c528cedd62ae041a2f556869c132d484469 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Fri, 3 Mar 2017 21:39:31 +0000 Subject: [PATCH] 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 --- .../SQLiteRepository/SQLiteRepository.cs | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index dfbcb91..3f8ef98 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -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 { @@ -386,10 +391,7 @@ namespace SQLiteRepository var calendarWeek = GetIso8601CalendarWeek(logTime); 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("update CardUniqueId set LastUsed = ? where Id = ?", + dt, + cardId); + } + private List GetAssociatedIdentifiers(int userId) { var cards = _connection.Query(