From 54d11ddf9de1dc2e6f3532f604ebacdc79dfca23 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Wed, 8 Feb 2017 16:51:23 +0000 Subject: [PATCH] added stub/comment for manual swipe data log submission. returned user id in user edit started working on the direction/logtime method --- .../SQLiteRepository/SQLiteRepository.cs | 37 ++++++++++++++++--- .../Controllers/SwipeDataController.cs | 5 +++ .../Controllers/UsersController.cs | 3 +- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index d58816e..0813a74 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -254,17 +254,39 @@ namespace SQLiteRepository } else { - //TODO: handle when more than one comes back. should NEVER happen but.... + //TODO: log when more than one comes back. should NEVER happen but.... ident = cardIdQuery.First(); } - + //TODO: change log direction to an ENUM //TODO: Handle In/Out Flag.. + var logDirection = false; //get the last flag + if (ident.UserId_FK != -1) + { + var lastEntry = _connection.Query( + SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION, + ident.UserId_FK); + if (lastEntry.Any()) + { + var lastLog = lastEntry.First(); + // See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in) + if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime)) + { + logDirection = true; + } + else + { + logDirection = !lastLog.InOut; + } + } + } + else + { + logDirection = false; //TODO: need an "unknown" state.. + } //SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION //then invert it, and store it.. - var logDirection = false; - //TODO: See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in) - + //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 TimeLog @@ -280,6 +302,11 @@ namespace SQLiteRepository return OperationResponse.SUCCESS; } + private bool IsLogDateTimeYesterdayOrOlder(DateTime dt) + { + return dt.Date.CompareTo(DateTime.Today.Date) < 0; + } + private User ChangeToUserObject(UserIdentity user) { return new User diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs index 0618619..3e5bc87 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs @@ -54,5 +54,10 @@ namespace WindowsDataCenter Content = new StringContent("TODO: return ID") }); } + + //need another method here for posting. + //public IHttpActionResult ManuallyPostData([FromBody] ManualLog log){ + // + //} } } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs index f3935ca..73de953 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs @@ -60,8 +60,7 @@ namespace WindowsDataCenter { int userId; _repo.UpdateUser(user, out userId); - //TODO: MUST HAVE - return user id! - var resp = Request.CreateResponse(HttpStatusCode.OK, "TODO:return UserID"); + var resp = Request.CreateResponse(HttpStatusCode.OK, userId); return ResponseMessage(resp); //ResponseMessage(new HttpResponseMessage(HttpStatusCode.Created) //{