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

247 lines
6.7 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.Core;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using System.Collections.Generic;
using HRM.BO;
using Ease.Core.Utility;
namespace HRM.DA
{
#region Complain Service
[Serializable]
public class ComplainService :ServiceTemplate , IComplainService
{
public ComplainService() { }
private void MapObject(Complain oComplain, DataReader oReader)
{
base.SetObjectID(oComplain, oReader.GetInt32("ComplainID").Value);
oComplain.Code = oReader.GetString("code");
oComplain.Description = oReader.GetString("Description");
this.SetObjectState(oComplain, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
Complain oComplain = new Complain();
MapObject(oComplain, oReader);
return oComplain as T;
}
protected Complain CreateObject(DataReader oReader)
{
Complain oComplain = new Complain();
MapObject(oComplain, oReader);
return oComplain;
}
#region Service implementation
public Complain Get(int id)
{
Complain oComplain = new Complain();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ComplainDA.Get(tc, id));
if (oreader.Read())
{
oComplain = this.CreateObject<Complain>(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 oComplain;
}
public List<Complain> Get()
{
#region Complain List
List<Complain> complains = new List<Complain>();
//if (complains != null)
// return complains;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComplainDA.Get(tc));
complains = this.CreateObjects<Complain>(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(religions, "Get");
#endregion*/
return complains;
}
public List<Complain> Get(EnumStatus status)
{
List<Complain> complains = new List<Complain>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComplainDA.Get(tc, status));
complains = this.CreateObjects<Complain>(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 complains;
}
public List<Complain> GetDAComplainPicker(int complainid)
{
List<Complain> Complains = new List<Complain>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComplainDA.GetDAComplainPicker(tc, complainid));
Complains = this.CreateObjects<Complain>(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 Complains;
}
public DataSet GetAllComplain(int empId)
{
DataSet dsetDSB = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dsetDSB = ComplainDA.GetAllComplain(tc, empId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dsetDSB;
}
public int Save(Complain oComplain)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oComplain.IsNew)
{
int id = tc.GenerateID("Complain", "ComplainID");
base.SetObjectID(oComplain, id);
ComplainDA.Insert(tc, oComplain);
}
else
{
ComplainDA.Update(tc, oComplain);
}
tc.End();
return oComplain.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);
ComplainDA.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
}