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

168 lines
4.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35;
using Payroll.BO;
namespace Payroll.Service
{
public class PMPRatingService : ServiceTemplate, IPMPRatingService
{
#region Object Mapping
private void MapObject(PMPRating oPMPRating, DataReader oReader)
{
SetObjectID(oPMPRating, oReader.GetID("PMPRatingID"));
oPMPRating.Name = oReader.GetString("PMPRatingName");
oPMPRating.RatingValue = oReader.GetString("PMPRatingvalue");
oPMPRating.CreatedBy = oReader.GetID("CreadtedBy");
oPMPRating.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oPMPRating.ModifiedBy = oReader.GetID("ModifiedBy") == null ? null : oReader.GetID("ModifiedBy");
oPMPRating.ModifiedDate = oReader.GetDateTime("ModifiedDate") == null ? DateTime.MinValue : oReader.GetDateTime("ModifiedDate");
oPMPRating.Status = (EnumStatus)oReader.GetInt32("Status");
oPMPRating.Sequence = (int)oReader.GetInt32("Sequence");
this.SetObjectState(oPMPRating, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PMPRating oPMPRating = new PMPRating();
MapObject(oPMPRating, oReader);
return oPMPRating as T;
}
#endregion
#region Service Implementation
#region GetAll By Status
public ObjectsTemplate<PMPRating> Get(EnumStatus status)
{
ObjectsTemplate<PMPRating> oPMPRating = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPRatingDA.Get(tc, status));
oPMPRating = this.CreateObjects<PMPRating>(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 oPMPRating;
}
#endregion
#region Delete By ID
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PMPRatingDA.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 Save
public ID Save(PMPRating oPMPRating)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPMPRating.IsNew)
{
int id = tc.GenerateID("PMP_Rating", "PMPRatingID");
int sequenceNo = tc.GenerateID("PMP_Rating", "Sequence");
oPMPRating.Sequence = sequenceNo;
base.SetObjectID(oPMPRating, ID.FromInteger(id));
PMPRatingDA.Insert(tc, oPMPRating);
}
else
{
PMPRatingDA.Update(tc, oPMPRating);
}
tc.End();
return oPMPRating.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Get By Id
public PMPRating GetById(ID id)
{
PMPRating oPMPRating = null;
ObjectsTemplate<PMPRating> allRatings;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPRatingDA.GetById(tc, id));
allRatings = this.CreateObjects<PMPRating>(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
}
oPMPRating = allRatings[0];
return oPMPRating;
}
#endregion
#endregion
}
}