EchoTex_Payroll/HRM.DA/Service/RewardStatement/RewardStatementParameterService.cs

299 lines
11 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class RewardStatementParameterService : ServiceTemplate, IRewardStatementParameterService
{
#region Constructor
public RewardStatementParameterService()
{
}
#endregion
#region MapObjects
private void MapObject(RewardStatementParameter oRewardStatementParameter, DataReader oReader)
{
base.SetObjectID(oRewardStatementParameter, (oReader.GetInt32("RewardStatementParameterID").Value));
oRewardStatementParameter.FlatAmount = oReader.GetDouble("FlatAmount").GetValueOrDefault();
oRewardStatementParameter.BasicAmount = oReader.GetDouble("BasicAmount").GetValueOrDefault();
oRewardStatementParameter.GCAmount = oReader.GetDouble("GCAmount").GetValueOrDefault();
oRewardStatementParameter.RewardStatementID = (oReader.GetInt32("RewardStatementID").Value);
oRewardStatementParameter.IsIndividual = oReader.GetBoolean("IsIndividual").Value;
oRewardStatementParameter.Gender = (EnumGender)oReader.GetInt32("Gender").Value;
oRewardStatementParameter.TopTeam = (EnumTopTeam)oReader.GetInt32("TopTeam").Value;
oRewardStatementParameter.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oRewardStatementParameter.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
? oReader.GetDateTime("CreatedDate").Value
: DateTime.MinValue;
oRewardStatementParameter.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oRewardStatementParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(oRewardStatementParameter, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
RewardStatementParameter oRewardStatementParameter = new RewardStatementParameter();
MapObject(oRewardStatementParameter, oReader);
return oRewardStatementParameter as T;
}
#endregion
#region MapRewardStatementParameterDetail
private void MapRewardStatementParameterDetailObject(
RewardStatementParameterDetail oRewardStatementParameterDetail, DataReader oReader)
{
base.SetObjectID(oRewardStatementParameterDetail, (oReader.GetInt32("RSParameterDetailID").Value));
oRewardStatementParameterDetail.RewardStatementParameterID =
oReader.GetInt32("RewardStatementParameterID", 0);
oRewardStatementParameterDetail.GradeLocationType =
(EnumGradeLocationType)oReader.GetInt32("GradeDepartmentType").Value;
;
oRewardStatementParameterDetail.GradeLocationID = oReader.GetInt32("GradeDepartmentID", 0);
this.SetObjectState(oRewardStatementParameterDetail, Ease.Core.ObjectState.Saved);
}
private RewardStatementParameterDetail CreateRecognitionDetailObject(DataReader oReader)
{
RewardStatementParameterDetail oRewardStatementParameterDetail = new RewardStatementParameterDetail();
MapRewardStatementParameterDetailObject(oRewardStatementParameterDetail, oReader);
return oRewardStatementParameterDetail;
}
#endregion
#region Recognition Service Methods
public RewardStatementParameter Get(int id)
{
RewardStatementParameter oRewardStatementParameter = new RewardStatementParameter();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(RewardStatementParameterDA.Get(tc, id));
if (oreader.Read())
{
oRewardStatementParameter = this.CreateObject<RewardStatementParameter>(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 oRewardStatementParameter;
}
public List<RewardStatementParameter> Get()
{
List<RewardStatementParameter> oRewardStatementParameters = new List<RewardStatementParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RewardStatementParameterDA.Get(tc));
oRewardStatementParameters = this.CreateObjects<RewardStatementParameter>(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 oRewardStatementParameters;
}
public List<RewardStatementParameter> GetWithRewardStatement(int rewardStatementID)
{
List<RewardStatementParameter> rewardStatementParameters = new List<RewardStatementParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(RewardStatementParameterDA.Get(tc, rewardStatementID));
rewardStatementParameters = this.CreateObjects<RewardStatementParameter>(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 rewardStatementParameters;
}
public int Save(RewardStatementParameter oRewardStatementParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRewardStatementParameter.IsNew)
{
int id = tc.GenerateID("RewardStatementParameter", "RewardStatementParameterID");
base.SetObjectID(oRewardStatementParameter, (id));
RewardStatementParameterDA.Insert(tc, oRewardStatementParameter);
}
else
{
RewardStatementParameterDA.Update(tc, oRewardStatementParameter);
RewardStatementParameterDA.DeleteRewardStatementParameterDetail(tc, oRewardStatementParameter.ID);
RewardStatementParameterIndividualDA.DeletebyParamId(tc, oRewardStatementParameter.ID);
}
#region RewardStatementParameterDetail
foreach (RewardStatementParameterDetail item in oRewardStatementParameter
.RewardStatementParameterDetails)
{
int id = tc.GenerateID("RSParameterDetail", "RSParameterDetailID");
base.SetObjectID(item, (id));
item.RewardStatementParameterID = oRewardStatementParameter.ID;
RewardStatementParameterDA.InsertRewardStatementParameterDetail(tc, item);
}
#endregion
foreach (RewardStatementParameterIndividual rewIndv in oRewardStatementParameter
.RewardStatementParameterIndividuals)
{
rewIndv.RewardStatementParameterID = oRewardStatementParameter.ID;
int id = tc.GenerateID("RSParameterIndividual", "RSParameterIndividualID");
base.SetObjectID(rewIndv, (id));
RewardStatementParameterIndividualDA.Insert(tc, rewIndv);
}
tc.End();
return oRewardStatementParameter.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);
RewardStatementParameterDA.DeleteRewardStatementParameterDetail(tc, id);
RewardStatementParameterDA.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
#region RewardStatementParameterDetail Service Methods
public List<RewardStatementParameterDetail> GetRewardStatementParameterDetails(int rewardStatementParameterID)
{
List<RewardStatementParameterDetail> oRewardStatementParameterDetails =
new List<RewardStatementParameterDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr =
new DataReader(
RewardStatementParameterDA.GetRewardStatementParameterDetails(tc, rewardStatementParameterID));
while (dr.Read())
{
RewardStatementParameterDetail oRewardStatementParameterDetail =
new RewardStatementParameterDetail();
oRewardStatementParameterDetail = this.CreateRecognitionDetailObject(dr);
oRewardStatementParameterDetails.Add(oRewardStatementParameterDetail);
}
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 oRewardStatementParameterDetails;
}
#endregion
}
}