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 PMPRatingService : ServiceTemplate, IPMPRatingService { #region Object Mapping private void MapObject(PMPRating oPMPRating, DataReader oReader) { SetObjectID(oPMPRating, oReader.GetInt32("PMPRatingID", 0)); oPMPRating.Name = oReader.GetString("PMPRatingName"); oPMPRating.Description = oReader.GetString("PMPRatingDescription"); oPMPRating.PMPYearId = oReader.GetInt32("PMPYearId", 0); oPMPRating.PMPRatingType = (EnumPMPRatingType)oReader.GetInt32("PMPRatingType").Value; //oPMPRating.BellCurveType = (EnumBellCurveType)oReader.GetInt32("BellCurveType").Value; oPMPRating.BellCurveType = oReader.GetInt32("BellCurveType").HasValue ? (EnumBellCurveType)oReader.GetInt32("BellCurveType").Value : (EnumBellCurveType?)null; oPMPRating.HeadCount = oReader.GetDouble("HeadCount").HasValue ? oReader.GetDouble("HeadCount").Value : null; oPMPRating.IncrementPercent = oReader.GetDouble("IncrementPercent", 0); oPMPRating.FromPercent = oReader.GetDouble("FromPercent", 0); oPMPRating.ToPercent = oReader.GetDouble("ToPercent", 0); oPMPRating.RatingValue = oReader.GetDouble("PMPRatingvalue", 0); oPMPRating.CreatedBy = oReader.GetInt32("CreatedBy", 0); oPMPRating.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.MinValue; oPMPRating.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oPMPRating.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; oPMPRating.Status = (EnumStatus)oReader.GetInt32("Status"); oPMPRating.Sequence = (int)oReader.GetInt32("Sequence"); this.SetObjectState(oPMPRating, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PMPRating oPMPRating = new PMPRating(); MapObject(oPMPRating, oReader); return oPMPRating as T; } #endregion #region Service Implementation #region GetAll By Status public List Get(EnumStatus status) { List oPMPRating = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPRatingDA.Get(tc, status)); oPMPRating = 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 oPMPRating; } #endregion #region Delete By ID public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMPRatingDA.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 #region Insert public int Save(PMPRating oPMPRating) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPMPRating.IsNew) { int id = tc.GenerateID("PMP_Rating", "PMPRatingID"); int sequenceNo = tc.GenerateID("PMP_Rating", "Sequence"); oPMPRating.Sequence = sequenceNo; base.SetObjectID(oPMPRating, (id)); PMPRatingDA.Insert(tc, oPMPRating); } else { PMPRatingDA.Update(tc, oPMPRating); } tc.End(); return oPMPRating.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Get By Id public PMPRating GetById(int id) { PMPRating oPMPRating = null; List allRatings; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPRatingDA.GetById(tc, id)); allRatings = 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 } oPMPRating = allRatings[0]; return oPMPRating; } #endregion #region Get By Type And Year public List GetPMPRatingByTypeAndYear(EnumPMPRatingType type, int pmpYearId) { List oPMPRating = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPRatingDA.GetPMPRatingByTypeAndYear(tc, type, pmpYearId)); oPMPRating = 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 oPMPRating; } #endregion #endregion } }