using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Data; using System.Linq; using HRM.BO; using HRM.DA; namespace HRM.BO { #region UserRecord Service [Serializable] public class UserRecordService : ServiceTemplate, IUserRecordService { #region Private functions and declaration public UserRecordService() { } private void MapObject(UserRecord oUserRecord, DataReader oReader) { this.SetObjectID(oUserRecord, oReader.GetInt32("UserRecordID").Value); oUserRecord.UserObjectID = oReader.GetInt32("UserObjectID").Value; oUserRecord.PositionNo = oReader.GetInt32("PositionNo").Value; oUserRecord.Field1 = oReader.GetString("Field1"); oUserRecord.Field1LastValue = oReader.GetString("Field1"); oUserRecord.Field2 = oReader.GetString("Field2"); oUserRecord.Field3 = oReader.GetString("Field3"); oUserRecord.Field4 = oReader.GetString("Field4"); oUserRecord.Field5 = oReader.GetString("Field5"); oUserRecord.Field6 = oReader.GetString("Field6"); oUserRecord.Field7 = oReader.GetString("Field7"); oUserRecord.Field8 = oReader.GetString("Field8"); oUserRecord.CreatedBy = oReader.GetInt32("CreatedBy").Value; oUserRecord.CreatedDate = oReader.GetDateTime("CreateDate").Value; oUserRecord.ModifiedBy = oReader.GetInt32("Modifiedby"); oUserRecord.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oUserRecord.FundTypeID = oReader.GetInt32("FundTypeID").Value; this.SetObjectState(oUserRecord, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { UserRecord oEmployee = new UserRecord(); MapObject(oEmployee, oReader); return oEmployee as T; } protected UserRecord CreateObject(DataReader oReader) { UserRecord oEmployee = new UserRecord(); MapObject(oEmployee, oReader); return oEmployee; } #endregion #region Service implementation public List GetUserRecordByUserObjectID(int userObjectID, int fundtypeid) { List oUserRecords = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader = new DataReader(UserRecordDA.GetByUserObjectID(tc, userObjectID,fundtypeid)); oUserRecords = this.CreateObjects(oReader); oReader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetUserObject" + e.Message, e); #endregion } return oUserRecords; } public List Get( int userObjectID, int fundTypeID) { List oUserRecords = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader = new DataReader(UserRecordDA.GetByUserObjectID(tc, userObjectID, fundTypeID)); oUserRecords = this.CreateObjects(oReader); oReader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetUserObject" + e.Message, e); #endregion } return oUserRecords; } public List Get() { List oUserRecords = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader = new DataReader(UserRecordDA.Get(tc)); oUserRecords = this.CreateObjects(oReader); oReader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetUserObject" + e.Message, e); #endregion } return oUserRecords; } public UserRecord Get(int ID) { UserRecord oUserRecord =null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oReader = new DataReader(UserRecordDA.Get(tc, ID)); if (oReader.Read()) { oUserRecord = this.CreateObject(oReader); } oReader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetUserObject" + e.Message, e); #endregion } return oUserRecord; } public UserRecord GetByFieldOne(List orecords, string fieldOne) { foreach (UserRecord ur in orecords) { if (ur.Field1.Trim() == fieldOne) { return ur; } } return null; } public UserRecord GetByField1(string sUserRecordField1, int userObjectID, int fundTypeID) { UserRecord oUserRecord = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(UserRecordDA.GetByField1(tc, sUserRecordField1, userObjectID, fundTypeID)); if (oreader.Read()) { oUserRecord = CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to GetUserRecord : " + e.Message, e); #endregion } return oUserRecord; } #endregion } #endregion }