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 Complain Service [Serializable] public class ComplainService : ServiceTemplate, IComplainService { #region Private functions and declaration Cache _cache = new Cache(typeof(Complain)); #endregion public ComplainService() { } private void MapObject(Complain oComplain, DataReader oReader) { base.SetObjectID(oComplain, oReader.GetID("ComplainID")); oComplain.Code = oReader.GetString("code"); oComplain.Description = oReader.GetString("Description"); this.SetObjectState(oComplain, Ease.CoreV35.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(ID id) { Complain oComplain = new Complain(); #region Cache Header oComplain = _cache["Get", id] as Complain; if (oComplain != null) return oComplain; #endregion 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 } #region Cache Footer _cache.Add(oComplain, "Get", id); #endregion return oComplain; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate religions = _cache["Get"] as ObjectsTemplate; if (religions != null) return religions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComplainDA.Get(tc)); religions = 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 religions; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate religions = _cache["Get"] as ObjectsTemplate; if (religions != null) return religions; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ComplainDA.Get(tc, status)); religions = 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", status); #endregion return religions; } public ID Save(Complain oComplain) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oComplain.IsNew) { int id = tc.GenerateID("Complain", "ComplainID"); base.SetObjectID(oComplain, ID.FromInteger(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(ID 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 }