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 class Thana Service [Serializable] public class ThanaService : ServiceTemplate, IThanaService { #region Private functions and declaration Cache _cache = new Cache(typeof(Thana)); #endregion #region constructor public ThanaService() { } #endregion #region object private void MapObject(Thana oThana, DataReader oReader) { base.SetObjectID(oThana, oReader.GetID("THANAID")); oThana.Code = oReader.GetString("CODE"); oThana.Name = oReader.GetString("NAME"); oThana.DistrictID = oReader.GetID("DISTRICTID"); oThana.Sequence = oReader.GetInt32("SequenceNo").Value; oThana.Status = (EnumStatus)oReader.GetInt32("Status").Value; oThana.CreatedBy = oReader.GetID("CreatedBy"); oThana.CreatedDate = oReader.GetDateTime("CreationDate").Value; oThana.ModifiedBy = oReader.GetID("ModifiedBy"); oThana.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oThana, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Thana oThana = new Thana(); MapObject(oThana, oReader); return oThana as T; } protected Thana CreateObject(DataReader oReader) { Thana oThana = new Thana(); MapObject(oThana, oReader); return oThana; } #endregion #region Service implementation public Thana Get(ID id) { Thana oThana = new Thana(); #region Cache Header oThana = _cache["Get", id] as Thana; if (oThana != null) return oThana; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ThanaDA.Get(tc, id)); if (oreader.Read()) { oThana = 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(oThana, "Get", id); #endregion return oThana; } public Thana Get(string sCode) { Thana oThana = new Thana(); #region Cache Header oThana = _cache["Get", sCode] as Thana; if (oThana != null) return oThana; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ThanaDA.Get(tc, sCode)); if (oreader.Read()) { oThana = 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(oThana, "Get", sCode); #endregion return oThana; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate thanas = _cache["Get"] as ObjectsTemplate; if (thanas != null) return thanas; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ThanaDA.Get(tc)); thanas = 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(thanas, "Get"); #endregion return thanas; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate thanas = _cache["Get"] as ObjectsTemplate; if (thanas != null) return thanas; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ThanaDA.Get(tc, status)); thanas = 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(thanas, "Get", status); #endregion return thanas; } public ObjectsTemplate GetByDistID(ID nDistID) { #region Cache Header ObjectsTemplate thanas = _cache["GetByDistID"] as ObjectsTemplate; if (thanas != null) return thanas; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ThanaDA.GetByDistID(tc, nDistID)); thanas = 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(thanas, "GetByDistID", nDistID); #endregion return thanas; } public ID Save(Thana oThana) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oThana.IsNew) { int id = tc.GenerateID("THANA", "THANAID"); base.SetObjectID(oThana, ID.FromInteger(id)); ThanaDA.Insert(tc, oThana); } else { ThanaDA.Update(tc, oThana); } tc.End(); return oThana.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); ThanaDA.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 }