using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class ObjectiveCategoryGradesService : ServiceTemplate, IObjectiveCategoryGradesService { #region Object Mapping private void MapObject(ObjectiveCategoryGrades oObjectiveCategoryGrades, DataReader oReader) { SetObjectID(oObjectiveCategoryGrades, oReader.GetInt32("ObjectiveCategoryGradesID", 0)); oObjectiveCategoryGrades.ObjectiveType = oReader.GetInt32("ObjectiveType").Value; oObjectiveCategoryGrades.ObjectiveCategoryID = oReader.GetInt32("ObjectiveCategoryID", 0); oObjectiveCategoryGrades.GradeID = oReader.GetInt32("GradeID", 0); //(oReader.GetInt32("GradeID").Value); oObjectiveCategoryGrades.Tier = oReader.GetInt32("Tier").Value; oObjectiveCategoryGrades.Percent = oReader.GetDouble("Percent").Value == 0.0 ? 0.0 : oReader.GetDouble("Percent").Value; oObjectiveCategoryGrades.OBMOSRequired = oReader.GetBoolean("OBMOSRequired").Value; oObjectiveCategoryGrades.DPMOSRequired = oReader.GetBoolean("DPMOSRequired").Value; this.SetObjectState(oObjectiveCategoryGrades, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ObjectiveCategoryGrades oObjectiveCategoryGrades = new ObjectiveCategoryGrades(); MapObject(oObjectiveCategoryGrades, oReader); return oObjectiveCategoryGrades as T; } #endregion #region IObjectiveCategoryGradesService Members #region Get All public List Get() { List oObjectiveCategoryGrades = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.Get(tc)); oObjectiveCategoryGrades = 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 oObjectiveCategoryGrades; } public List Get(int nPmpyearID, int nCategory) { List oObjectiveCategoryGrades = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.Get(tc, nPmpyearID, nCategory)); oObjectiveCategoryGrades = 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 oObjectiveCategoryGrades; } public List GetByPMPYear(int nPmpyearID) { List oObjectiveCategoryGrades = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.GetByPMPYear(tc, nPmpyearID)); oObjectiveCategoryGrades = 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 oObjectiveCategoryGrades; } public List GetByGradeId(int gradeId, int pmpYearId) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.GetByGradeId(tc, gradeId, pmpYearId)); items = 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 items; } public List GetByEmpTier(int empID, int nPmpyearID) { List oObjectiveCategoryGrades = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.GetByEmpTier(tc, empID, nPmpyearID)); oObjectiveCategoryGrades = 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 oObjectiveCategoryGrades; } #endregion #region Get By ID public ObjectiveCategoryGrades Get(int id) { ObjectiveCategoryGrades oObjectiveCategoryGrades = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveCategoryGradesDA.Get(tc, id)); oObjectiveCategoryGrades = 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 oObjectiveCategoryGrades; } #endregion #region Insert public int Save(ObjectiveCategoryGrades item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("ObjectiveCategoryGrades", "ObjectiveCategoryGradesID"); base.SetObjectID(item, (id)); ObjectiveCategoryGradesDA.Save(tc, item); } else { ObjectiveCategoryGradesDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectiveCategoryGradesDA.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 } }