207 lines
6.0 KiB
C#
207 lines
6.0 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.Caching;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
#region SAPDesignationCode Service
|
|
[Serializable]
|
|
public class SAPDesignationCodeService : ServiceTemplate, ISAPDesignationCodeService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(SAPDesignationCodeService));
|
|
#endregion
|
|
|
|
#region Object Mapping
|
|
|
|
private void MapObject(SAPDesignationCode oSAPDesignationCode, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oSAPDesignationCode, oReader.GetID("SAPDesignationCodeID"));
|
|
oSAPDesignationCode.DesignationID = oReader.GetID("DesignationID");
|
|
oSAPDesignationCode.SAPCode = oReader.GetString("SAPCode");
|
|
this.SetObjectState(oSAPDesignationCode, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
SAPDesignationCode oSAPDesignationCode = new SAPDesignationCode();
|
|
MapObject(oSAPDesignationCode, oReader);
|
|
return oSAPDesignationCode as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public ObjectsTemplate<SAPDesignationCode> Get(ID designationID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<SAPDesignationCode> sAPDesignationCodes = _cache["Get",designationID] as ObjectsTemplate<SAPDesignationCode>;
|
|
if (sAPDesignationCodes != null)
|
|
return sAPDesignationCodes;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(SAPDesignationCodeDA.Get(tc,designationID));
|
|
sAPDesignationCodes = this.CreateObjects<SAPDesignationCode>(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
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(sAPDesignationCodes, "Get",designationID);
|
|
|
|
#endregion
|
|
|
|
return sAPDesignationCodes;
|
|
}
|
|
|
|
public ObjectsTemplate<SAPDesignationCode> Get(TransactionContext tc,ID designationID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<SAPDesignationCode> sAPDesignationCodes = _cache["Get", designationID] as ObjectsTemplate<SAPDesignationCode>;
|
|
if (sAPDesignationCodes != null)
|
|
return sAPDesignationCodes;
|
|
|
|
#endregion
|
|
|
|
try
|
|
{
|
|
DataReader dr = new DataReader(SAPDesignationCodeDA.Get(tc, designationID));
|
|
sAPDesignationCodes = this.CreateObjects<SAPDesignationCode>(dr);
|
|
dr.Close();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(sAPDesignationCodes, "Get", designationID);
|
|
|
|
#endregion
|
|
|
|
return sAPDesignationCodes;
|
|
}
|
|
|
|
public ID Save(SAPDesignationCode oSAPDesignationCode)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oSAPDesignationCode.IsNew)
|
|
{
|
|
int id = tc.GenerateID("SAPDesignationCode", "SAPDesignationCodeID");
|
|
base.SetObjectID(oSAPDesignationCode, ID.FromInteger(id));
|
|
SAPDesignationCodeDA.Insert(tc, oSAPDesignationCode);
|
|
}
|
|
else
|
|
{
|
|
SAPDesignationCodeDA.Update(tc, oSAPDesignationCode);
|
|
}
|
|
tc.End();
|
|
return oSAPDesignationCode.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(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
SAPDesignationCodeDA.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 bool SAPCodeExists(string sapCode, out string sDesigName)
|
|
{
|
|
TransactionContext tc = null;
|
|
bool isExists; string sDName;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
isExists = SAPDesignationCodeDA.SapCodeExists(tc, sapCode, out sDName);
|
|
sDesigName = sDName;
|
|
return isExists;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
finally
|
|
{
|
|
if (tc != null)
|
|
tc.End();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|