EchoTex_Payroll/HRM.DA/Service/Users/RoleActionPermissionService.cs
2024-10-14 10:01:49 +06:00

287 lines
8.8 KiB
C#

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 RoleActionPermissionService : ServiceTemplate
{
public RoleActionPermissionService()
{
}
private void MapObject(Role.RoleActionPermission oRolePermission, DataReader oReader)
{
base.SetObjectID(oRolePermission, oReader.GetInt32("RoleActionPermissionID", 0));
oRolePermission.RoleID = oReader.GetInt32("RoleID", 0);
oRolePermission.RolePermissionID = oReader.GetInt32("RolePermissionID", 0);
oRolePermission.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oRolePermission.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oRolePermission.ActionCode = oReader.GetString("PermissionCode");
oRolePermission.Name = oReader.GetString("Name");
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.RoleActionPermission oRolePermission = new Role.RoleActionPermission();
MapObject(oRolePermission, oReader);
return oRolePermission as T;
}
#region Service implementation
public Role.RoleActionPermission Get(int id)
{
Role.RoleActionPermission oRolePermission = new Role.RoleActionPermission();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(RoleActionPermissionDA.Get(tc, id));
if (oreader.Read())
{
oRolePermission = this.CreateObject<Role.RoleActionPermission>(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.RoleActionPermission> Get()
{
List<Role.RoleActionPermission> rolePermissions = new List<Role.RoleActionPermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RoleActionPermissionDA.Get(tc));
rolePermissions = this.CreateObjects<Role.RoleActionPermission>(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.RoleActionPermission> Get(EnumAuthStatus eStatus)
{
List<Role.RoleActionPermission> rolePermissions = new List<Role.RoleActionPermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RoleActionPermissionDA.Get(tc, eStatus));
rolePermissions = this.CreateObjects<Role.RoleActionPermission>(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.RoleActionPermission> Get(int roleID, EnumAuthStatus eStatus)
{
List<Role.RoleActionPermission> rolePermissions = new List<Role.RoleActionPermission>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RoleActionPermissionDA.Get(tc, roleID, eStatus));
rolePermissions = this.CreateObjects<Role.RoleActionPermission>(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.RoleActionPermission oRolePermission)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRolePermission.IsNew)
{
int id = tc.GenerateID("RoleActionPermission", "RoleActionPermissionID");
base.SetObjectID(oRolePermission, id);
RoleActionPermissionDA.Insert(tc, oRolePermission);
}
else
{
RoleActionPermissionDA.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 Save(List<Role.RoleActionPermission> _RolePermissions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//RoleActionPermissionDA.DeleteByRoleID(tc, _RolePermissions[0].RoleID);
foreach (Role.RoleActionPermission permission in _RolePermissions)
{
//if (permission.IsNew)
//{
int id = tc.GenerateID("RoleActionPermission", "RoleActionPermissionID");
base.SetObjectID(permission, id);
RoleActionPermissionDA.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.RoleActionPermission> _RolePermissions)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (Role.RoleActionPermission permission in _RolePermissions)
{
RoleActionPermissionDA.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);
RoleActionPermissionDA.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
}
}