EchoTex_Payroll/HRM.DA/Service/Assets/AssetItService.cs

221 lines
6.1 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
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<T>(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<AssetIt>(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<AssetIt> GetAssetIt(int assetserialid, int assetitid, string ipaddress, string macaddress, string serialno, string specification)
{
List<AssetIt> AssetsIt = new List<AssetIt>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetItDA.GetAssetIt(tc, assetserialid, assetitid, ipaddress, macaddress, serialno, specification));
AssetsIt = this.CreateObjects<AssetIt>(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<AssetIt> GetAssetItSerialPicker(int assetid, int categoryid, int assetitid, int assetserialid)
{
List<AssetIt> AssetItSerials = new List<AssetIt>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetItDA.GetAssetItSerialPicker(tc, assetid, categoryid, assetitid, assetserialid));
AssetItSerials = this.CreateObjects<AssetIt>(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<AssetIt> Get()
{
List<AssetIt> assets = new List<AssetIt>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(AssetItDA.Get(tc));
assets = this.CreateObjects<AssetIt>(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
}
}