using System; using Ease.Core.Model; using Ease.Core.DataAccess; using HRM.BO; using Ease.Core.Utility; using System.Collections.Generic; namespace HRM.DA { public class CountryService : ServiceTemplate, ICountryService { #region constructor public CountryService() { } #endregion #region Object private void MapObject(Country oCountry, DataReader oReader) { //##### base.SetObjectID(oCountry, oReader.GetInt32("COUNTRYID").Value); oCountry.Code = oReader.GetString("CODE"); oCountry.Name = oReader.GetString("NAME"); //oCountry.Sequence = oReader.GetInt32("SequenceNo").Value; //oCountry.Status = (EnumStatus)oReader.GetInt32("Status").Value; oCountry.CreatedBy = oReader.GetInt32("CreatedBy", 0); oCountry.CreatedDate = oReader.GetDateTime("CreationDate").Value; oCountry.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oCountry.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oCountry, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Country oCountry = new Country(); MapObject(oCountry, oReader); return oCountry as T; } #endregion #region Service implementation public Country Get(int id) { Country oCountry = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(CountryDA.Get(tc, id)); if (oreader.Read()) { oCountry = 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 oCountry; } public Country Get(string sCode) { Country oCountry = null; //TransactionContext tc = null; //try //{ // tc = TransactionContext.Begin(); // DataReader oreader = new DataReader(CountryService.Get(tc, sCode)); // if (oreader.Read()) // { // oCountry = 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 oCountry; } public List Get() { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); // DataReader dr = new DataReader(CountryService.Get(tc)); DataReader dr = new DataReader(CountryDA.Get(tc)); countries = 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 countries; } public List Get(EnumStatus status, int payrolltypeid) { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CountryDA.Get(tc, status)); countries = 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 countries; } public List Get(EnumStatus status) { List countries = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(CountryDA.Get(tc, status)); countries = 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 countries; } public int Save(Country oCountry) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oCountry.IsNew) { int id = tc.GenerateID("COUNTRY", "COUNTRYID"); base.SetObjectID(oCountry, id); if (oCountry.Code == "") oCountry.Code = oCountry.ID.ToString(); CountryDA.Insert(tc, oCountry); } else { CountryDA.Update(tc, oCountry); } tc.End(); return oCountry.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); // CountryService.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 } }