EchoTex_Payroll/HRM.DA/Service/Users/RolePermissionService.cs

422 lines
12 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using HRM.BO;
namespace HRM.DA
{
public class RolePermissionService : ServiceTemplate
{
public RolePermissionService()
{
}
private void MapObject(Role.RolePermission oRolePermission, DataReader oReader)
{
base.SetObjectID(oRolePermission, oReader.GetInt32("RolePermissionID", 0));
oRolePermission.RoleID = oReader.GetInt32("roleID", 0);
oRolePermission.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oRolePermission.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oRolePermission.PermissionCode = oReader.GetString("PermissionCode");
oRolePermission.Name = oReader.GetString("Name");
oRolePermission.Link = oReader.GetString("Link");
oRolePermission.Status = (EnumAuthStatus)oReader.GetInt32("AuthStatus");
oRolePermission.ApproveBy = oReader.GetInt32("ApproveBy").Value;
oRolePermission.ApproveDate = oReader.GetDateTime("ApproveDate").Value;
oRolePermission.ModifiedBy = oReader.GetInt32("ModifiedBy").Value;
oRolePermission.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value;
this.SetObjectState(oRolePermission, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Role.RolePermission oRolePermission = new Role.RolePermission();
MapObject(oRolePermission, oReader);
return oRolePermission as T;
}
#region Service implementation
public Role.RolePermission Get(int id)
{
Role.RolePermission oRolePermission = new Role.RolePermission();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(RolePermissionDA.Get(tc, id));
if (oreader.Read())
{
oRolePermission = this.CreateObject<Role.RolePermission>(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 oRolePermission;
}
public List<Role.RolePermission> Get()
{
List<Role.RolePermission> rolePermissions = new List<Role.RolePermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RolePermissionDA.Get(tc));
rolePermissions = this.CreateObjects<Role.RolePermission>(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 rolePermissions;
}
//public RolePermission Get(string sKey, int RoleID)
//{
// RolePermission oRolePermission = null;
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader oreader = new DataReader(RolePermissionDA.Get(tc, sKey, RoleID));
// if (oreader.Read())
// {
// oRolePermission = this.CreateObject<RolePermission>(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 oRolePermission;
//}
public List<Role.RolePermission> GetByRoleID(int roleID)
{
List<Role.RolePermission> rolePermissions = new List<Role.RolePermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RolePermissionDA.Get(tc, roleID));
rolePermissions = this.CreateObjects<Role.RolePermission>(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 rolePermissions;
}
public DataSet GetRolePerAudit(int type, DateTime fromDate, DateTime ToDate)
{
DataSet rolePer = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
rolePer = RolePermissionDA.GetRolePerAudit(tc, type, fromDate, ToDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return rolePer;
}
public List<Role.RolePermission> GetAll(int roleID)
{
List<Role.RolePermission> rolePermissions = new List<Role.RolePermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RolePermissionDA.GetAll(tc, roleID));
rolePermissions = this.CreateObjects<Role.RolePermission>(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 rolePermissions;
}
public List<Role.RolePermission> GetAllItem(int roleID)
{
List<Role.RolePermission> rolePermissions = new List<Role.RolePermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RolePermissionDA.GetAllItem(tc, roleID));
rolePermissions = this.CreateObjects<Role.RolePermission>(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 rolePermissions;
}
public List<Role.RolePermission> Get(int roleID, EnumAuthStatus eStatus)
{
List<Role.RolePermission> rolePermissions = new List<Role.RolePermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RolePermissionDA.Get(tc, roleID, eStatus));
rolePermissions = this.CreateObjects<Role.RolePermission>(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 rolePermissions;
}
public int Save(Role.RolePermission oRolePermission)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRolePermission.IsNew)
{
int id = tc.GenerateID("RolePermission", "RolePermissionID");
base.SetObjectID(oRolePermission, id);
RolePermissionDA.Insert(tc, oRolePermission);
}
else
{
RolePermissionDA.Update(tc, oRolePermission);
}
tc.End();
return oRolePermission.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByRoleID(int nRoleID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
RolePermissionDA.DeleteByRoleID(tc, nRoleID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(List<Role.RolePermission> _RolePermissions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//RolePermissionDA.DeleteByRoleID(tc, _RolePermissions[0].RoleID);
foreach (Role.RolePermission permission in _RolePermissions)
{
//if (permission.IsNew)
//{
int id = tc.GenerateID("RolePermission", "RolePermissionID");
base.SetObjectID(permission, id);
RolePermissionDA.Insert(tc, permission);
//}
//tc.ExecuteNonQuery("Update UserRole set status=%n,createdby=%n where roleid=%n",(int)EnumStatus.Inactive,Payroll.BO.User.CurrentUser.ID.Integer, _RolePermissions[0].RoleID.Integer);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Update(List<Role.RolePermission> _RolePermissions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (Role.RolePermission permission in _RolePermissions)
{
RolePermissionDA.Update(tc, permission);
}
tc.End();
}
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);
RolePermissionDA.Delete(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
}
}