add converters to help convert from/to data transfer objects.
removed conversion code from SQLiteRepository.cs in favour of new converters. pulled out string queries from SQLiteRepository and moved to SQLiteProcedures.cs. #95
This commit is contained in:
parent
492314a956
commit
f871c23631
@ -0,0 +1,51 @@
|
||||
using Interfaces;
|
||||
|
||||
namespace SQLiteRepository.Converters
|
||||
{
|
||||
static class LogDirectionConverter
|
||||
{
|
||||
public static LogDirection ConvertToLogDirectionDto(LogDirectionDb direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirectionDb.IN:
|
||||
return LogDirection.IN;
|
||||
case LogDirectionDb.OUT:
|
||||
return LogDirection.OUT;
|
||||
default:
|
||||
return LogDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogDirectionDb ConvertFromLogDirectionDto(LogDirection direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirection.IN:
|
||||
return LogDirectionDb.IN;
|
||||
case LogDirection.OUT:
|
||||
return LogDirectionDb.OUT;
|
||||
default:
|
||||
return LogDirectionDb.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogDirectionDb InvertLogDirectionDb(LogDirectionDb direction)
|
||||
{
|
||||
return (LogDirectionDb)(int)InvertLogDirection((LogDirection)(int)direction);
|
||||
}
|
||||
|
||||
public static LogDirection InvertLogDirection(LogDirection direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirection.IN:
|
||||
return LogDirection.OUT;
|
||||
case LogDirection.OUT:
|
||||
return LogDirection.IN;
|
||||
default:
|
||||
return LogDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
using Interfaces;
|
||||
|
||||
namespace SQLiteRepository.Converters
|
||||
{
|
||||
static class LogSourceConverter
|
||||
{
|
||||
public static LogSource ConvertToLogSourceDto(LogSourceDb source)
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
case LogSourceDb.IDENTIFIER:
|
||||
return LogSource.IDENTIFIER;
|
||||
case LogSourceDb.TRAYAPP:
|
||||
return LogSource.TRAYAPP;
|
||||
case LogSourceDb.UI:
|
||||
return LogSource.UI;
|
||||
default:
|
||||
return LogSource.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogSourceDb ConvertFromLogSourceDto(LogSource source)
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
case LogSource.IDENTIFIER:
|
||||
return LogSourceDb.IDENTIFIER;
|
||||
case LogSource.TRAYAPP:
|
||||
return LogSourceDb.TRAYAPP;
|
||||
case LogSource.UI:
|
||||
return LogSourceDb.UI;
|
||||
default:
|
||||
return LogSourceDb.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -39,84 +39,4 @@ namespace SQLiteRepository.Converters
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
static class LogSourceConverter
|
||||
{
|
||||
public static LogSource ConvertToLogSourceDto(LogSourceDb source)
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
case LogSourceDb.IDENTIFIER:
|
||||
return LogSource.IDENTIFIER;
|
||||
case LogSourceDb.TRAYAPP:
|
||||
return LogSource.TRAYAPP;
|
||||
case LogSourceDb.UI:
|
||||
return LogSource.UI;
|
||||
default:
|
||||
return LogSource.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogSourceDb ConvertFromLogSourceDto(LogSource source)
|
||||
{
|
||||
switch (source)
|
||||
{
|
||||
case LogSource.IDENTIFIER:
|
||||
return LogSourceDb.IDENTIFIER;
|
||||
case LogSource.TRAYAPP:
|
||||
return LogSourceDb.TRAYAPP;
|
||||
case LogSource.UI:
|
||||
return LogSourceDb.UI;
|
||||
default:
|
||||
return LogSourceDb.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class LogDirectionConverter
|
||||
{
|
||||
public static LogDirection ConvertToLogDirectionDto(LogDirectionDb direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirectionDb.IN:
|
||||
return LogDirection.IN;
|
||||
case LogDirectionDb.OUT:
|
||||
return LogDirection.OUT;
|
||||
default:
|
||||
return LogDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogDirectionDb ConvertFromLogDirectionDto(LogDirection direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirection.IN:
|
||||
return LogDirectionDb.IN;
|
||||
case LogDirection.OUT:
|
||||
return LogDirectionDb.OUT;
|
||||
default:
|
||||
return LogDirectionDb.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
public static LogDirectionDb InvertLogDirectionDb(LogDirectionDb direction)
|
||||
{
|
||||
return (LogDirectionDb)(int)InvertLogDirection((LogDirection)(int)direction);
|
||||
}
|
||||
|
||||
public static LogDirection InvertLogDirection(LogDirection direction)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case LogDirection.IN:
|
||||
return LogDirection.OUT;
|
||||
case LogDirection.OUT:
|
||||
return LogDirection.IN;
|
||||
default:
|
||||
return LogDirection.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -126,5 +126,7 @@ namespace SQLiteRepository
|
||||
+ nameof(TimeLogDb.Year) + "=?,"
|
||||
+ nameof(TimeLogDb.Source) + "=? "
|
||||
+ "where " + nameof(TimeLogDb.Id) + "=?";
|
||||
|
||||
public const string GET_DB_VERSION = "select * from DbVersion";
|
||||
}
|
||||
}
|
||||
@ -515,20 +515,12 @@ namespace SQLiteRepository
|
||||
|
||||
public OperationResponse CreateLog(TimeLog log)
|
||||
{
|
||||
var calendarWeek = GetIso8601CalendarWeek(log.EventTime.UtcDateTime);
|
||||
var year = log.EventTime.Year;
|
||||
log.CalendarWeek = calendarWeek;
|
||||
log.Year = year;
|
||||
var dbLog = new TimeLogDb
|
||||
{
|
||||
SwipeEventDateTime = log.EventTime,
|
||||
Direction = (LogDirectionDb)(int)log.Direction,
|
||||
Year = year,
|
||||
CalendarWeek = calendarWeek,
|
||||
Source = (LogSourceDb)(int)log.Source,
|
||||
UserId_FK = log.UserId,
|
||||
IdentifierId = ConvertSourceToIdentifierId(log.Source),
|
||||
};
|
||||
log.CalendarWeek = GetIso8601CalendarWeek(log.EventTime.UtcDateTime);
|
||||
log.Year= log.EventTime.Year;
|
||||
|
||||
var dbLog = TimeLogConverter.ConvertFromTimeLogDto(log);
|
||||
dbLog.IdentifierId = ConvertSourceToIdentifierId(log.Source);
|
||||
|
||||
#region update in/out directions for manual logs.
|
||||
UpdateExistingLogDirections(log);
|
||||
#endregion
|
||||
@ -541,6 +533,7 @@ namespace SQLiteRepository
|
||||
{
|
||||
var query = _connection.Query<TimeLogDb>(
|
||||
SQLiteProcedures.GET_TIMELOG_ENTRY, log.Id);
|
||||
|
||||
if(!query.Any())
|
||||
return OperationResponse.FAILED;
|
||||
|
||||
@ -562,7 +555,7 @@ namespace SQLiteRepository
|
||||
|
||||
private void CheckForDbUpgrade()
|
||||
{
|
||||
var data = _connection.Query<DbVersion>("select * from DbVersion");
|
||||
var data = _connection.Query<DbVersion>(SQLiteProcedures.GET_DB_VERSION);
|
||||
if (!data.Any())
|
||||
{
|
||||
//Pre-Upgrade database, need upgrading
|
||||
@ -813,7 +806,7 @@ namespace SQLiteRepository
|
||||
|
||||
private void UpdateIdentifierLastUsed(DateTimeOffset dt, int cardId)
|
||||
{
|
||||
var res = _connection.ExecuteScalar<CardUniqueId>(SQLiteProcedures.UPDATE_CARD_LAST_USED,
|
||||
_connection.ExecuteScalar<CardUniqueId>(SQLiteProcedures.UPDATE_CARD_LAST_USED,
|
||||
dt,
|
||||
cardId);
|
||||
}
|
||||
@ -862,18 +855,6 @@ namespace SQLiteRepository
|
||||
return dt.Date.CompareTo(DateTime.Today.Date) < 0;
|
||||
}
|
||||
|
||||
private User ChangeToUserObject(UserIdentity user)
|
||||
{
|
||||
return new User
|
||||
{
|
||||
UserId = user.Id,
|
||||
FirstName = user.FirstName,
|
||||
LastName = user.LastName,
|
||||
HoursPerWeek = user.HoursPerWeek,
|
||||
IsContractor = user.IsContractor
|
||||
};
|
||||
}
|
||||
|
||||
private void UpdateExistingLogDirections(TimeLog log)
|
||||
{
|
||||
//need to make this generic so that both create and delete will update the log directions.. but ARGH.
|
||||
|
||||
@ -78,6 +78,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CardUniqueId.cs" />
|
||||
<Compile Include="Converters\LogDirectionConverter.cs" />
|
||||
<Compile Include="Converters\LogSourceConverter.cs" />
|
||||
<Compile Include="Converters\TimeLogConverter.cs" />
|
||||
<Compile Include="Converters\UserConverter.cs" />
|
||||
<Compile Include="DBVersion.cs" />
|
||||
<Compile Include="GroupDb.cs" />
|
||||
<Compile Include="LogSourceDb.cs" />
|
||||
|
||||
@ -55,6 +55,7 @@
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
<DocumentationFile>bin\ReleaseInstallers\WindowsDataCenter.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="DalSoft.WebApi.HelpPage, Version=0.0.7.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user