From 380b976f3d35648ba5a0bb34b1884079ceccd97d Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Wed, 11 Sep 2019 17:38:43 +0100 Subject: [PATCH] add code to support nodes providing their own time (in support of satellite modes) #72 --- .../Controllers/SwipeDataController.cs | 98 ++++++++++--------- 1 file changed, 52 insertions(+), 46 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs index ed31a9f..91e5c96 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs @@ -1,47 +1,53 @@ -using System; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using Interfaces; - -namespace WindowsDataCenter -{ - /// - /// - /// - [RoutePrefix("api/swipedata")] - public class SwipeDataController : ApiController - { - private readonly IRepository _repo; - private readonly ILogger _logger; - - /// - /// - /// - /// - /// - public SwipeDataController(IRepository repo, ILogger logger) - { - if(repo == null) throw new ArgumentNullException(nameof(repo)); - _repo = repo; - if(logger == null) throw new ArgumentNullException(nameof(logger)); - _logger = logger; - } - - /// - /// - /// - /// - /// - [HttpPost] - [Route("")] - public IHttpActionResult PostData([FromBody] CardData cData) - { - int logId; - var resp = _repo.LogEventTime(new Identifier {UniqueId = cData.CardUId}, out logId); - _logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}, direction is : {2}", cData.CardUId, - DateTime.UtcNow, resp.Direction); - return Ok(new {Id = logId, resp.Direction}); - } - } +using System; +using System.Net; +using System.Net.Http; +using System.Web.Http; +using Interfaces; + +namespace WindowsDataCenter +{ + /// + /// + /// + [RoutePrefix("api/swipedata")] + public class SwipeDataController : ApiController + { + private readonly IRepository _repo; + private readonly ILogger _logger; + + /// + /// + /// + /// + /// + public SwipeDataController(IRepository repo, ILogger logger) + { + if(repo == null) throw new ArgumentNullException(nameof(repo)); + _repo = repo; + if(logger == null) throw new ArgumentNullException(nameof(logger)); + _logger = logger; + } + + /// + /// + /// + /// + /// + [HttpPost] + [Route("")] + public IHttpActionResult PostData([FromBody] CardData cData) + { + int logId; + + var id = new Identifier {UniqueId = cData.CardUId}; + + var resp = cData.UtcTimeStamp.HasValue + ? _repo.LogEventTime(id, out logId, cData.UtcTimeStamp.Value) + : _repo.LogEventTime(id, out logId); + + _logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}, direction is : {2}", cData.CardUId, + DateTime.UtcNow, resp.Direction); + return Ok(new {Id = logId, resp.Direction}); + } + } } \ No newline at end of file