HRM-10/HRM.DA/Service/Fund/Basic/InvestmentCategoryService.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

365 lines
10 KiB
C#

using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
[Serializable]
#region InvestmentCategoryService
public class InvestmentCategoryService : ServiceTemplate, IInvestmentCategoryService
{
#region Private Function And Declaration
public InvestmentCategoryService()
{
}
private void MapObject(InvestmentCategory oInvestmentCategory, DataReader dr)
{
base.SetObjectID(oInvestmentCategory, dr.GetInt32("InvestmentCategoryID").Value);
oInvestmentCategory.Code = dr.GetString("Code");
oInvestmentCategory.Name = dr.GetString("Name");
oInvestmentCategory.UserObjectName = dr.GetString("UserObjectName");
oInvestmentCategory.MinValue = dr.GetDouble("MinValue").Value;
oInvestmentCategory.InterestRate = dr.GetDouble("InterestRate").Value;
oInvestmentCategory.FundTypeID = dr.GetInt32("FundTypeID").Value;
oInvestmentCategory.CreatedBy = dr.GetInt32("CreatedBy").Value;
oInvestmentCategory.CreatedDate = dr.GetDateTime("CreatedDate").Value;
oInvestmentCategory.ModifiedBy = dr.GetInt32("ModifiedBy");
oInvestmentCategory.ModifiedDate = dr.GetDateTime("ModifiedDate");
base.SetObjectState(oInvestmentCategory, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
InvestmentCategory item = new InvestmentCategory();
MapObject(item, dr);
return item as T;
}
private InvestmentCategory CreateObject(DataReader dr)
{
InvestmentCategory oInvestmentCategory = new InvestmentCategory();
MapObject(oInvestmentCategory, dr);
return oInvestmentCategory;
}
private List<InvestmentCategory> CreateObjects(IDataReader dr)
{
List<InvestmentCategory> oInvestmentCategorys = new List<InvestmentCategory>();
DataReader oreader = new DataReader(dr);
while (dr.Read())
{
InvestmentCategory Item = CreateObject(oreader);
oInvestmentCategorys.Add(Item);
}
return oInvestmentCategorys;
}
#endregion
#region Get
public List<InvestmentCategory> GetByFundType(int fundTypeID)
{
List<InvestmentCategory> oInvestmentCategory = new List<InvestmentCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader oreader = InvestmentCategoryDA.GetByFundType(tc, fundTypeID);
DataReader dr = new DataReader(oreader);
oInvestmentCategory = CreateObjects<InvestmentCategory>(dr);
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get InvestmentCategory", e);
#endregion
}
return oInvestmentCategory;
}
#endregion
#region GetbyFundTypeID(By ID)
public InvestmentCategory GetbyFundTypeID(int ID)
{
#region Cache Header
InvestmentCategory InvestmentCategory = new InvestmentCategory();
if (InvestmentCategory != null)
return InvestmentCategory;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(InvestmentCategoryDA.GetbyFundTypeID(tc, ID));
if (dr.Read())
{
InvestmentCategory = this.CreateObject<InvestmentCategory>(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
#endregion
return InvestmentCategory;
}
public InvestmentCategory Get(int ID)
{
InvestmentCategory InvestmentCategory = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(InvestmentCategoryDA.Get(tc, ID));
if (dr.Read())
{
InvestmentCategory = this.CreateObject<InvestmentCategory>(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
#endregion
return InvestmentCategory;
}
#endregion
public List<InvestmentCategory> Get()
{
List<InvestmentCategory> oInvestmentCategory = new List<InvestmentCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(InvestmentCategoryDA.Get(tc));
oInvestmentCategory = this.CreateObjects<InvestmentCategory>(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 oInvestmentCategory;
}
public List<InvestmentCategory> Get(EnumStatus status, int payrollTypeId)
{
List<InvestmentCategory> oInvestmentCategory = new List<InvestmentCategory>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader oreader = InvestmentCategoryDA.Get(tc);
DataReader dr = new DataReader(oreader);
oInvestmentCategory = CreateObjects<InvestmentCategory>(dr);
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 oInvestmentCategory;
}
#region IsExist
public bool IsExist(string code, int fundtypeid)
{
bool exists = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
exists = InvestmentCategoryDA.IsExist(tc, code, fundtypeid);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Check by code" + e.Message, e);
}
return exists;
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
InvestmentCategoryDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete InvestmentCategory", e);
#endregion
}
}
#endregion
#region Insert
public void Save(InvestmentCategory investmentCategory)
{
InvestmentCategory oInvestmentCategory = new InvestmentCategory();
oInvestmentCategory = investmentCategory;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oInvestmentCategory.IsNew)
{
int id = tc.GenerateID("FM_InvestmentCategory", "InvestmentCategoryID");
base.SetObjectID(oInvestmentCategory, (id));
InvestmentCategoryDA.Insert(tc, oInvestmentCategory);
}
else
{
InvestmentCategoryDA.Update(tc, oInvestmentCategory);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region GetTable
public DataTable GetTable(int fundtypeid)
{
DataTable dTbl = new DataTable("InvestmentCategory");
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader ir = InvestmentCategoryDA.Get(tc, fundtypeid);
dTbl.Load(ir);
ir.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 dTbl;
}
#endregion
}
#endregion
}