HRM-10/HRM.BO/User/UserRole.cs
2026-11-17 12:32:27 +06:00

178 lines
6.6 KiB
C#

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<Role.RolePermission>();
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<Role.RolePermission> 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<UserRole> Get(EnumRoleType roleType, int?userid, int?roleID);
List<UserRole> Get(List<SearchEmployee> searhEmps);
List<UserRole> GetByUserID(int UserID);
DataSet GetRoleAudit(int type, DateTime fromDate, DateTime ToDate);
DataTable GetUserMenuByRole(string roleId);
void Save(List<UserRole> userRoles, int payrolltypeid);
void Delete(int id);
// Maker-checker (Authentication > User Role Permission). See UserRoleMakerChecker_DB_Changes.sql.
/// <summary>The person's live roles of the subject's role type, and any change waiting for approval.</summary>
UserRoleState GetRoleState(UserRoleSubject subject);
/// <summary>Maker: records the wanted roles as pending requests. Returns how many requests were made.</summary>
int RequestChange(UserRoleChangeRequest request, int makerID);
/// <summary>Checker: makes the subject's pending requests live (creates the login first if needed).</summary>
void Approve(UserRoleSubject subject, int approverID);
/// <summary>Checker: drops the subject's pending requests; live roles stay as they were.</summary>
void Reject(UserRoleSubject subject, int approverID);
/// <summary>Every request waiting for approval, of everyone, with names for display.</summary>
List<UserRoleRequest> GetPending();
}
#endregion
#region User role maker-checker
/// <summary>What a UserRoleRequest asks for.</summary>
public enum EnumUserRoleRequestType
{
Add = 1,
Remove = 2,
}
/// <summary>
/// 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).
/// </summary>
public class UserRoleSubject
{
public EnumRoleType RoleType { get; set; }
public int? UserID { get; set; }
public int? EmployeeID { get; set; }
public int? PayrollTypeID { get; set; }
}
/// <summary>Maker's request: the roles (of the subject's role type) the person should have.</summary>
public class UserRoleChangeRequest : UserRoleSubject
{
public UserRoleChangeRequest()
{
RoleIDs = new List<int>();
}
public List<int> RoleIDs { get; set; }
}
/// <summary>
/// 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.
/// </summary>
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; }
/// <summary>NewNotYetApprove (2) = waiting, Approved (5), Rejected (10).</summary>
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; }
}
/// <summary>A person's roles of one role type, as the User Role Permission page shows them.</summary>
public class UserRoleState
{
public UserRoleState()
{
LiveRoleIDs = new List<int>();
Pending = new List<UserRoleRequest>();
}
public EnumRoleType RoleType { get; set; }
public int? UserID { get; set; }
public int? EmployeeID { get; set; }
/// <summary>Self Service: the employee's payroll type.</summary>
public int? PayrollTypeID { get; set; }
public string LoginID { get; set; }
public string PersonName { get; set; }
/// <summary>False for a Self Service employee who has no login yet (one is made when a change is sent).</summary>
public bool HasLogin { get; set; }
/// <summary>The login was made for a change still waiting for approval (Users.Status 2): it cannot sign in yet.</summary>
public bool LoginWaiting { get; set; }
/// <summary>Roles of this role type the person has now (live).</summary>
public List<int> LiveRoleIDs { get; set; }
/// <summary>Requests waiting for approval.</summary>
public List<UserRoleRequest> Pending { get; set; }
}
#endregion
}