using System; using System.Collections.Generic; using System.Data; namespace HRM.BO { #region UserRole public class UserRole : BasicBaseObject { #region Constructor public UserRole() { RolePermision = new List(); RoleID = 0; UserID = 0; Role = null; User = null; EventDate = DateTime.Today; CreatedBy = 0; AuthorizedBy = 0; AuthorizedDate = DateTime.MinValue; ComputerName = ""; ApprovedComputerName = ""; UserRoleStatus = EnumAuthStatus.NewNotYetApprove; } #endregion #region Properties public int RoleID { get; set; } public int UserID { get; set; } public Role Role { get; set; } public User User { get; set; } public List RolePermision { get; set; } public DateTime? AuthorizedDate { get; set; } public int AuthorizedBy { get; set; } public string ApprovedComputerName { get; set; } public DateTime EventDate { get; set; } public string ComputerName { get; set; } public EnumAuthStatus UserRoleStatus { get; set; } // not Database Property, public string loginIDView { get; set; } public string userNameView { get; set; } public string roleNameView { get; set; } public int? payrollTypeID { get; set; } public int? employeeID { get; set; } public EnumRoleType? RoleType { get; set; } public bool? IsOld { get; set; } public string? NewRoleName { get; set; } #endregion } #endregion #region IUserRole Service public interface IUserRoleService { UserRole Get(int id); List Get(EnumRoleType roleType, int?userid, int?roleID); List Get(List searhEmps); List GetByUserID(int UserID); DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate); DataTable GetUserMenuByRole(string roleId); void Save(List userRoles, int payrolltypeid); void Delete(int id); // Maker-checker (Authentication > User Role Permission). See UserRoleMakerChecker_DB_Changes.sql. /// The person's live roles of the subject's role type, and any change waiting for approval. UserRoleState GetRoleState(UserRoleSubject subject); /// Maker: records the wanted roles as pending requests. Returns how many requests were made. int RequestChange(UserRoleChangeRequest request, int makerID); /// Checker: makes the subject's pending requests live (creates the login first if needed). void Approve(UserRoleSubject subject, int approverID); /// Checker: drops the subject's pending requests; live roles stay as they were. void Reject(UserRoleSubject subject, int approverID); /// Every request waiting for approval, of everyone, with names for display. List GetPending(); } #endregion #region User role maker-checker /// What a UserRoleRequest asks for. public enum EnumUserRoleRequestType { Add = 1, Remove = 2, } /// /// Whose roles: an Admin user (RoleType Admin, UserID) or a Self Service employee /// (RoleType Self_Service, EmployeeID + PayrollTypeID; UserID only once the employee has a login). /// public class UserRoleSubject { public EnumRoleType RoleType { get; set; } public int? UserID { get; set; } public int? EmployeeID { get; set; } public int? PayrollTypeID { get; set; } } /// Maker's request: the roles (of the subject's role type) the person should have. public class UserRoleChangeRequest : UserRoleSubject { public UserRoleChangeRequest() { RoleIDs = new List(); } public List RoleIDs { get; set; } } /// /// One UserRole row as the maker-checker screens show it (not a table of its own). A row waiting for /// approval is a request: UserRole.Status 2 = give the role (RequestType Add, maker = CreatedBy), /// Status 3 = take it away (RequestType Remove, maker = ModifiedBy). ID is the UserRoleID. /// public class UserRoleRequest : BasicBaseObject { public UserRoleRequest() { Status = EnumAuthStatus.NewNotYetApprove; } public EnumUserRoleRequestType RequestType { get; set; } public int RoleID { get; set; } public EnumRoleType RoleType { get; set; } public int? UserID { get; set; } public int? EmployeeID { get; set; } public int? PayrollTypeID { get; set; } /// NewNotYetApprove (2) = waiting, Approved (5), Rejected (10). public EnumAuthStatus Status { get; set; } public int? ApprovedBy { get; set; } public DateTime? ApprovedDate { get; set; } // Not database properties: filled for display. public string RoleName { get; set; } public string LoginID { get; set; } public string PersonName { get; set; } public string EmployeeNo { get; set; } public string MakerLoginID { get; set; } } /// A person's roles of one role type, as the User Role Permission page shows them. public class UserRoleState { public UserRoleState() { LiveRoleIDs = new List(); Pending = new List(); } public EnumRoleType RoleType { get; set; } public int? UserID { get; set; } public int? EmployeeID { get; set; } /// Self Service: the employee's payroll type. public int? PayrollTypeID { get; set; } public string LoginID { get; set; } public string PersonName { get; set; } /// False for a Self Service employee who has no login yet (one is made when a change is sent). public bool HasLogin { get; set; } /// The login was made for a change still waiting for approval (Users.Status 2): it cannot sign in yet. public bool LoginWaiting { get; set; } /// Roles of this role type the person has now (live). public List LiveRoleIDs { get; set; } /// Requests waiting for approval. public List Pending { get; set; } } #endregion }