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
{
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";
}
}

View File

@ -20,7 +20,7 @@ namespace SQLiteRepository
_connection.CreateTable<CardUniqueId>();
_connection.CreateTable<UserIdentity>();
_connection.CreateTable<TimeLogDB>();
_connection.CreateTable<TimeLogDb>();
}
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<TimeLog> GetTimeLogList(int userId, int calendarWeek, int year)
{
List<TimeLog> ret;
var timeLogList = _connection.Query<TimeLogDB>(
var timeLogList = _connection.Query<TimeLogDb>(
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<TimeLogDB>(
var lastEntry = _connection.Query<TimeLogDb>(
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;

View File

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

View File

@ -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
}
}