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

186 lines
6.4 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 MarketSurveyCompany Service
[Serializable]
public class MarketSurveyCompanyService : ServiceTemplate, IMarketSurveyCompanyService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(MarketSurveyCompany));
#endregion
public MarketSurveyCompanyService() { }
private void MapObject(MarketSurveyCompany oMarketSurveyCompany, DataReader oReader)
{
//oMarketSurveyCompany.ID = oReader.GetID("MarketSurveyCompanyID");
base.SetObjectID(oMarketSurveyCompany, oReader.GetID("MarketSurveyCompanyID"));
oMarketSurveyCompany.Code = oReader.GetString("Code");
oMarketSurveyCompany.Name = oReader.GetString("Name");
oMarketSurveyCompany.Address = oReader.GetString("Address");
oMarketSurveyCompany.CreatedBy = oReader.GetID("CreatedBy");
oMarketSurveyCompany.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oMarketSurveyCompany.ModifiedBy = oReader.GetID("ModifiedBy");
oMarketSurveyCompany.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oMarketSurveyCompany.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oMarketSurveyCompany.Sequence = oReader.GetInt32("SequenceNO").Value;
this.SetObjectState(oMarketSurveyCompany,Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
MarketSurveyCompany oMarketSurveyCompany = new MarketSurveyCompany();
MapObject(oMarketSurveyCompany, oReader);
return oMarketSurveyCompany as T;
}
protected MarketSurveyCompany CreateObject(DataReader oReader)
{
MarketSurveyCompany oMarketSurveyCompany = new MarketSurveyCompany();
MapObject(oMarketSurveyCompany, oReader);
return oMarketSurveyCompany;
}
#region Service implementation
public MarketSurveyCompany Get(ID id)
{
MarketSurveyCompany oMarketSurveyCompany = new MarketSurveyCompany();
#region Cache Header
oMarketSurveyCompany = _cache["Get", id] as MarketSurveyCompany;
if (oMarketSurveyCompany != null)
return oMarketSurveyCompany;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(MarketSurveyCompanyDA.Get(tc, id));
if (oreader.Read())
{
oMarketSurveyCompany = this.CreateObject<MarketSurveyCompany>(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
}
#region Cache Footer
_cache.Add(oMarketSurveyCompany, "Get", id);
#endregion
return oMarketSurveyCompany;
}
public ObjectsTemplate<MarketSurveyCompany> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<MarketSurveyCompany> MarketSurveyCompanys = _cache["Get",status] as ObjectsTemplate<MarketSurveyCompany>;
if (MarketSurveyCompanys != null)
return MarketSurveyCompanys;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(MarketSurveyCompanyDA.Get(tc,status));
MarketSurveyCompanys = this.CreateObjects<MarketSurveyCompany>(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(MarketSurveyCompanys, "Get",status);
#endregion
return MarketSurveyCompanys;
}
public ID Save(MarketSurveyCompany oMarketSurveyCompany)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oMarketSurveyCompany.IsNew)
{
int id = tc.GenerateID("MarketSurveyCompany", "MarketSurveyCompanyID");
base.SetObjectID(oMarketSurveyCompany, ID.FromInteger(id));
int seqNo = tc.GenerateID("MarketSurveyCompany", "SequenceNO");
oMarketSurveyCompany.Sequence = seqNo;
MarketSurveyCompanyDA.Insert(tc, oMarketSurveyCompany);
}
else
{
MarketSurveyCompanyDA.Update(tc, oMarketSurveyCompany);
}
tc.End();
return oMarketSurveyCompany.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);
MarketSurveyCompanyDA.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
}