From 440c1f44cedaa0491b9dcd68ee4b0289fc915bef Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Tue, 31 Jan 2017 21:57:21 +0000 Subject: [PATCH] Added IRepository comments. Changed oder of response codes. changed HoursPerWeek to use float not int. Changed AssociatedIdentifierCount to use count property on AssociatedIdentifiers instead of needing to populate separately. Changed UserCount in UserList for the same reason. Added Users list initialisation to prevent null ref exception. overrode Equals and GetHashCode to allow use of List.Except method. (tests show without this, Except is useless). --- .../Interfaces/IRepository.cs | 77 +++++++++++++++++-- .../Interfaces/Identifier.cs | 15 ++++ .../Interfaces/OperationResponse.cs | 4 +- .../WindowsDataCenter/Interfaces/User.cs | 9 ++- .../WindowsDataCenter/Interfaces/UserList.cs | 6 +- 5 files changed, 100 insertions(+), 11 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs index cffe1de..8cf0ea0 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs @@ -1,17 +1,82 @@ -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Interfaces +namespace Interfaces { public interface IRepository { + /// + /// Get a list of Users + /// + /// + /// Returns with full list of users, + /// plus a total user count. Pagination options are supported. + /// UserList GetUsers(); + /// + /// Get details about a single user in the system base on their Id + /// + /// + /// integer data type, the Id of the User to get details about. + /// + /// object with full details, + /// including full + /// User GetUser(int id); + /// + /// Get a list of the timelogs available for the specified user + /// for the current Calendar Week + /// + /// + /// integer data type, the Id of the user to get time logs for + /// + /// + /// with nested objects + /// for the current calendar week + /// TimeLogList GetTimeLogs(int userId); + /// + /// Get a list of the timelogs available for the specified user + /// for the specified calendar week + /// + /// + /// integer data type, the Id of the user to get time logs for + /// + /// + /// integer data type, the calendar week to retrieve logs for. + /// + /// + /// with nested objects + /// for the current calendar week + /// TimeLogList GetTimeLogs(int userId, int calendarWeek); - IdentifierList GetUnassignedList(); + /// + /// Get a full list of Identifiers which are not associated to a user. + /// + /// + /// with nested list + /// + IdentifierList GetUnassignedIdentifierList(); + /// + /// Update a user in the system with the new values. + /// + /// + /// If the user object passed does not exist, it will be created. + /// + /// + /// object detailing the new properties to assign to the user. + /// The Id Field should not be changed, or should be -1 for new users. + /// + /// + /// to indicate procedure status. + /// OperationResponse UpdateUser(User user); + /// + /// Create a new TimeLog Event in the repository. + /// + /// + /// object with the Unique Id triggering the event + /// + /// + /// to indicate procedure status. + /// OperationResponse LogEventTime(Identifier identifier); } } diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/Identifier.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/Identifier.cs index 1c3b7a6..52766ff 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/Identifier.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/Identifier.cs @@ -5,5 +5,20 @@ public int Id { get; set; } public string UniqueId { get; set; } public bool IsAssociatedToUser { get; set; } + + public override bool Equals(object obj) + { + var identObj = obj as Identifier; + if (identObj == null) return false; + + return identObj.Id == Id + && identObj.IsAssociatedToUser == IsAssociatedToUser + && identObj.UniqueId == UniqueId; + } + + public override int GetHashCode() + { + return Id.GetHashCode() ^ UniqueId.GetHashCode() ^ IsAssociatedToUser.GetHashCode(); + } } } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/OperationResponse.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/OperationResponse.cs index 3851a5c..08df027 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/OperationResponse.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/OperationResponse.cs @@ -4,8 +4,8 @@ { NONE = 0, SUCCESS = 1, - CREATED = 2, - UPDATED = 3, + UPDATED = 2, + CREATED = 3, DELETED = 4, FAILED = 5 } diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs index e232428..0b74df6 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs @@ -11,8 +11,13 @@ namespace Interfaces public int UserId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } - public int HoursPerWeek { get; set; } - public int AssociatedIdentifierCount { get; set; } + public float HoursPerWeek { get; set; } + + public int AssociatedIdentifierCount + { + get { return AssociatedIdentifiers.Count; } + } + public List AssociatedIdentifiers { get; set; } } } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs index 18e57ee..303d7d3 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/UserList.cs @@ -4,7 +4,11 @@ namespace Interfaces { public class UserList { - public int UserCount { get; set; } + public UserList() + { + Users = new List(); + } + public int UserCount { get { return Users.Count; } } public List Users { get; set; } public int PageSize { get; set; } public int PageNumber { get; set; }