using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.DataAccess; using System.Data; using Ease.CoreV35; namespace Payroll.Service { public class AppraisalPointService : ServiceTemplate, IAppraisalPointService { #region Object Mapping private void MapObject(AppraisalPoint oAppraisalPoint, DataReader oReader) { SetObjectID(oAppraisalPoint, oReader.GetID("AppraisalPointID")); oAppraisalPoint.Code = oReader.GetString("Code"); oAppraisalPoint.Name = oReader.GetString("Name"); oAppraisalPoint.Status = (EnumStatus)oReader.GetInt32("Status"); if (oReader.GetDateTime("CreatedDate") != null) { oAppraisalPoint.CreatedDate = (DateTime)oReader.GetDateTime("CreatedDate"); } else oAppraisalPoint.CreatedDate = DateTime.MinValue; if (oReader.GetDateTime("ModifiedDate") != null) { oAppraisalPoint.ModifiedDate = (DateTime)oReader.GetDateTime("ModifiedDate"); } else oAppraisalPoint.ModifiedDate = null; if (oReader.GetInt32("CreatedBy") != null) { oAppraisalPoint.CreatedBy = oReader.GetID("CreatedBy"); } else oAppraisalPoint.CreatedBy = null; if (oReader.GetInt32("ModifiedBy") != null) { oAppraisalPoint.ModifiedBy = oReader.GetID("ModifiedBy"); } else oAppraisalPoint.ModifiedBy = null; this.SetObjectState(oAppraisalPoint,ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { AppraisalPoint oAppraisalPoint = new AppraisalPoint(); MapObject(oAppraisalPoint, oReader); return oAppraisalPoint as T; } #endregion #region Service Implementation public ObjectsTemplate Get(EnumStatus status) { ObjectsTemplate oAppraisalPoint = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AppraisalPointDA.Get(tc, status)); oAppraisalPoint = 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 oAppraisalPoint; } public ID Save(AppraisalPoint item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("AppraisalPoint", "AppraisalPointID"); int seqNo = tc.GenerateID("AppraisalPoint", "Sequence"); item.Sequence = seqNo; SetObjectID(item, ID.FromInteger(id)); AppraisalPointDA.Insert(tc, item); } else { AppraisalPointDA.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 } } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AppraisalPointDA.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 } } public bool CheckCode(string code) { bool flag = true; DataSet ds = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ds = AppraisalPointDA.CheckCode(tc, code); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } if (ds.Tables[0].Rows.Count >= 1) { flag = false; } return flag; } #endregion } }