diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs index 8cf0ea0..2a8c720 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs @@ -11,6 +11,15 @@ /// UserList GetUsers(); /// + /// Search the user list for the following string + /// + /// string to search the user store for. + /// + /// Returns with full list of users, + /// plus a total user count. Pagination options are supported. + /// + UserList Search(string searchParam); + /// /// Get details about a single user in the system base on their Id /// /// diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs index 303d7d3..701dfe7 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs @@ -8,6 +8,7 @@ namespace Interfaces { Users = new List(); } + public string Query { get; set; } public int UserCount { get { return Users.Count; } } public List Users { get; set; } public int PageSize { get; set; } diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs index 959b755..1ed3431 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteProcedures.cs @@ -14,5 +14,6 @@ namespace SQLiteRepository public const string UPDATE_CARD_USER_ID = "update CardUniqueId set UserId_FK=? where Id=?"; + public const string SEARCH_USER_LIST = "SELECT * FROM[UserIdentity] where(FirstName Like ? OR LastName Like ?)"; } } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index 4afd5f6..8dd9c76 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -58,6 +58,45 @@ namespace SQLiteRepository return ret; } + public UserList Search(string searchParam) + { + var ret = new UserList(); + searchParam = string.Format("%{0}%", searchParam); + var users = _connection.Query( + SQLiteProcedures.SEARCH_USER_LIST, + searchParam, searchParam); + + if (!users.Any()) + { + ret.PageNumber = 1; + ret.PageSize = 20; + return ret; + } + + foreach (var user in users) + { + var userObj = ChangeToUserObject(user); + var cards = _connection.Query( + SQLiteProcedures.GET_CARDS_BY_USER_ID, + user.Id); + + foreach (var card in cards) + { + userObj.AssociatedIdentifiers.Add(new Identifier() + { + UniqueId = card.CardUId, + IsAssociatedToUser = true, + Id = card.Id + }); + } + ret.Users.Add(userObj); + } + ret.PageSize = 20; + ret.PageNumber = 1; + + return ret; + } + public User GetUser(int id) { var ret = new User(); diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs index 0322f2d..2ed6dd7 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/UsersController.cs @@ -19,9 +19,10 @@ namespace WindowsDataCenter [HttpGet] [Route("")] - public IHttpActionResult GetUsers([FromUri] int pageSize = -1, [FromUri] int pageNumber =-1) + public IHttpActionResult GetUsers([FromUri] string query = "",[FromUri] int pageSize = -1, [FromUri] int pageNumber =-1) { - var userList = _repo.GetUsers(); + var userList = query == string.Empty ? _repo.GetUsers() : _repo.Search(query); + userList.Query = query == string.Empty ? null : query; var msg = Request.CreateResponse(HttpStatusCode.OK, userList); diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html index ba936f5..4c38957 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html @@ -2,9 +2,19 @@ Flexi Time Data Viewer - - - + + + + + + + + + + + + @@ -34,22 +44,22 @@ - + - + - Go! + Go! - - - + + + Add New User - - + + ID @@ -76,37 +86,45 @@ - + Users - + - First Name - + First Name + Last Name - + Hours Per Week - + + + + + + + + + Associated Cards - + - + - + @@ -122,21 +140,21 @@ - + - + - Submit + Cancel Submit - + Users @@ -150,12 +168,9 @@ - - Content @@ -230,13 +245,11 @@ - - - - - - + +
Content