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 { #region BonusAdjustItem Service public class BonusAdjustItemService : ServiceTemplate, IBonusAdjustItemService { public BonusAdjustItemService() { } private void MapObject(BonusAdjustItem oBonusAdjustItem, DataReader oReader) { base.SetObjectID(oBonusAdjustItem, (oReader.GetInt32("BonusAdjustItemID").Value)); oBonusAdjustItem.Code = oReader.GetString("code"); oBonusAdjustItem.Name = oReader.GetString("name"); oBonusAdjustItem.Side = (EnumSide)oReader.GetInt32("side").Value; oBonusAdjustItem.Amount = oReader.GetDouble("Amount").Value; oBonusAdjustItem.Sequence = oReader.GetInt32("SequenceNo").Value; oBonusAdjustItem.Status = (EnumStatus)oReader.GetInt32("Status").Value; oBonusAdjustItem.CreatedBy = oReader.GetInt32("CreatedBy", 0); oBonusAdjustItem.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.MinValue; oBonusAdjustItem.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oBonusAdjustItem.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; this.SetObjectState(oBonusAdjustItem, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); MapObject(oBonusAdjustItem, oReader); return oBonusAdjustItem as T; } protected BonusAdjustItem CreateObject(DataReader oReader) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); MapObject(oBonusAdjustItem, oReader); return oBonusAdjustItem; } #region Service implementation public BonusAdjustItem Get(int id) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(BonusAdjustItemDA.Get(tc, id)); if (oreader.Read()) { oBonusAdjustItem = 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 oBonusAdjustItem; } public List Get(EnumStatus status) { List bonusAdjustItems = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusAdjustItemDA.Get(tc, status)); bonusAdjustItems = this.CreateObjects(dr); dr.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 bonusAdjustItems; } public int Save(BonusAdjustItem oBonusAdjustItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBonusAdjustItem.IsNew) { int id = tc.GenerateID("BonusAdjustItem", "BonusAdjustItemID"); base.SetObjectID(oBonusAdjustItem, (id)); int seqNo = tc.GenerateID("BonusAdjustItem", "SequenceNo"); oBonusAdjustItem.Sequence = seqNo; BonusAdjustItemDA.Insert(tc, oBonusAdjustItem); } else { BonusAdjustItemDA.Update(tc, oBonusAdjustItem); } tc.End(); return oBonusAdjustItem.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(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); BonusAdjustItemDA.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 }