using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { public class PasswordHistoryService : ServiceTemplate, IPasswordHistoryService { private void MapObject(PasswordHistory oHistory, DataReader oReader) { base.SetObjectID(oHistory, ID.FromInteger(oReader.GetInt32("PasswordHistoryID").Value)); oHistory.UserID = ID.FromInteger(oReader.GetInt32("UserID").Value); oHistory.UserPassword = oReader.GetString("UserPassword"); oHistory.CreatedDate = oReader.GetDateTime("CreationDate").Value; this.SetObjectState(oHistory, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PasswordHistory oHistory = new PasswordHistory(); MapObject(oHistory, oReader); return oHistory as T; } public ID Save(PasswordHistory oHistory) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("PasswordHistory", "PasswordHistoryID"); base.SetObjectID(oHistory, ID.FromInteger(id)); PasswordHistoryDA.Insert(tc, oHistory); tc.End(); return oHistory.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ObjectsTemplate Get() { ObjectsTemplate histories = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PasswordHistoryDA.Get(tc)); histories = 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 histories; } public ObjectsTemplate Get(ID nUserID) { ObjectsTemplate histories = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PasswordHistoryDA.Get(tc, nUserID)); histories = 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 histories; } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PasswordHistoryDA.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 } } } }