using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using System; using System.Collections.Generic; namespace HRM.DA { public class TrainingNeedAnalysisHistoryService : ServiceTemplate, ITrainingNeedAnalysisHistoryService { #region Constructor public TrainingNeedAnalysisHistoryService() { } #endregion #region Map Object private void MapObject(TrainingNeedAnalysisHistory oItem, DataReader oReader) { base.SetObjectID(oItem, oReader.GetInt32("ID").Value); oItem.UserID = oReader.GetInt32("UserID").GetValueOrDefault(); oItem.EmpID = oReader.GetInt32("EmpID").GetValueOrDefault(); oItem.EmpType = oReader.GetInt32("EmpType").HasValue ? (EnumPMPActorType)oReader.GetInt32("EmpType").Value : (EnumPMPActorType?)null; oItem.UpdateDate = oReader.GetDateTime("UpdateDate").HasValue ? oReader.GetDateTime("UpdateDate").Value : (DateTime?)null; oItem.ColumnName = oReader.GetString("ColumnName", true, string.Empty); oItem.OldValue = oReader.GetString("OldValue", true, string.Empty); oItem.NewValue = oReader.GetString("NewValue", true, string.Empty); oItem.Remarks = oReader.GetString("Remarks", true, string.Empty); oItem.Version = oReader.GetInt32("Version").HasValue ? oReader.GetInt32("Version").Value : (int?)null; this.SetObjectState(oItem, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TrainingNeedAnalysisHistory oItem = new TrainingNeedAnalysisHistory(); MapObject(oItem, oReader); return oItem as T; } #endregion #region Service implementation public TrainingNeedAnalysisHistory Get(int ID) { TrainingNeedAnalysisHistory oItem = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(TrainingNeedAnalysisHistoryDA.Get(tc, ID)); if (oReader.Read()) { oItem = this.CreateObject(oReader); } oReader.Close(); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } return oItem; } public List Get() { List list = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(TrainingNeedAnalysisHistoryDA.Get(tc)); list = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } return list; } public List GetAll() { return Get(); } public int Save(TrainingNeedAnalysisHistory oItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oItem.IsNew) { int id = tc.GenerateID("TrainingNeedAnalysisHistory", "ID"); base.SetObjectID(oItem, id); TrainingNeedAnalysisHistoryDA.Insert(tc, oItem); } else { TrainingNeedAnalysisHistoryDA.Update(tc, oItem); } tc.End(); return oItem.ID; } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); TrainingNeedAnalysisHistoryDA.Delete(tc, id); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } #endregion } }