From 38fab21afd1849779a88e9ad0aa34e903464dbd9 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Thu, 9 Feb 2017 21:33:52 +0000 Subject: [PATCH] renamed TimeLogDB to TimeLogDb. moved LogDirectionDB to its own file and renamed to LogDirectionDb --- .../SQLiteRepository/LogDirectionDb.cs | 9 +++++++ .../SQLiteRepository/SQLiteProcedures.cs | 4 +-- .../SQLiteRepository/SQLiteRepository.cs | 27 +++++++++---------- .../SQLiteRepository/SQLiteRepository.csproj | 3 ++- .../{TimeLog.cs => TimeLogDb.cs} | 11 ++------ 5 files changed, 28 insertions(+), 26 deletions(-) create mode 100644 DataCenter_Windows/WindowsDataCenter/SQLiteRepository/LogDirectionDb.cs rename DataCenter_Windows/WindowsDataCenter/SQLiteRepository/{TimeLog.cs => TimeLogDb.cs} (68%) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/LogDirectionDb.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/LogDirectionDb.cs new file mode 100644 index 0000000..c6c73ca --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/LogDirectionDb.cs @@ -0,0 +1,9 @@ +namespace SQLiteRepository +{ + public enum LogDirectionDb + { + UNKNOWN = 0, + IN = 1, + OUT = 2 + } +} \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs index 4cc7aa7..871bba2 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs @@ -2,7 +2,7 @@ namespace SQLiteRepository { internal static class SQLiteProcedures { - public const string GET_TIMELOGS = "select * from "+nameof(TimeLogDB)+ " where (" + nameof(TimeLogDB.UserId_FK) + "=? AND " + nameof(TimeLogDB.CalendarWeek) + "=? and " + nameof(TimeLogDB.Year) + "=?)"; + public const string GET_TIMELOGS = "select * from "+nameof(TimeLogDb)+ " where (" + nameof(TimeLogDb.UserId_FK) + "=? AND " + nameof(TimeLogDb.CalendarWeek) + "=? and " + nameof(TimeLogDb.Year) + "=?)"; public const string GET_ALL_USERS = "select * from " + nameof(UserIdentity); public const string GET_USER_BY_ID = "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?"; @@ -17,6 +17,6 @@ namespace SQLiteRepository public const string SEARCH_USER_LIST = "SELECT * FROM " + nameof(UserIdentity) + " where(" + nameof(UserIdentity.FirstName) + " Like ? OR " + nameof(UserIdentity.LastName) + " Like ?)"; - public const string GET_LAST_TIMELOG_DIRECTION = "SELECT * FROM " + nameof(TimeLogDB) + " where " + nameof(TimeLogDB.UserId_FK) + " = ? order by " + nameof(TimeLogDB.SwipeEventDateTime) + " LIMIT 1"; + public const string GET_LAST_TIMELOG_DIRECTION = "SELECT * FROM " + nameof(TimeLogDb) + " where " + nameof(TimeLogDb.UserId_FK) + " = ? order by " + nameof(TimeLogDb.SwipeEventDateTime) + " LIMIT 1"; } } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index 32db645..d8c4157 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -20,7 +20,7 @@ namespace SQLiteRepository _connection.CreateTable(); _connection.CreateTable(); - _connection.CreateTable(); + _connection.CreateTable(); } public UserList GetUsers() @@ -288,7 +288,7 @@ namespace SQLiteRepository //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, UserId_FK = ident.UserId_FK, @@ -306,12 +306,11 @@ namespace SQLiteRepository private List GetTimeLogList(int userId, int calendarWeek, int year) { - List ret; - var timeLogList = _connection.Query( + var timeLogList = _connection.Query( SQLiteProcedures.GET_TIMELOGS, userId, calendarWeek, year); - ret= timeLogList.Select(x => new TimeLog + var ret = timeLogList.Select(x => new TimeLog { Id = x.Id, CalendarWeek = x.CalendarWeek, @@ -324,12 +323,12 @@ namespace SQLiteRepository return ret; } - private LogDirectionDB GetLogDirection(int userId) + private LogDirectionDb GetLogDirection(int userId) { - var logDirection = LogDirectionDB.UNKNOWN; + var logDirection = LogDirectionDb.UNKNOWN; if (userId != -1) { - var lastEntry = _connection.Query( + var lastEntry = _connection.Query( SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION, userId); if (lastEntry.Any()) @@ -338,21 +337,21 @@ namespace SQLiteRepository // See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in) if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime)) { - logDirection = LogDirectionDB.IN; + logDirection = LogDirectionDb.IN; } else { // we have a time log from today already, so just do the opposite of what we last did! - if (lastLog.Direction == LogDirectionDB.IN) - logDirection = LogDirectionDB.OUT; - else if (lastLog.Direction == LogDirectionDB.OUT) - logDirection = LogDirectionDB.IN; + if (lastLog.Direction == LogDirectionDb.IN) + logDirection = LogDirectionDb.OUT; + else if (lastLog.Direction == LogDirectionDb.OUT) + logDirection = LogDirectionDb.IN; } } else { //assume its the first then! - logDirection = LogDirectionDB.IN; + logDirection = LogDirectionDb.IN; } } return logDirection; diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj index 00858cc..de10722 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj @@ -57,7 +57,8 @@ - + + diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLog.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLogDb.cs similarity index 68% rename from DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLog.cs rename to DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLogDb.cs index f2b0777..7e13b4e 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLog.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/TimeLogDb.cs @@ -3,22 +3,15 @@ using SQLite.Net.Attributes; namespace SQLiteRepository { - public sealed class TimeLogDB + public sealed class TimeLogDb { [PrimaryKey, AutoIncrement] public int Id { get; set; } public int UserId_FK { get; set; } public int IdentifierId { get; set; } - public LogDirectionDB Direction { get; set; } + public LogDirectionDb Direction { get; set; } public DateTimeOffset SwipeEventDateTime { get; set; } public int CalendarWeek { get; set; } public int Year { get; set; } } - - public enum LogDirectionDB - { - UNKNOWN = 0, - IN = 1, - OUT = 2 - } } \ No newline at end of file