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(