HRM-10/HRM.DA/Service/Basic/UserLogInInfoService.cs

310 lines
9.0 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using HRM.BO;
namespace HRM.DA
{
public class UserLogInInfoService : ServiceTemplate, IUserLogInInfoService
{
public UserLogInInfoService()
{
}
private void MapObject(UserLogInInfo oUserLogInInfo, DataReader oReader)
{
base.SetObjectID(oUserLogInInfo, oReader.GetInt32("SlID").Value);
oUserLogInInfo.UserID = oReader.GetInt32("UserID", 0);
oUserLogInInfo.LoginTime = oReader.GetDateTime("LoginTime").Value;
oUserLogInInfo.PCNumber = oReader.GetString("PCNumber");
if (oReader.GetDateTime("LogoutTime") != null)
oUserLogInInfo.LogoutTime = Convert.ToDateTime(oReader.GetString("LogoutTime"));
oUserLogInInfo.LogoutType = oReader.GetString("LogoutType") == null
? EnumLogoutType.NotInitiate
: (EnumLogoutType)oReader.GetInt32("LogoutType").Value;
}
protected override T CreateObject<T>(DataReader oReader)
{
UserLogInInfo oUserLogInInfo = new UserLogInInfo();
MapObject(oUserLogInInfo, oReader);
return oUserLogInInfo as T;
}
#region Service implementation
public UserLogInInfo Get(int id)
{
UserLogInInfo oUserLogInInfo = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(UserLogInInfoDA.Get(tc, id));
if (oreader.Read())
{
oUserLogInInfo = this.CreateObject<UserLogInInfo>(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 oUserLogInInfo;
}
public List<UserLogInInfo> Get()
{
List<UserLogInInfo> UserLogInInfos = new List<UserLogInInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UserLogInInfoDA.Get(tc));
UserLogInInfos = this.CreateObjects<UserLogInInfo>(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 UserLogInInfos;
}
public List<UserLogInInfo> GetLoggedUsers()
{
List<UserLogInInfo> UserLogInInfos = new List<UserLogInInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UserLogInInfoDA.GetLoggedUsers(tc));
UserLogInInfos = this.CreateObjects<UserLogInInfo>(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 UserLogInInfos;
}
public List<UserLogInInfo> Get(string sLoginID)
{
List<UserLogInInfo> UserLogInInfos = new List<UserLogInInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UserLogInInfoDA.Get(tc, sLoginID));
UserLogInInfos = this.CreateObjects<UserLogInInfo>(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 UserLogInInfos;
}
public List<UserLogInInfo> GetLastLogin(string sLoginID, bool isWebLogin)
{
List<UserLogInInfo> UserLogInInfos = new List<UserLogInInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = null;
if (!isWebLogin)
dr = new DataReader(UserLogInInfoDA.GetLastLogin(tc, sLoginID));
else
dr = new DataReader(UserLogInInfoDA.GetLastWebLogin(tc, sLoginID));
UserLogInInfos = this.CreateObjects<UserLogInInfo>(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 UserLogInInfos;
}
public void UpdateLogoutTime(int nLoginID)
{
TransactionContext tc = null;
tc = TransactionContext.Begin();
UserLogInInfoDA.UpdateLogoutTime(tc, nLoginID);
tc.End();
}
public List<UserLogInInfo> Get(DateTime dtFrom, DateTime dtTo)
{
List<UserLogInInfo> UserLogInInfos = new List<UserLogInInfo>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UserLogInInfoDA.Get(tc, dtFrom, dtTo));
UserLogInInfos = this.CreateObjects<UserLogInInfo>(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 UserLogInInfos;
}
public long NoofLogin(int nUserID)
{
long nCount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
nCount = UserLogInInfoDA.NoofLogin(tc, nUserID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return nCount;
}
public int Save(UserLogInInfo oUserLogInInfo)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oUserLogInInfo.IsNew)
{
int id = tc.GenerateID("UserLoginInfo", "SlID");
base.SetObjectID(oUserLogInInfo, id);
UserLogInInfoDA.Insert(tc, oUserLogInInfo);
}
else
UserLogInInfoDA.Update(tc, oUserLogInInfo);
tc.End();
return oUserLogInInfo.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(TransactionContext tc, UserLogInInfo oUserLogInInfo)
{
try
{
if (oUserLogInInfo.IsNew)
{
UserLogInInfoDA.Insert(tc, oUserLogInInfo);
}
else UserLogInInfoDA.Update(tc, oUserLogInInfo);
return oUserLogInInfo.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)
{
//Not Needed
}
#endregion
}
}