Add LastEventDateTime property to User object
Add Code to populate the LastEventDateTime property in SQLiteRepository - getting the last TimeLogEvent datetime. will return min value if no logs available. #53
This commit is contained in:
parent
309e8c093d
commit
69f3e502e0
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Interfaces
|
||||
{
|
||||
@ -19,7 +20,7 @@ namespace Interfaces
|
||||
{
|
||||
get { return AssociatedIdentifiers.Count; }
|
||||
}
|
||||
|
||||
public DateTime LastEventDateTime { get; set; }
|
||||
public List<Identifier> AssociatedIdentifiers { get; set; }
|
||||
|
||||
public bool State { get; set; }
|
||||
|
||||
@ -98,6 +98,14 @@ namespace SQLiteRepository
|
||||
return ret;
|
||||
}
|
||||
|
||||
private DateTime GetLastLogDateTime(TimeLogDb timeLog)
|
||||
{
|
||||
if (timeLog != null)
|
||||
{
|
||||
return timeLog.SwipeEventDateTime.DateTime;
|
||||
}
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
private bool GetUserState(LogDirectionDb logDirection)
|
||||
{
|
||||
switch (logDirection)
|
||||
@ -503,23 +511,20 @@ namespace SQLiteRepository
|
||||
var logDirection = LogDirectionDb.UNKNOWN;
|
||||
if (userId != -1)
|
||||
{
|
||||
var lastEntry = _connection.Query<TimeLogDb>(
|
||||
SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION,
|
||||
userId);
|
||||
if (lastEntry.Any())
|
||||
var lastEntry = GetLastTimeLog(userId);
|
||||
if (lastEntry != null)
|
||||
{
|
||||
var lastLog = lastEntry.First();
|
||||
// See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in)
|
||||
if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime))
|
||||
if (IsLogDateTimeYesterdayOrOlder(lastEntry.SwipeEventDateTime.DateTime))
|
||||
{
|
||||
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)
|
||||
if (lastEntry.Direction == LogDirectionDb.IN)
|
||||
logDirection = LogDirectionDb.OUT;
|
||||
else if (lastLog.Direction == LogDirectionDb.OUT)
|
||||
else if (lastEntry.Direction == LogDirectionDb.OUT)
|
||||
logDirection = LogDirectionDb.IN;
|
||||
}
|
||||
}
|
||||
@ -532,6 +537,17 @@ namespace SQLiteRepository
|
||||
return logDirection;
|
||||
}
|
||||
|
||||
private TimeLogDb GetLastTimeLog(int userId)
|
||||
{
|
||||
var lastEntry = _connection.Query<TimeLogDb>(
|
||||
SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION,
|
||||
userId);
|
||||
if (lastEntry.Any())
|
||||
{
|
||||
return lastEntry.First();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Get the calendar week of the year according to the ISO8601 standard (starts monday).
|
||||
/// </summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user