using HRM.BO; using HRM.DA; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Data; namespace HRM.DA { public class AssetCategoryService : ServiceTemplate, IAssetCategoryService { public AssetCategoryService() { } private void MapObject(AssetCategory oAssetCategory, DataReader oReader) { base.SetObjectID(oAssetCategory, oReader.GetInt32("ASSETCATEGORYID").Value); oAssetCategory.Code = oReader.GetString("code"); oAssetCategory.Name = oReader.GetString("description"); oAssetCategory.ParentID = oReader.GetInt32("parentID"); oAssetCategory.Status = (EnumStatus)oReader.GetInt32("Status").Value; oAssetCategory.Tier = oReader.GetInt32("TIRE").Value; oAssetCategory.CreatedBy = oReader.GetInt32("CreatedBy").Value; oAssetCategory.CreatedDate = oReader.GetDateTime("CreationDate").Value; oAssetCategory.ModifiedBy = oReader.GetInt32("ModifiedBy"); oAssetCategory.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oAssetCategory, Ease.Core.ObjectState.Saved); oAssetCategory.PayrollTypeID = oReader.GetInt32("PayrollTypeID").Value; } protected override T CreateObject(DataReader oReader) { AssetCategory oAssetCategory = new AssetCategory(); MapObject(oAssetCategory, oReader); return oAssetCategory as T; } #region Service implementation public AssetCategory Get(TransactionContext tc, int id) { AssetCategory oAssetCategory = null; try { DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, id)); if (oreader.Read()) { oAssetCategory = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oAssetCategory; } public AssetCategory Get(int id) { AssetCategory oAssetCategory = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, id)); if (oreader.Read()) { oAssetCategory = 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 oAssetCategory; } public string GetNextCode(int tier) { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "location", "codeautogenerate", "location", "Code", tier); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public List GetAssetCategories() { List assetCategories = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.Get(tc)); assetCategories = 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 } //#region Cache Footer //_cache.Add(locations, "Get"); //#endregion return assetCategories; } public List GetAllAssetCategories(int payrollTypeID, EnumStatus status, string code, string name) { List assetCategories = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.GetAllAssetCategories(tc, payrollTypeID, status, code, name)); assetCategories = 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 assetCategories; } public List GetAllAssetCategory(string code, string name) { List assetCategories = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.GetAllAssetCategory(tc, code, name)); assetCategories = 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 assetCategories; } public string GetNextCode(int _tier, string _parentCode) { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); //#### _code = GlobalFunctionService.GetMaxCodeofTree(tc, "location", "codeautogenerate", "location", "Code","LocationID","ParentID", _parentCode, _tier); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public string GetNextCode(int _tier, int parentid) { TransactionContext tc = null; string _code = ""; string parentCode = string.Empty; try { if (parentid != -1) { AssetCategory parent = this.Get((int)parentid); if (parent != null) parentCode = parent.Code; } tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCodeofTree(tc, "AssetCategory", "codeautogenerate", "AssetCategory", "Code", "AssetCategoryID", "ParentID", parentCode, _tier); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public AssetCategory Get(string code) { AssetCategory oLocation = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, code)); if (oreader.Read()) { oLocation = 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 oLocation; } public List Get(EnumStatus sts) { List allLocations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AssetCategoryDA.Get(tc, sts)); if (oreader.Read()) { allLocations = this.CreateObjects(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 allLocations; } public List Get() { List locations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.Get(tc)); locations = 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 locations; } public List GetChield(int parentID) { List locations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.GetChilds(tc, parentID)); locations = 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 locations; } public List GetParents(EnumStatus status, int payrollTypeID) { List locations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.GetParent(tc, status, payrollTypeID)); locations = 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 locations; } public List Get(EnumStatus status, int payrollTypeID) { List locations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.Get(tc, status, payrollTypeID)); locations = 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 locations; } public List GetByTier(int tier) { List locations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AssetCategoryDA.GetByTier(tc, tier)); locations = 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 locations; } public int Save(AssetCategory oAssetCategory) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAssetCategory.IsNew) { int id = tc.GenerateID("AssetCategory", "ASSETCATEGORYID"); //int sequenceId = tc.GenerateID("oAssetCategory", "SequenceNO"); //oLocation.Sequence = sequenceId; base.SetObjectID(oAssetCategory, id); AssetCategoryDA.Insert(tc, oAssetCategory); } else { AssetCategoryDA.Update(tc, oAssetCategory); } tc.End(); return oAssetCategory.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, int UserID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AssetCategoryDA.Delete(tc, id, UserID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AssetCategoryDA.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 } } } }