CEL_Payroll/Payroll.Service/Budget/Service/EmpAppraisalRatingService.cs
2024-09-17 14:30:13 +06:00

221 lines
6.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35;
namespace Payroll.Service
{
public class EmpAppraisalRatingService : ServiceTemplate, IEmpAppraisalRatingService
{
#region Object Mapping
private void MapObject(EmpAppraisalRating oEmpAppraisalRating, DataReader oReader)
{
SetObjectID(oEmpAppraisalRating, oReader.GetID("EmpAppraislRatingID"));
oEmpAppraisalRating.AppraisalPointRatingID = oReader.GetID("AppraisalPointRatingID");
if (oReader.GetDateTime("AppraisalYear") != null)
{
oEmpAppraisalRating.AppraisalYear = (DateTime)oReader.GetDateTime("AppraisalYear");
}
else
{
oEmpAppraisalRating.AppraisalYear = DateTime.MinValue;
}
oEmpAppraisalRating.EmployeeID = ((oReader.GetID("EmployeeID") == null) ? null : oReader.GetID("EmployeeID"));
if (oReader.GetString("CreatedBy") != null)
{
oEmpAppraisalRating.CreatedBy = oReader.GetID("CreatedBy");
}
else oEmpAppraisalRating.CreatedBy = null;
if (oReader.GetString("ModifiedBy") != null)
{
oEmpAppraisalRating.ModifiedBy = oReader.GetID("ModifiedBy");
}
else oEmpAppraisalRating.ModifiedBy = null;
if (oReader.GetDateTime("CreationDate") != null)
{
oEmpAppraisalRating.CreatedDate = (DateTime)oReader.GetDateTime("CreationDate");
}
else
{
oEmpAppraisalRating.CreatedDate = DateTime.MinValue;
}
if (oReader.GetDateTime("ModifiedDate") != null)
{
oEmpAppraisalRating.ModifiedDate = (DateTime)oReader.GetDateTime("ModifiedDate");
}
else
{
oEmpAppraisalRating.ModifiedDate = DateTime.MinValue;
}
this.SetObjectState(oEmpAppraisalRating, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
EmpAppraisalRating oEmpAppraisalRating = new EmpAppraisalRating();
MapObject(oEmpAppraisalRating, oReader);
return oEmpAppraisalRating as T;
}
#endregion
#region Service Implementation
public ObjectsTemplate<EmpAppraisalRating> Get(DateTime appraisalyear)
{
ObjectsTemplate<EmpAppraisalRating> oEmpAppraisalRating = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(EmpAppraisalRatingDA.Get(tc, appraisalyear));
oEmpAppraisalRating = this.CreateObjects<EmpAppraisalRating>(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 oEmpAppraisalRating;
}
public ID Save(EmpAppraisalRating item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("EmpAppraisalRating", "EmpAppraislRatingID");
int sNo = tc.GenerateID("EmpAppraisalRating", "Sequence");
SetObjectID(item, ID.FromInteger(id));
EmpAppraisalRatingDA.Insert(tc, item);
}
else
{
EmpAppraisalRatingDA.Update(tc, item);
}
tc.End();
return item.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(ObjectsTemplate<EmpAppraisalRating> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (EmpAppraisalRating item in items)
{
EmpAppraisalRatingDA.DeleteByEmpIdAndYear(tc,item);
//if (item.IsNew)
//{
// int id = tc.GenerateID("EmpAppraisalRating", "EmpAppraislRatingID");
// SetObjectID(item, ID.FromInteger(id));
// EmpAppraisalRatingDA.Insert(tc, item);
//}
//else
//{
// EmpAppraisalRatingDA.Update(tc, item);
//}
int id = tc.GenerateID("EmpAppraisalRating", "EmpAppraislRatingID");
SetObjectID(item, ID.FromInteger(id));
EmpAppraisalRatingDA.Insert(tc, item);
}
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(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmpAppraisalRatingDA.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
}
}
public void Update(EmpAppraisalRating item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
EmpAppraisalRatingDA.Update(tc, item);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}