using System; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using System.Collections.Generic; using HRM.BO; namespace HRM.DA { public class AssetItService: ServiceTemplate, IAssetItService { #region MapObject For AssetIt protected override T CreateObject(DataReader oReader) { AssetIt oAssetIt = new AssetIt(); MapObject(oAssetIt, oReader); return oAssetIt as T; } private void MapObject(AssetIt oAssetIt, DataReader oReader) { base.SetObjectID(oAssetIt, oReader.GetInt32("AssetItID").Value); oAssetIt.AssetSerialID = oReader.GetInt32("AssetSerialID").Value; oAssetIt.IpAddress = oReader.GetString("IpAddress"); oAssetIt.MacAddress = oReader.GetString("MacAddress"); oAssetIt.SerialNo = oReader.GetString("SerialNo"); oAssetIt.Specification = oReader.GetString("Specification"); this.SetObjectState(oAssetIt, Ease.Core.ObjectState.Saved); } #endregion MapObject For AssetIt #region Service Implemantation public AssetIt Get(int id) { AssetIt oAsset = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AssetItDA.Get(tc, id)); if (oreader.Read()) { oAsset = 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 oAsset; } public List GetAssetIt(int assetserialid, int assetitid, string ipaddress, string macaddress, string serialno, string specification) { List AssetsIt = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetItDA.GetAssetIt(tc, assetserialid, assetitid, ipaddress, macaddress, serialno, specification)); AssetsIt = 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 AssetsIt; } public List GetAssetItSerialPicker(int assetid, int categoryid, int assetitid, int assetserialid) { List AssetItSerials = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetItDA.GetAssetItSerialPicker(tc, assetid, categoryid, assetitid, assetserialid)); AssetItSerials = 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 AssetItSerials; } public List Get() { List assets = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetItDA.Get(tc)); assets = 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 assets; } public int Save(AssetIt oAsset) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAsset.IsNew) { int id = tc.GenerateID("AssetIt", "AssetItID"); base.SetObjectID(oAsset, id); AssetItDA.Insert(tc, oAsset); } else { AssetItDA.Update(tc, oAsset); } return oAsset.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } finally { tc.End(); } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AssetItDA.Delete(tc, id); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } finally { tc.End(); } } #endregion Service Implemantation } }