using System; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Payroll.BO; namespace Payroll.Service { #region Training Service [Serializable] class TrainingScheduleAttnService : ServiceTemplate, ITrainingScheduleAttnService { #region Private functions and declaration Cache _cache = new Cache(typeof(TrainingScheduleAttn)); private void MapObject(TrainingScheduleAttn oTrainingScheduleAttn, DataReader oReader) { base.SetObjectID(oTrainingScheduleAttn, oReader.GetID("TSAttnID")); oTrainingScheduleAttn.TrainingScheduleID = oReader.GetID("TrainingScheduleID"); oTrainingScheduleAttn.TSDateID = oReader.GetID("TSDateID"); oTrainingScheduleAttn.EmployeeID = oReader.GetID("EmployeeID"); this.SetObjectState(oTrainingScheduleAttn, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TrainingScheduleAttn oTrainingScheduleAttng = new TrainingScheduleAttn(); MapObject(oTrainingScheduleAttng, oReader); return oTrainingScheduleAttng as T; } #endregion #region Implementation of ITrainingScheduleAttnService #region Get TrainingScheduleAttn public TrainingScheduleAttn Get(ID trainingScheduleAttnID) { TrainingScheduleAttn otrainingScheduleAttn = null; #region CacheHeader otrainingScheduleAttn = (TrainingScheduleAttn)_cache["Get", trainingScheduleAttnID]; if (otrainingScheduleAttn != null) return otrainingScheduleAttn; #endregion TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingScheduleAttnDA.Get(tc, trainingScheduleAttnID.Integer)); oreader.Read(); otrainingScheduleAttn = CreateObject(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } #region CacheFooter _cache.Add(otrainingScheduleAttn, "Get", trainingScheduleAttnID); #endregion return otrainingScheduleAttn; } #endregion #region Get ObjectsTemplate public ObjectsTemplate Get() { ObjectsTemplate trainingScheduleAttns; #region CacheHeader trainingScheduleAttns = (ObjectsTemplate)_cache["Get"]; if (trainingScheduleAttns != null) return trainingScheduleAttns; #endregion TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingScheduleAttnDA.Get(tc)); trainingScheduleAttns = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } #region CacheFooter _cache.Add(trainingScheduleAttns, "Get"); #endregion return trainingScheduleAttns; } public ObjectsTemplate GetByTrainingScheduleID(ID trainingScheduleID) { ObjectsTemplate trainingScheduleAttns; #region CacheHeader trainingScheduleAttns = (ObjectsTemplate)_cache["Get"]; if (trainingScheduleAttns != null) return trainingScheduleAttns; #endregion TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingScheduleAttnDA.GetByTrainingScheduleID(tc, trainingScheduleID)); trainingScheduleAttns = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } #region CacheFooter _cache.Add(trainingScheduleAttns, "Get"); #endregion return trainingScheduleAttns; } public ObjectsTemplate GetByTrainingScheduleDateID(ID trainingScheduleDateID) { ObjectsTemplate trainingScheduleAttns; #region CacheHeader trainingScheduleAttns = (ObjectsTemplate)_cache["Get"]; if (trainingScheduleAttns != null) return trainingScheduleAttns; #endregion TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingScheduleAttnDA.GetByTrainingScheduleDateID(tc, trainingScheduleDateID)); trainingScheduleAttns = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } #region CacheFooter _cache.Add(trainingScheduleAttns, "Get"); #endregion return trainingScheduleAttns; } #endregion #region Save TrainingScheduleAttn public ID Save(TrainingScheduleAttn oTrainingScheduleAttn) { try { TransactionContext tc = null; try { #region Saving data tc = TransactionContext.Begin(true); if (oTrainingScheduleAttn.IsNew) { int newID = tc.GenerateID("TrainingScheduleAttn", "TSAttnID"); base.SetObjectID(oTrainingScheduleAttn, ID.FromInteger(newID)); TrainingScheduleAttnDA.Insert(tc, oTrainingScheduleAttn); } else TrainingScheduleAttnDA.Update(tc, oTrainingScheduleAttn); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { //throw new ServiceException(e.Message, e); throw new Exception(e.Message, e); } return oTrainingScheduleAttn.ID; } public ID Save(TransactionContext tc, TrainingScheduleAttn oTrainingScheduleAttn) { try { try { #region Saving data if (oTrainingScheduleAttn.IsNew) { int newID = tc.GenerateID("TrainingScheduleAttn", "TSAttnID"); base.SetObjectID(oTrainingScheduleAttn, ID.FromInteger(newID)); TrainingScheduleAttnDA.Insert(tc, oTrainingScheduleAttn); } else TrainingScheduleAttnDA.Update(tc, oTrainingScheduleAttn); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { //throw new ServiceException(e.Message, e); throw new Exception(e.Message, e); } return oTrainingScheduleAttn.ID; } #endregion #region Delete public void Delete(ID id) { try { TransactionContext tc = null; try { #region Deleting data tc = TransactionContext.Begin(true); TrainingScheduleAttnDA.Delete(tc, id.Integer); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { throw new ServiceException(e.Message, e); } } #endregion public bool DoesTrainingScheduleAttnExists(ID trainingScheduleDateID) { try { TransactionContext tc = null; tc = TransactionContext.Begin(); bool result = false; result = TrainingScheduleAttnDA.DoesTrainingScheduleAttnExists(tc,trainingScheduleDateID); tc.End(); return result; } catch (Exception e) { throw new Exception(e.Message, e); } } #endregion } #endregion }