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(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(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 Get() { #region Complain List List complains = new List(); //if (complains != null) // return complains; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComplainDA.Get(tc)); complains = this.CreateObjects(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 Get(EnumStatus status) { List complains = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComplainDA.Get(tc, status)); complains = this.CreateObjects(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 GetDAComplainPicker(int complainid) { List Complains = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComplainDA.GetDAComplainPicker(tc, complainid)); Complains = this.CreateObjects(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 }