using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using System.Collections.Generic; using Ease.Core.Utility; namespace HRM.DA { #region class Thana Service public class ThanaService : ServiceTemplate, IThanaService { #region constructor public ThanaService() { } #endregion #region object private void MapObject(Thana oThana, DataReader oReader) { base.SetObjectID(oThana, oReader.GetInt32("THANAID").Value); oThana.Code = oReader.GetString("CODE"); oThana.Name = oReader.GetString("NAME"); oThana.DistrictID = oReader.GetInt32("DISTRICTID", 0); oThana.Sequence = oReader.GetInt32("SequenceNo").Value; oThana.Status = (EnumStatus)oReader.GetInt32("Status").Value; oThana.CreatedBy = oReader.GetInt32("CreatedBy", 0); oThana.CreatedDate = oReader.GetDateTime("CreationDate").Value; oThana.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oThana.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oThana, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Thana oThana = new Thana(); MapObject(oThana, oReader); return oThana as T; } #endregion #region Service implementation public Thana Get(int id) { Thana oThana = null; 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 } return oThana; } public Thana Get(string sCode) { Thana oThana = null; 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 } return oThana; } public List Get() { List thanas = new List(); 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 } return thanas; } public List Get(EnumStatus status) { List thanas = new List(); 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 } return thanas; } public List GetByDistID(int nDistID) { List thanas = new List(); 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 } return thanas; } public int Save(Thana oThana) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oThana.IsNew) { int id = tc.GenerateID("THANA", "THANAID"); base.SetObjectID(oThana, id); if (oThana.Code == "") oThana.Code = oThana.ID.ToString(); 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(int 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 }