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 { #region PhotoPath Service [Serializable] public class PhotoPathService : ServiceTemplate, IPhotoPathService { #region Private functions and declaration Cache _cache = new Cache(typeof(PhotoPath)); #endregion public PhotoPathService() { } private void MapObject(PhotoPath oPhotoPath, DataReader oReader) { base.SetObjectID(oPhotoPath, oReader.GetID("PathID")); oPhotoPath.EmployeePhoto = oReader.GetString("EmployeePhoto"); oPhotoPath.EmployeeSignature = oReader.GetString("EmployeeSignature"); oPhotoPath.NomineePhoto = oReader.GetString("NomineePhoto"); oPhotoPath.NomineeSignature = oReader.GetString("NomineeSignature"); oPhotoPath.HospitalizationPhoto = oReader.GetString("HospitalizationPhoto"); oPhotoPath.LetterTempPath = oReader.GetString("LetterTempPath"); oPhotoPath.TrainingOutlinePath = oReader.GetString("TrainingOutlinePath"); oPhotoPath.ERRSFilePath = oReader.GetString("ERRSFilePath"); this.SetObjectState(oPhotoPath, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PhotoPath oPhotoPath = new PhotoPath(); MapObject(oPhotoPath, oReader); return oPhotoPath as T; } protected PhotoPath CreateObject(DataReader oReader) { PhotoPath oPhotoPath = new PhotoPath(); MapObject(oPhotoPath, oReader); return oPhotoPath; } #region Service implementation public PhotoPath Get(ID id) { PhotoPath oPhotoPath = new PhotoPath(); #region Cache Header oPhotoPath = _cache["Get", id] as PhotoPath; if (oPhotoPath != null) return oPhotoPath; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PhotoPathDA.Get(tc, id)); if (oreader.Read()) { oPhotoPath = 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 } #region Cache Footer _cache.Add(oPhotoPath, "Get", id); #endregion return oPhotoPath; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate PhotoPaths = _cache["Get"] as ObjectsTemplate; if (PhotoPaths != null) return PhotoPaths; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(PhotoPathDA.Get(tc)); PhotoPaths = 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 } #region Cache Footer _cache.Add(PhotoPaths, "Get"); #endregion return PhotoPaths; } public ID Save(PhotoPath oPhotoPath) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oPhotoPath.IsNew) { int id = tc.GenerateID("PhotoPath", "PathID"); base.SetObjectID(oPhotoPath, ID.FromInteger(id)); PhotoPathDA.Insert(tc, oPhotoPath); } else { PhotoPathDA.Update(tc, oPhotoPath); } tc.End(); return oPhotoPath.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); PhotoPathDA.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 }