489 lines
15 KiB
C#
489 lines
15 KiB
C#
using HRM.BO;
|
|
using Ease.Core;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.DataAccess.SQL;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.SqlClient;
|
|
using System.Net;
|
|
using System.Threading;
|
|
using Azure.Core;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace HRM.DA
|
|
{
|
|
#region User Service
|
|
public class ErJobUserService : ServiceTemplate, IErJobUserService
|
|
{
|
|
private string _lastPasswords;
|
|
public ErJobUserService() { }
|
|
|
|
private void MapObject(ErJobUser oUser, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oUser, oReader.GetInt32("UserID").Value);
|
|
oUser.Email = oReader.GetString("Email");
|
|
oUser.UserName = oReader.GetString("userName");
|
|
oUser.Mobile = oReader.GetString("Mobile");
|
|
oUser.Password = oReader.GetString("password",null);
|
|
oUser.UserFrom = (EnumUserFrom)Convert.ToInt32(oReader.GetInt32("UserFrom"));
|
|
oUser.Password = oReader.GetString("Password",string.Empty);
|
|
oUser.IsActive = oReader.GetBoolean("IsActive",false);
|
|
oUser.InActiveDate = oReader.GetDateTime("InActiveDate",DateTime.MinValue);
|
|
oUser.InActiveReason = oReader.GetString("InActiveReason",string.Empty);
|
|
oUser.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oUser.IsCVCompleted = oReader.GetBoolean("isCVCompleted", true,false);
|
|
this.SetObjectState(oUser, Ease.Core.ObjectState.Saved);
|
|
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
ErJobUser oUser = new ErJobUser();
|
|
MapObject(oUser, oReader);
|
|
return oUser as T;
|
|
}
|
|
|
|
|
|
|
|
#region Service implementation
|
|
|
|
//public List<User> Get(string LoginID, string Name, EnumUserType type)
|
|
//{
|
|
// TransactionContext tc = null;
|
|
// List<User> users = new List<User>();
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
// DataReader dr = new DataReader(UserDA.Get(tc, LoginID, Name, type));
|
|
// users = this.CreateObjects<User>(dr);
|
|
// dr.Close();
|
|
|
|
// tc.End();
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
|
|
// throw new ServiceException(e.Message, e);
|
|
|
|
// #endregion
|
|
// }
|
|
|
|
// return users;
|
|
//}
|
|
|
|
public List<ErJobUser> GetAll()
|
|
{
|
|
TransactionContext tc = null;
|
|
List<ErJobUser> users = new List<ErJobUser>();
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(ErJobUserDA.Get(tc));
|
|
users = this.CreateObjects<ErJobUser>(dr);
|
|
dr.Close();
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return users;
|
|
}
|
|
|
|
|
|
public ErJobUser Get(int userid)
|
|
{
|
|
ErJobUser oUser = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ErJobUserDA.Get(tc, userid));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<ErJobUser>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
return oUser;
|
|
}
|
|
|
|
#region PPIC SPECIFIC
|
|
public ErJobUser Get(string email)
|
|
{
|
|
ErJobUser oUser = null;
|
|
|
|
TransactionContext tc = null;
|
|
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ErJobUserDA.GetByLoginIDByEmail(tc, email));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<ErJobUser>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
return oUser;
|
|
}
|
|
|
|
public ErJobUser CheckEmailMobExist(string email,string mobile)
|
|
{
|
|
ErJobUser oUser = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ErJobUserDA.checkIfEmailOrMobileNoExist(tc, email, mobile));
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<ErJobUser>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
|
|
return oUser;
|
|
}
|
|
|
|
public ErJobUser GetByLoginIDAndPassword(string sLoginID, string sPassword)
|
|
{
|
|
ErJobUser oUser = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ErJobUserDA.GetByLoginIDAndPassword(tc, sLoginID, sPassword));
|
|
|
|
if (oreader.Read())
|
|
{
|
|
oUser = this.CreateObject<ErJobUser>(oreader);
|
|
}
|
|
oreader.Close();
|
|
tc.End();
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
|
|
return oUser;
|
|
}
|
|
|
|
#region PasswordHistories
|
|
|
|
public string CheckPasswordHistory(string password, string lastPasswords, bool checkPassword, bool esp, bool dalp, short ndap)
|
|
{
|
|
string value = string.Empty;
|
|
if (checkPassword)
|
|
{
|
|
_lastPasswords = lastPasswords;
|
|
if (esp && !Global.StringFuncions.IsStrongPassword(password))
|
|
value = "Password must be at least 8 letters and have uppper & lower case letters and numbers.";
|
|
|
|
password = Global.CipherFunctions.EncryptByTDS(password);
|
|
if (dalp && actualPasswordHistories(dalp, ndap).Contains(password))
|
|
value = string.Format("You cannot use this password, because it was used in last {0} passwords.", ndap);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
void CheckPasswordHistory(string password, bool esp, bool dalp, short ndap)
|
|
{
|
|
try
|
|
{
|
|
string tmpPassword = Global.CipherFunctions.DecryptByTDS(password);
|
|
if (esp && !Global.StringFuncions.IsStrongPassword(tmpPassword))
|
|
throw new Exception("Password must be at least 8 letters and have uppper & lower case letters and numbers.");
|
|
|
|
if (dalp && actualPasswordHistories(dalp, ndap).Contains(password))
|
|
throw new Exception(string.Format("You cannot use this password, because it was used in last {0} passwords.", ndap));
|
|
|
|
if (passwordHistories.Count >= 5)
|
|
passwordHistories.Dequeue();
|
|
|
|
passwordHistories.Enqueue(password);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new Exception(e.Message, e);
|
|
}
|
|
}
|
|
|
|
void makePasswordHistory()
|
|
{
|
|
string[] phs = passwordHistories.ToArray();
|
|
if (phs.Length > 0)
|
|
_lastPasswords = string.Join(",", phs);
|
|
}
|
|
|
|
private Queue<string> _phs;
|
|
Queue<string> passwordHistories
|
|
{
|
|
get
|
|
{
|
|
if (_phs == null)
|
|
{
|
|
_phs = new Queue<string>();
|
|
if (!string.IsNullOrWhiteSpace(_lastPasswords))
|
|
{
|
|
string[] passwords = _lastPasswords.Split(',');
|
|
foreach (string item in passwords)
|
|
{
|
|
if (!_phs.Contains(item))
|
|
_phs.Enqueue(item);
|
|
}
|
|
}
|
|
}
|
|
return _phs;
|
|
}
|
|
}
|
|
|
|
List<string> actualPasswordHistories(bool dalp, short ndap)
|
|
{
|
|
List<string> pwds = new List<string>();
|
|
string[] pwdsHists = passwordHistories.ToArray();
|
|
if (dalp && ndap > 0 && pwdsHists.Length > 0)
|
|
{
|
|
for (int idx = pwdsHists.Length - 1; idx >= 0; idx--)
|
|
{
|
|
if (!pwds.Contains(pwdsHists[idx]) && pwds.Count < ndap)
|
|
pwds.Add(pwdsHists[idx]);
|
|
}
|
|
}
|
|
return pwds;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
//public User GetByLogINID(string sName, EnumSystemType eSysType)
|
|
//{
|
|
// User oUser = null;
|
|
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
// DataReader oreader = new DataReader(UserDA.GetByLogInID(tc, sName, eSysType));
|
|
// if (oreader.Read())
|
|
// {
|
|
// oUser = this.CreateObject<User>(oreader);
|
|
// }
|
|
// oreader.Close();
|
|
// tc.End();
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
// throw new ServiceException(e.Message, e);
|
|
// #endregion
|
|
// }
|
|
|
|
// return oUser;
|
|
//}
|
|
|
|
//public User Get(int employeeid, EnumUserType type)
|
|
//{
|
|
// User oUser = null;
|
|
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
// DataReader oreader = new DataReader(UserDA.Get(tc, employeeid, type));
|
|
// if (oreader.Read())
|
|
// {
|
|
// oUser = this.CreateObject<User>(oreader);
|
|
// }
|
|
// oreader.Close();
|
|
// tc.End();
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
// throw new ServiceException(e.Message, e);
|
|
// #endregion
|
|
// }
|
|
|
|
// return oUser;
|
|
//}
|
|
|
|
//public ErJobUser GetByEmailAndPassword(string email, string sPassword)
|
|
//{
|
|
// ErJobUser oUser = null;
|
|
|
|
// TransactionContext tc = null;
|
|
// try
|
|
// {
|
|
// tc = TransactionContext.Begin();
|
|
// DataReader oreader = new DataReader(ErJobUserDA.GetByEmailAndPassword(tc, email, sPassword));
|
|
// if (oreader.Read())
|
|
// {
|
|
// oUser = this.CreateObject<User>(oreader);
|
|
// }
|
|
// oreader.Close();
|
|
// tc.End();
|
|
|
|
// if (oUser !=null)
|
|
// {
|
|
// UserLogInInfo login = new UserLogInInfo();
|
|
// login.UserID = oUser.ID;
|
|
// login.LoginTime = DateTime.Now;
|
|
// login.PCNumber = Environment.MachineName + " ," +
|
|
// System.Net.Dns.GetHostName() + " ," +
|
|
// Environment.GetEnvironmentVariable("COMPUTERNAME");
|
|
// Thread myNewThread = new Thread(() => SaveLoginfo(login));
|
|
// myNewThread.Start();
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
// catch (Exception e)
|
|
// {
|
|
// #region Handle Exception
|
|
// if (tc != null)
|
|
// tc.HandleError();
|
|
// ExceptionLog.Write(e);
|
|
// throw new ServiceException(e.Message, e);
|
|
// #endregion
|
|
// }
|
|
|
|
// return oUser;
|
|
//}
|
|
|
|
|
|
public int Save(ErJobUser oUser)
|
|
{
|
|
TransactionContext tc = null;
|
|
int id = 0;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
id = this.Save(tc, oUser);
|
|
tc.End();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
return id;
|
|
}
|
|
|
|
|
|
|
|
public int Save(TransactionContext tc, ErJobUser oUser)
|
|
{
|
|
try
|
|
{
|
|
//oUser.Password = Ease.Core.Utility.Global.CipherFunctions.Encrypt("CeLiMiTeD.AdMIn", oUser.Password);
|
|
if (oUser.IsNew)
|
|
{
|
|
int id = tc.GenerateID("ERJOBUSER", "USERID");
|
|
base.SetObjectID(oUser, id);
|
|
ErJobUserDA.Insert(tc, oUser);
|
|
}
|
|
else
|
|
{
|
|
ErJobUserDA.Update(tc, oUser);
|
|
}
|
|
return oUser.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
UserDA.Delete(tc, id);
|
|
UserRoleDA.DeleteByUserID(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
#endregion
|
|
}
|