renamed TimeLogDB to TimeLogDb.

moved LogDirectionDB to its own file and renamed to LogDirectionDb
This commit is contained in:
chris.watts90@outlook.com 2017-02-09 21:33:52 +00:00
parent 150a9a8d70
commit 38fab21afd
5 changed files with 28 additions and 26 deletions

View File

@ -0,0 +1,9 @@
namespace SQLiteRepository
{
public enum LogDirectionDb
{
UNKNOWN = 0,
IN = 1,
OUT = 2
}
}

View File

@ -2,7 +2,7 @@ namespace SQLiteRepository
{ {
internal static class SQLiteProcedures 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_ALL_USERS = "select * from " + nameof(UserIdentity);
public const string GET_USER_BY_ID = "select * from " + nameof(UserIdentity) + " where " + nameof(UserIdentity.Id) + "=?"; 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 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";
} }
} }

View File

@ -20,7 +20,7 @@ namespace SQLiteRepository
_connection.CreateTable<CardUniqueId>(); _connection.CreateTable<CardUniqueId>();
_connection.CreateTable<UserIdentity>(); _connection.CreateTable<UserIdentity>();
_connection.CreateTable<TimeLogDB>(); _connection.CreateTable<TimeLogDb>();
} }
public UserList GetUsers() public UserList GetUsers()
@ -288,7 +288,7 @@ namespace SQLiteRepository
//TODO: Handle When the identifier is assigned to a user (identifier has -1) //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. //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,
UserId_FK = ident.UserId_FK, UserId_FK = ident.UserId_FK,
@ -306,12 +306,11 @@ namespace SQLiteRepository
private List<TimeLog> GetTimeLogList(int userId, int calendarWeek, int year) private List<TimeLog> GetTimeLogList(int userId, int calendarWeek, int year)
{ {
List<TimeLog> ret; var timeLogList = _connection.Query<TimeLogDb>(
var timeLogList = _connection.Query<TimeLogDB>(
SQLiteProcedures.GET_TIMELOGS, SQLiteProcedures.GET_TIMELOGS,
userId, calendarWeek, year); userId, calendarWeek, year);
ret= timeLogList.Select(x => new TimeLog var ret = timeLogList.Select(x => new TimeLog
{ {
Id = x.Id, Id = x.Id,
CalendarWeek = x.CalendarWeek, CalendarWeek = x.CalendarWeek,
@ -324,12 +323,12 @@ namespace SQLiteRepository
return ret; return ret;
} }
private LogDirectionDB GetLogDirection(int userId) private LogDirectionDb GetLogDirection(int userId)
{ {
var logDirection = LogDirectionDB.UNKNOWN; var logDirection = LogDirectionDb.UNKNOWN;
if (userId != -1) if (userId != -1)
{ {
var lastEntry = _connection.Query<TimeLogDB>( var lastEntry = _connection.Query<TimeLogDb>(
SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION, SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION,
userId); userId);
if (lastEntry.Any()) if (lastEntry.Any())
@ -338,21 +337,21 @@ namespace SQLiteRepository
// See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in) // See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in)
if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime)) if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime))
{ {
logDirection = LogDirectionDB.IN; logDirection = LogDirectionDb.IN;
} }
else else
{ {
// we have a time log from today already, so just do the opposite of what we last did! // we have a time log from today already, so just do the opposite of what we last did!
if (lastLog.Direction == LogDirectionDB.IN) if (lastLog.Direction == LogDirectionDb.IN)
logDirection = LogDirectionDB.OUT; logDirection = LogDirectionDb.OUT;
else if (lastLog.Direction == LogDirectionDB.OUT) else if (lastLog.Direction == LogDirectionDb.OUT)
logDirection = LogDirectionDB.IN; logDirection = LogDirectionDb.IN;
} }
} }
else else
{ {
//assume its the first then! //assume its the first then!
logDirection = LogDirectionDB.IN; logDirection = LogDirectionDb.IN;
} }
} }
return logDirection; return logDirection;

View File

@ -57,7 +57,8 @@
<Compile Include="Constants.cs" /> <Compile Include="Constants.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SQLiteProcedures.cs" /> <Compile Include="SQLiteProcedures.cs" />
<Compile Include="TimeLog.cs" /> <Compile Include="LogDirectionDb.cs" />
<Compile Include="TimeLogDb.cs" />
<Compile Include="UserIdentity.cs" /> <Compile Include="UserIdentity.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -3,22 +3,15 @@ using SQLite.Net.Attributes;
namespace SQLiteRepository namespace SQLiteRepository
{ {
public sealed class TimeLogDB public sealed class TimeLogDb
{ {
[PrimaryKey, AutoIncrement] [PrimaryKey, AutoIncrement]
public int Id { get; set; } public int Id { get; set; }
public int UserId_FK { get; set; } public int UserId_FK { get; set; }
public int IdentifierId { get; set; } public int IdentifierId { get; set; }
public LogDirectionDB Direction { get; set; } public LogDirectionDb Direction { get; set; }
public DateTimeOffset SwipeEventDateTime { get; set; } public DateTimeOffset SwipeEventDateTime { get; set; }
public int CalendarWeek { get; set; } public int CalendarWeek { get; set; }
public int Year { get; set; } public int Year { get; set; }
} }
public enum LogDirectionDB
{
UNKNOWN = 0,
IN = 1,
OUT = 2
}
} }