EchoTex_Payroll/HRM.DA/Service/Letter/OrganizationService.cs

158 lines
5.5 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
namespace HRM.DA
{
#region Letter Organization Service
public class OrganizationService : ServiceTemplate, IOrganizationService
{
public OrganizationService() { }
private void MapObject(Organization oLetterOrganization, DataReader oReader)
{
base.SetObjectID(oLetterOrganization, oReader.GetInt32("ORGANIZATIONID").Value);
oLetterOrganization.Name = oReader.GetString("Name", string.Empty);
oLetterOrganization.Code = oReader.GetString("Code", string.Empty);
oLetterOrganization.Address = oReader.GetString("Address", string.Empty);
oLetterOrganization.AddressLine2 = oReader.GetString("AddressLine2", string.Empty);
oLetterOrganization.AddressLine3 = oReader.GetString("AddressLine3", string.Empty);
oLetterOrganization.OrganizationType = oReader.GetInt16("ORGANIZATIONTYPE") != null ? (EnumLetterOrganizationType)oReader.GetInt32("ORGANIZATIONTYPE").Value : EnumLetterOrganizationType.Embassy;
// oLetterOrganization.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
//oLetterOrganization.CreatedDate = oReader.GetString("CreationDate") != null ? oReader.GetDateTime("CreationDate").Value : DateTime.Now;
oLetterOrganization.RecipeintDesignation = oReader.GetString("RECIPIENTDESIGNATION", string.Empty);
//oLetterOrganization.ModifiedBy = oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
//oLetterOrganization.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oLetterOrganization.CountryId = oReader.GetInt32("Country",0);
this.SetObjectState(oLetterOrganization, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Organization oLetterOrganization = new Organization();
MapObject(oLetterOrganization, oReader);
return oLetterOrganization as T;
}
#region Service implementation
public Organization Get(int id)
{
Organization oLetterOrganization = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OrganizationDA.Get(tc, id));
if (oreader.Read())
{
oLetterOrganization = this.CreateObject<Organization>(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 oLetterOrganization;
}
public List<Organization> Get(EnumStatus status)
{
List<Organization> LetterOrganizations = new List<Organization>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OrganizationDA.Get(tc));
LetterOrganizations = this.CreateObjects<Organization>(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
}
return LetterOrganizations;
}
public int Save(Organization oLetterOrganization)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLetterOrganization.IsNew)
{
int id = tc.GenerateID("Organization", "ORGANIZATIONID");
base.SetObjectID(oLetterOrganization, id);
OrganizationDA.Insert(tc, oLetterOrganization);
}
else
{
OrganizationDA.Update(tc, oLetterOrganization);
}
tc.End();
return oLetterOrganization.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(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OrganizationDA.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
}