EchoTex_Payroll/HRM.BO/User/Users.cs

195 lines
6.9 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using Ease.Core.Model;
using System.Data;
using System.Security.Claims;
namespace HRM.BO
{
public class CurrentUser
{
public int UserID { get; set; }
public string LoginID { get; set; }
private int? _employeeID;
public int? EmployeeID
{
get
{
if (UserType == EnumUserType.Employee && this._employeeID == null)
{
throw new Exception("Employee-ID cann't be null, Self-service login");
}
return this._employeeID;
}
set { _employeeID = value; }
}
public string UserName { get; set; }
public int? PayrollTypeID { get; set; }
public DateTime? NextPayProcessDate { get; set; }
public DateTime? LastPayProcessDate { get; set; }
public int? TaxParamID {get;set;}
public string Description { get; set; }
public EnumUserType UserType { get; set; }
public bool hasDataPermission { get; set; }
public CurrentUser()
{
this.PayrollTypeID = null;
this.EmployeeID = null;
this.TaxParamID = null;
this.NextPayProcessDate = null;
this.hasDataPermission = false;
}
public static CurrentUser GetCurrentUser(ClaimsPrincipal principal)
{
if (principal == null || principal.Identity == null || principal.Identity.IsAuthenticated == false)
return null;
CurrentUser oUser = new CurrentUser();
foreach (Claim item in principal.Claims)
{
if (item.Type == "UserID")
oUser.UserID = Convert.ToInt32(item.Value);
if (item.Type == "UserName")
oUser.UserName = item.Value;
if (item.Type == "LoginID")
oUser.LoginID = item.Value;
if (item.Type == "UserType")
oUser.UserType =(EnumUserType) Convert.ToInt32( item.Value);
if (item.Type == "EmployeeID" && item.Value !="0")
oUser.EmployeeID = Convert.ToInt32(item.Value);
if (item.Type == "PayrollTypeID" && item.Value != "0")
oUser.PayrollTypeID = Convert.ToInt32(item.Value);
if (item.Type == "nextPayProcessDate" && item.Value != "null") {
oUser.NextPayProcessDate = Convert.ToDateTime(item.Value);
//oUser.LastPayProcessDate = oUser.LastPayProcessDate.Value.AddMonths(-1).LastDateOfMonth();
}
if (item.Type == "taxParamId" && item.Value != "null" && item.Value != string.Empty)
oUser.TaxParamID = Convert.ToInt32(item.Value);
if (item.Type == "hasDataPermission" && item.Value != "null" && item.Value != string.Empty)
oUser.hasDataPermission = Convert.ToBoolean(item.Value);
}
return oUser;
}
}
public partial class User : BasicBaseObject
{
public User()
{
this.PasswordHints = "";
this.NeverExpire = false;
this.EmployeeID = null;
this.ChangePasswordAtNextLogon = true;
this.LastPasswordChangedDate = null;
this.IPAddress = "";
this.MacAddress = "";
this.ComputerName = "";
}
public void Logout()
{
}
public string LoginID { get; set; }
public bool NeverExpire { get; set; }
public string MacAddress { get; set; }
public string IPAddress { get; set; }
public string UserRole { get; set; }
//public string Password { get; set; }
private string _password;
public string Password
{
// get { return Ease.Core.Utility.Global.CipherFunctions.Decrypt("CeLiMiTeD.AdMIn", _password); }
get { return _password; }
set { _password = value; }
}
public bool ResetPassword { get; set; }
public bool ChangePasswordAtNextLogon { get; set; }
public DateTime? LastPasswordChangedDate { get; set; }
public string PasswordHints { get; set; }
public DateTime? ExpireDate { get; set; }
public bool IsPasswordExpired // not a database filed
{
get
{
if (ExpireDate.HasValue)
return DateTime.Today.Date > ExpireDate.Value;
return false;
}
}
public int? EmployeeID { get; set; }
public string Email { get; set; } //erec
#region Payroll Specific
public string UserName { get; set; }
public string? ComputerName { get; set; }
public EnumAuthStatus UserStatus { get; set; }
public int ParentID { get; set; }
public bool SISU{ get; set; }
public EnumUserType UserType { get; set; }
public int LogInPayrollTypeID { get; set; } // Not a database field
public int? ApprovedBy { get; set; }
public DateTime? ApprovedDate { get; set; }
public string? ApprovedComputerName { get; set; }
public string LockedWorkStation { get; set; }
public string Reason { get; set; }
public int? AuthorizedBy { get; set; }
public DateTime? AuthorizedDate { get; set; }
public List<UserAccessType> UserAccessTypes { get; set; }
public List<UserRole> Roles { get; set; }
#endregion
}
#region IUser Service
public interface IUserService
{
User GetByLoginIDAndPassword(string LoginID, string password);
User GetByLoginIDAndPasswordAndHostName(string LoginID, string password, string hostName);
int Save(User item);
List<User> Get(string LoginID, string Name, EnumUserType type);
List<User> GetAll();
bool IsSuperUser(string LoginID);
void ChangePasswordEss(User oUser);
void ChangePasswordAdmin(User oUser);
DateTime GetEndofContractDate(string LoginID);
User Get(int employeeid, EnumUserType type);
User Get(int id);
User GetByEmail(string email);
//User Get(string sName);
User GetByLogINID(string sLogINID, EnumSystemType eSysType);
//User GetByLoginIDAndPassword(string sLoginID, string sPassword, EnumSystemType eSysType);
User ADLogIn(string emailAddress, EnumSystemType eSysType);
//List<User> Get(EnumSystemType type);
//List<User> Get();
//void Delete(int id);
void Update(User user, EnumStatus status);
void Approve(User user);
int GetUserId(int employeeid, EnumUserType type);
User GetByLoginIDbyEmail(string sEmail);
void DoActiveAndIntacive(User oUser);
//void SaveAllUsers(List<User> oUsers);
//DataSet GetUsers(EnumSystemType type, DateTime fromDate, DateTime ToDate);
}
#endregion
}