265 lines
8.2 KiB
C#
265 lines
8.2 KiB
C#
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Model;
|
|
using Ease.Core.Utility;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
|
|
|
|
namespace Common.DA
|
|
{
|
|
public class RoleDesignationService : ServiceTemplate, IRoleDesignationService
|
|
{
|
|
public RoleDesignationService() { }
|
|
|
|
private void MapObject(RoleDesignation oRolePermission, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oRolePermission, oReader.GetInt32("RoleDesignationID", 0));
|
|
oRolePermission.RoleID = oReader.GetInt32("RoleID", 0);
|
|
oRolePermission.DesignationID = oReader.GetInt32("DesignationID", 0);
|
|
oRolePermission.CreatedBy = oReader.GetInt32("CreatedBy", 0);
|
|
oRolePermission.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|
oRolePermission.AuthStatus = (EnumAuthStatus)oReader.GetInt32("AuthStatus");
|
|
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)
|
|
{
|
|
RoleDesignation oRolePermission = new RoleDesignation();
|
|
MapObject(oRolePermission, oReader);
|
|
return oRolePermission as T;
|
|
}
|
|
|
|
#region Service implementation
|
|
public RoleDesignation Get(int id)
|
|
{
|
|
RoleDesignation oRolePermission = new RoleDesignation();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(RoleDesignationDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oRolePermission = this.CreateObject<RoleDesignation>(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<RoleDesignation> Get()
|
|
{
|
|
List<RoleDesignation> rolePermissions = new List<RoleDesignation>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(RoleDesignationDA.Get(tc));
|
|
rolePermissions = this.CreateObjects<RoleDesignation>(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<RoleDesignation> Get(EnumAuthStatus eStatus)
|
|
{
|
|
List<RoleDesignation> rolePermissions = new List<RoleDesignation>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(RoleDesignationDA.Get(tc, eStatus));
|
|
rolePermissions = this.CreateObjects<RoleDesignation>(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<RoleDesignation> Get(int roleID, EnumAuthStatus eStatus)
|
|
{
|
|
List<RoleDesignation> rolePermissions = new List<RoleDesignation>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(RoleDesignationDA.Get(tc, roleID, eStatus));
|
|
rolePermissions = this.CreateObjects<RoleDesignation>(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(RoleDesignation oRolePermission)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oRolePermission.IsNew)
|
|
{
|
|
int id = tc.GenerateID("PR_RoleDesignation", "RoleDesignationID");
|
|
base.SetObjectID(oRolePermission, id);
|
|
RoleDesignationDA.Insert(tc, oRolePermission);
|
|
}
|
|
else
|
|
{
|
|
RoleDesignationDA.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.RoleDesignation> _RolePermissions)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
//RoleDesignationDA.DeleteByRoleID(tc, _RolePermissions[0].RoleID);
|
|
foreach (RoleDesignation permission in _RolePermissions)
|
|
{
|
|
//if (permission.IsNew)
|
|
//{
|
|
int id = tc.GenerateID("PR_RoleDesignation", "RoleDesignationID");
|
|
base.SetObjectID(permission, id);
|
|
RoleDesignationDA.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<RoleDesignation> _RolePermissions)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
foreach (RoleDesignation permission in _RolePermissions)
|
|
{
|
|
RoleDesignationDA.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);
|
|
RoleDesignationDA.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
|
|
|
|
}
|
|
}
|