using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.DataAccess; using Ease.CoreV35; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class PMSReviewService : ServiceTemplate { #region Object Mapping private void MapObject(PMSReview oObjective, DataReader oReader) { SetObjectID(oObjective, oReader.GetInt32("PMSReviewID").Value); oObjective.EmployeeID = oReader.GetInt32("EmployeeID", 0); oObjective.CTC = oReader.GetDouble("CTC").Value; oObjective.PreviousRating = oReader.GetString("PreviousRating"); oObjective.CurrentRating = oReader.GetString("CurrentRating", string.Empty); oObjective.IncrementPercent = oReader.GetDouble("IncrementPercent").Value; oObjective.CashBonus = oReader.GetDouble("CashBonus").Value; oObjective.Promotion = oReader.GetBoolean("Promotion").Value; oObjective.NewGradeID = oReader.GetInt32("NewGradeID", 0); oObjective.COLA = oReader.GetDouble("COLA").Value; oObjective.MeritIcrement = oReader.GetDouble("MeritIcrement").Value; oObjective.PositionIncrement = oReader.GetDouble("PositionIncrement").Value; oObjective.MarketAdjusment = oReader.GetDouble("MarketAdjusment").Value; oObjective.TotalIncrement = oReader.GetDouble("TotalIncrement").Value; oObjective.BonusAmount = oReader.GetDouble("BonusAmount").Value; oObjective.LTIAPercent = oReader.GetDouble("LTIAPercent").Value; oObjective.LTIATK = oReader.GetDouble("LTIATK").Value; oObjective.NewBasic = oReader.GetDouble("NewBasic").Value; oObjective.NewGross = oReader.GetDouble("NewGross").Value; oObjective.NewCTC = oReader.GetDouble("NewCTC").Value; oObjective.PMSProcessID = oReader.GetInt32("PMSProcessID", 0); oObjective.CreatedBy = oReader.GetInt32("CreatedBy", 0); oObjective.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oObjective.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oObjective.ModifiedDate = oReader.GetDateTime("ModifiedDate") == null ? null : oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oObjective, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PMSReview oPMSReview = new PMSReview(); MapObject(oPMSReview, oReader); return oPMSReview as T; } #endregion #region IObjectiveService Members #region Get All public List Get() { List oPMSReview = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMSReviewDA.Get(tc)); oPMSReview = 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 oPMSReview; } #endregion #region Get By ID public PMSReview Get(int id) { PMSReview oPMSReview = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMSReviewDA.Get(tc, id)); if (oreader.Read()) { oPMSReview = 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 oPMSReview; } public PMSReview Get(int empid, int pmpyearid) { PMSReview oPMSReview = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMSReviewDA.Get(tc, empid, pmpyearid)); if (oreader.Read()) { oPMSReview = 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 oPMSReview; } #endregion public int Save(PMSReview oPMSReview) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPMSReview.IsNew) { int id = tc.GenerateID("PMSReview", "PMSReviewID"); base.SetObjectID(oPMSReview, id); PMSReviewDA.Insert(tc, oPMSReview); } else { PMSReviewDA.Update(tc, oPMSReview); } tc.End(); return oPMSReview.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Upload(List oPMSReviews) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); var groupedItems = oPMSReviews.GroupBy(x => x.PMSProcessID).Select(g => new { PMSProcessID = g.Key, EmployeeIDs = g.Aggregate(new StringBuilder(), (sb, y) => sb.AppendFormat("{0},", y.EmployeeID), sbn => sbn.ToString().Trim(',')) }); foreach (var groupItem in groupedItems) { PMSReviewDA.Delete(tc, groupItem.PMSProcessID, groupItem.EmployeeIDs); } int id = tc.GenerateID("PMSReview", "PMSReviewID"); foreach (var oPMSReview in oPMSReviews) { base.SetObjectID(oPMSReview, id); PMSReviewDA.Insert(tc, oPMSReview); id++; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMSReviewDA.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 } }