using System; using System.Collections.Generic; using System.Data; using Ease.Core; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class CalibrationAudianceService : ServiceTemplate { private void MapObject(CalibrationAudiance calibrationAudiance, DataReader dataReader) { SetObjectID(calibrationAudiance, dataReader.GetInt32("CalibrationAudianceId", 0)); calibrationAudiance.CalibrationId = dataReader.GetInt32("CalibrationId", 0); calibrationAudiance.EmployeeId = dataReader.GetInt32("EmployeeId", 0); this.SetObjectState(calibrationAudiance, ObjectState.Saved); } protected override T CreateObject(DataReader dr) { CalibrationAudiance calibrationAudiance = new CalibrationAudiance(); MapObject(calibrationAudiance, dr); return calibrationAudiance as T; } #region Service implementation public CalibrationAudiance Get(int id) { CalibrationAudiance oCalibrationAudiance = new CalibrationAudiance(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CalibrationAudianceDA.Get(tc, id)); if (oreader.Read()) { oCalibrationAudiance = 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 oCalibrationAudiance; } public List Get() { List oCalibrationAudiances = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CalibrationAudianceDA.Get(tc)); oCalibrationAudiances = this.CreateObjects(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 oCalibrationAudiances; } public int Save(CalibrationAudiance oCalibrationAudiance) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oCalibrationAudiance.IsNew) { int id = tc.GenerateID("CalibrationAudiance", "CalibrationAudianceID"); base.SetObjectID(oCalibrationAudiance, id); CalibrationAudianceDA.Insert(tc, oCalibrationAudiance); } else { CalibrationAudianceDA.Update(tc, oCalibrationAudiance); } tc.End(); return oCalibrationAudiance.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetCalibrationAudiance", e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); CalibrationAudianceDA.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 } }