Add Api Endpoint to save/retrieve the active policy.Policy
Add SQLite code to save the policy html/markdown scripts from the user #94
This commit is contained in:
parent
f286498540
commit
dc2210b5b3
@ -112,5 +112,9 @@ namespace Interfaces
|
|||||||
OperationResponse DeleteLog(TimeLog log);
|
OperationResponse DeleteLog(TimeLog log);
|
||||||
OperationResponse CreateLog(TimeLog log);
|
OperationResponse CreateLog(TimeLog log);
|
||||||
OperationResponse UpdateLog(TimeLog log);
|
OperationResponse UpdateLog(TimeLog log);
|
||||||
|
|
||||||
|
Policy GetPolicy();
|
||||||
|
|
||||||
|
void SavePolicy(Policy policy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,6 +70,7 @@
|
|||||||
<Compile Include="IdentifierList.cs" />
|
<Compile Include="IdentifierList.cs" />
|
||||||
<Compile Include="ManualLog.cs" />
|
<Compile Include="ManualLog.cs" />
|
||||||
<Compile Include="OperationResponse.cs" />
|
<Compile Include="OperationResponse.cs" />
|
||||||
|
<Compile Include="Policy.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="TimeLog.cs" />
|
<Compile Include="TimeLog.cs" />
|
||||||
<Compile Include="TimeLogList.cs" />
|
<Compile Include="TimeLogList.cs" />
|
||||||
|
|||||||
18
DataCenter_Windows/WindowsDataCenter/Interfaces/Policy.cs
Normal file
18
DataCenter_Windows/WindowsDataCenter/Interfaces/Policy.cs
Normal file
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -38,6 +38,8 @@ namespace SQLiteRepository
|
|||||||
_connection.CreateTable<GroupDb>();
|
_connection.CreateTable<GroupDb>();
|
||||||
_connection.CreateTable<UserGroupJoinDb>();
|
_connection.CreateTable<UserGroupJoinDb>();
|
||||||
_connection.CreateTable<DbVersion>();
|
_connection.CreateTable<DbVersion>();
|
||||||
|
_connection.CreateTable<PolicyDb>();
|
||||||
|
|
||||||
_logger.Trace("Initialised SQLite Repository");
|
_logger.Trace("Initialised SQLite Repository");
|
||||||
_logger.Trace("Checking For Upgrades");
|
_logger.Trace("Checking For Upgrades");
|
||||||
CheckForDbUpgrade();
|
CheckForDbUpgrade();
|
||||||
@ -520,6 +522,34 @@ namespace SQLiteRepository
|
|||||||
return OperationResponse.UPDATED;
|
return OperationResponse.UPDATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Policy GetPolicy()
|
||||||
|
{
|
||||||
|
var query = $"select * from {nameof(PolicyDb)}";
|
||||||
|
var policies = _connection.Query<PolicyDb>(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<int>(query);
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
private int GetUserCount()
|
private int GetUserCount()
|
||||||
{
|
{
|
||||||
return _connection.ExecuteScalar<int>(SQLiteProcedures.GET_TOTAL_USER_COUNT);
|
return _connection.ExecuteScalar<int>(SQLiteProcedures.GET_TOTAL_USER_COUNT);
|
||||||
|
|||||||
@ -80,12 +80,14 @@
|
|||||||
<Compile Include="CardUniqueId.cs" />
|
<Compile Include="CardUniqueId.cs" />
|
||||||
<Compile Include="Converters\LogDirectionConverter.cs" />
|
<Compile Include="Converters\LogDirectionConverter.cs" />
|
||||||
<Compile Include="Converters\LogSourceConverter.cs" />
|
<Compile Include="Converters\LogSourceConverter.cs" />
|
||||||
|
<Compile Include="Converters\PolicyConverter.cs" />
|
||||||
<Compile Include="Converters\TimeLogConverter.cs" />
|
<Compile Include="Converters\TimeLogConverter.cs" />
|
||||||
<Compile Include="Converters\UserConverter.cs" />
|
<Compile Include="Converters\UserConverter.cs" />
|
||||||
<Compile Include="DBVersion.cs" />
|
<Compile Include="DBVersion.cs" />
|
||||||
<Compile Include="Extensions\Extensions.cs" />
|
<Compile Include="Extensions\Extensions.cs" />
|
||||||
<Compile Include="GroupDb.cs" />
|
<Compile Include="GroupDb.cs" />
|
||||||
<Compile Include="LogSourceDb.cs" />
|
<Compile Include="LogSourceDb.cs" />
|
||||||
|
<Compile Include="PolicyDb.cs" />
|
||||||
<Compile Include="SQLiteRepository.cs" />
|
<Compile Include="SQLiteRepository.cs" />
|
||||||
<Compile Include="Constants.cs" />
|
<Compile Include="Constants.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
@ -106,10 +108,10 @@
|
|||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<EmbeddedResource Include="UpgradeScripts\0.2.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="UpgradeScripts\0.2.sql" />
|
<None Include="packages.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="..\packages\System.Data.SQLite.Core.1.0.104.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net451\System.Data.SQLite.Core.targets')" />
|
<Import Project="..\packages\System.Data.SQLite.Core.1.0.104.0\build\net451\System.Data.SQLite.Core.targets" Condition="Exists('..\packages\System.Data.SQLite.Core.1.0.104.0\build\net451\System.Data.SQLite.Core.targets')" />
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Web.Http;
|
using System.Web.Http;
|
||||||
|
using WindowsDataCenter.Helpers;
|
||||||
using Interfaces;
|
using Interfaces;
|
||||||
|
|
||||||
namespace WindowsDataCenter
|
namespace WindowsDataCenter
|
||||||
@ -7,6 +8,12 @@ namespace WindowsDataCenter
|
|||||||
[RoutePrefix("api/app")]
|
[RoutePrefix("api/app")]
|
||||||
public class ApplicationController:ApiController
|
public class ApplicationController:ApiController
|
||||||
{
|
{
|
||||||
|
private IRepository _repo;
|
||||||
|
public ApplicationController(IRepository repo)
|
||||||
|
{
|
||||||
|
_repo = repo;
|
||||||
|
}
|
||||||
|
|
||||||
[Route("")]
|
[Route("")]
|
||||||
public IHttpActionResult GetAppDetails()
|
public IHttpActionResult GetAppDetails()
|
||||||
{
|
{
|
||||||
@ -22,5 +29,23 @@ namespace WindowsDataCenter
|
|||||||
|
|
||||||
return Ok(appDetails);
|
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..
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user