diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs index 63402ab..804bb04 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs @@ -112,5 +112,9 @@ namespace Interfaces OperationResponse DeleteLog(TimeLog log); OperationResponse CreateLog(TimeLog log); OperationResponse UpdateLog(TimeLog log); + + Policy GetPolicy(); + + void SavePolicy(Policy policy); } } diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj b/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj index 84f5ae8..e3b58bc 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj @@ -1,87 +1,88 @@ - - - - - Debug - AnyCPU - {B7347B72-E208-423A-9D99-723B558EA3D7} - Library - Properties - Interfaces - Interfaces - v4.5 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - bin\DebugInstallers\ - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - bin\ReleaseInstallers\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + AnyCPU + {B7347B72-E208-423A-9D99-723B558EA3D7} + Library + Properties + Interfaces + Interfaces + v4.5 + 512 + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\DebugInstallers\ + DEBUG;TRACE + full + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + bin\ReleaseInstallers\ + TRACE + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + --> \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/Policy.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/Policy.cs new file mode 100644 index 0000000..6baac80 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/Policy.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public class Policy + { + public DateTime ChangeDate { get; set; } + public string ChangeDescription { get; set; } + public string ChangeAuthor { get; set; } + public string Version { get; set; } + public string Markdown { get; set; } + public string Html { get; set; } + } +} diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Converters/PolicyConverter.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Converters/PolicyConverter.cs new file mode 100644 index 0000000..79cf4e4 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/Converters/PolicyConverter.cs @@ -0,0 +1,35 @@ +using Interfaces; + +namespace SQLiteRepository.Converters +{ + static class PolicyConverter + { + public static Policy ConvertToPolicyDto(PolicyDb policyDb) + { + if (policyDb == null) return null; + return new Policy + { + ChangeDescription = policyDb.ChangeDescription, + ChangeDate = policyDb.ChangeDate.UtcDateTime, + Html = policyDb.Html, + Version = policyDb.Version, + ChangeAuthor = policyDb.ChangeAuthor, + Markdown = policyDb.Markdown + }; + } + + public static PolicyDb ConvertFromPolicyDto(Policy policy) + { + if (policy == null) return null; + return new PolicyDb + { + ChangeDescription = policy.ChangeDescription, + ChangeDate = policy.ChangeDate, + Html = policy.Html, + Version = policy.Version, + ChangeAuthor = policy.ChangeAuthor, + Markdown = policy.Markdown + }; + } + } +} \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/PolicyDb.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/PolicyDb.cs new file mode 100644 index 0000000..ab2017d --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/PolicyDb.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SQLite.Net.Attributes; + +namespace SQLiteRepository +{ + internal class PolicyDb + { + [PrimaryKey, AutoIncrement] + public int Id { get; set; } + public DateTimeOffset ChangeDate { get; set; } + + public string ChangeDescription { get; set; } + + public string ChangeAuthor { get; set; } + + public string Version { get; set; } + + public string Markdown { get; set; } + + public string Html { get; set; } + + } +} diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index 67ca87a..44941ca 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -38,6 +38,8 @@ namespace SQLiteRepository _connection.CreateTable(); _connection.CreateTable(); _connection.CreateTable(); + _connection.CreateTable(); + _logger.Trace("Initialised SQLite Repository"); _logger.Trace("Checking For Upgrades"); CheckForDbUpgrade(); @@ -519,7 +521,35 @@ namespace SQLiteRepository return OperationResponse.UPDATED; } - + + public Policy GetPolicy() + { + var query = $"select * from {nameof(PolicyDb)}"; + var policies = _connection.Query(query); + + + return PolicyConverter.ConvertToPolicyDto(policies.OrderByDescending(x => x.Version).FirstOrDefault()); + } + + public void SavePolicy(Policy policy) + { + if (string.IsNullOrEmpty(policy.Version)) + { + policy.Version = (GetNextPolicyVersion()+1).ToString(); + } + var policyDb = PolicyConverter.ConvertFromPolicyDto(policy); + _connection.Insert(policyDb); + } + + private int GetNextPolicyVersion() + { + var query = $"select Max({nameof(PolicyDb.Id)}) from {nameof(PolicyDb)}"; + + var id = _connection.ExecuteScalar(query); + + return id; + } + private int GetUserCount() { return _connection.ExecuteScalar(SQLiteProcedures.GET_TOTAL_USER_COUNT); diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj index 9d457bc..2e83834 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.csproj @@ -1,129 +1,131 @@ - - - - - Debug - AnyCPU - {B3510C81-F069-48A2-B826-EBE0CE7AB0B2} - Library - Properties - SQLiteRepository - SQLiteRepository - v4.5.2 - 512 - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - true - bin\DebugInstallers\ - DEBUG;TRACE - full - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - bin\ReleaseInstallers\ - TRACE - true - pdbonly - AnyCPU - prompt - MinimumRecommendedRules.ruleset - - - - ..\packages\SQLite.Net.Core-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll - True - - - ..\packages\SQLite.Net-PCL.3.1.1\lib\net40\SQLite.Net.Platform.Generic.dll - True - - - ..\packages\SQLite.Net-PCL.3.1.1\lib\net4\SQLite.Net.Platform.Win32.dll - True - - - - - - ..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net451\System.Data.SQLite.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - {115250F6-F8C4-4F9B-A15F-251EA258D963} - ConfigurationHandler - - - {B7347B72-E208-423A-9D99-723B558EA3D7} - Interfaces - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + + + + + Debug + AnyCPU + {B3510C81-F069-48A2-B826-EBE0CE7AB0B2} + Library + Properties + SQLiteRepository + SQLiteRepository + v4.5.2 + 512 + + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + true + bin\DebugInstallers\ + DEBUG;TRACE + full + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + bin\ReleaseInstallers\ + TRACE + true + pdbonly + AnyCPU + prompt + MinimumRecommendedRules.ruleset + + + + ..\packages\SQLite.Net.Core-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll + True + + + ..\packages\SQLite.Net-PCL.3.1.1\lib\net40\SQLite.Net.Platform.Generic.dll + True + + + ..\packages\SQLite.Net-PCL.3.1.1\lib\net4\SQLite.Net.Platform.Win32.dll + True + + + + + + ..\packages\System.Data.SQLite.Core.1.0.104.0\lib\net451\System.Data.SQLite.dll + True + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {115250F6-F8C4-4F9B-A15F-251EA258D963} + ConfigurationHandler + + + {B7347B72-E208-423A-9D99-723B558EA3D7} + Interfaces + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + --> \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/packages.config b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/packages.config index 633c6d1..03b7b99 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/packages.config +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/packages.config @@ -1,6 +1,6 @@ - - - - - + + + + + \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/ApplicationController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/ApplicationController.cs index 8b3fc15..ce47313 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/ApplicationController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/ApplicationController.cs @@ -1,26 +1,51 @@ -using System.Reflection; -using System.Web.Http; -using Interfaces; - -namespace WindowsDataCenter -{ - [RoutePrefix("api/app")] - public class ApplicationController:ApiController - { - [Route("")] - public IHttpActionResult GetAppDetails() - { - var ninjectHelper = NinjectHelper.GetInstance(); - var appDetails = new AppDetails - { - ApplicationName = "Flexitime Tracker", - DataBaseProvider = ninjectHelper.Get().GetType().ToString(), - LoggerProvider = ninjectHelper.Get().GetType().ToString(), - Version = Assembly.GetEntryAssembly().GetName().Version.ToString(), - ErrorEmailAddress = ConfigurationHandler.ConfigurationHandler.GetConfiguration("BugSubmissionEmailAddress") ?? "NONE" - }; - - return Ok(appDetails); - } - } -} +using System.Reflection; +using System.Web.Http; +using WindowsDataCenter.Helpers; +using Interfaces; + +namespace WindowsDataCenter +{ + [RoutePrefix("api/app")] + public class ApplicationController:ApiController + { + private IRepository _repo; + public ApplicationController(IRepository repo) + { + _repo = repo; + } + + [Route("")] + public IHttpActionResult GetAppDetails() + { + var ninjectHelper = NinjectHelper.GetInstance(); + var appDetails = new AppDetails + { + ApplicationName = "Flexitime Tracker", + DataBaseProvider = ninjectHelper.Get().GetType().ToString(), + LoggerProvider = ninjectHelper.Get().GetType().ToString(), + Version = Assembly.GetEntryAssembly().GetName().Version.ToString(), + ErrorEmailAddress = ConfigurationHandler.ConfigurationHandler.GetConfiguration("BugSubmissionEmailAddress") ?? "NONE" + }; + + return Ok(appDetails); + } + + [Route("policy")] + [HttpGet] + [CacheControl(MaxAge = 0)] + public IHttpActionResult GetPolicy() + { + Policy policy = _repo.GetPolicy(); + return Json(policy); + } + + [Route("policy")] + [HttpPost] + [CacheControl(MaxAge = 0)] + public IHttpActionResult SavePolicy(Policy policy) + { + _repo.SavePolicy(policy); + return Ok(new {}); //empty to ensure ajax triggers Success.. + } + } +}