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

207 lines
6.1 KiB
C#

using System;
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 AssesmentValueDetailsService : ServiceTemplate, IAssesmentValueDetailsService
{
#region Object Mapping
private void MapObject(AssesmentValueDetails oAssesmentValueDetails, DataReader oReader)
{
SetObjectID(oAssesmentValueDetails, oReader.GetInt32("AssesmentValueDetailsID", 0));
oAssesmentValueDetails.ValueID = oReader.GetInt32("AssesmentValueID", 0);
oAssesmentValueDetails.Description = oReader.GetString("Description");
oAssesmentValueDetails.Status = (EnumStatus)oReader.GetInt32("Status");
oAssesmentValueDetails.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oAssesmentValueDetails.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
? oReader.GetDateTime("CreatedDate").Value
: DateTime.MinValue;
oAssesmentValueDetails.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oAssesmentValueDetails.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(oAssesmentValueDetails, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AssesmentValueDetails oAssesmentValueDetails = new AssesmentValueDetails();
MapObject(oAssesmentValueDetails, oReader);
return oAssesmentValueDetails as T;
}
#endregion
#region Service Implementation
#region Get By ValueID
public List<AssesmentValueDetails> GetWithValue(int ValueID)
{
List<AssesmentValueDetails> oAssesmentValueDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssesmentValueDetailsDA.Get(tc, ValueID));
oAssesmentValueDetails = this.CreateObjects<AssesmentValueDetails>(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 oAssesmentValueDetails;
}
#endregion
#region Get By ID
public AssesmentValueDetails Get(int id)
{
AssesmentValueDetails oAssesmentValueDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssesmentValueDetailsDA.Get(tc, id));
oAssesmentValueDetails = this.CreateObject<AssesmentValueDetails>(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
}
//if (oAssesmentValueDetails.Count == 1) return oAssesmentValueDetails[0];
//else return null;
return oAssesmentValueDetails;
}
#endregion
#region Get By Status
public List<AssesmentValueDetails> Get(EnumStatus status)
{
List<AssesmentValueDetails> oAssesmentValueDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AssesmentValueDetailsDA.Get(tc, status));
oAssesmentValueDetails = this.CreateObjects<AssesmentValueDetails>(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 oAssesmentValueDetails;
}
#endregion
#region Insert
public int Save(AssesmentValueDetails item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("AssesmentValueDetails", "AssesmentValueDetailsID");
base.SetObjectID(item, (id));
AssesmentValueDetailsDA.Insert(tc, item);
}
else
{
AssesmentValueDetailsDA.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
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
AssesmentValueDetailsDA.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
#endregion
}
}