using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region OrganogramEmployee Service [Serializable] public class OrganogramEmployeeService : ServiceTemplate, IOrganogramEmployeeService { #region Private functions and declaration Cache _cache = new Cache(typeof(OrganogramEmployee)); #endregion public OrganogramEmployeeService() { } private void MapObject(OrganogramEmployee oOrganEmp, DataReader oReader) { //base.SetObjectID(oOrganEmp,ID.FromComplex(oReader.GetID("NodeID"),oReader.GetID("EmployeeID"))); base.SetObjectID(oOrganEmp, oReader.GetID("OrganEmpID")); oOrganEmp.NodeID = oReader.GetID("NodeID"); oOrganEmp.EmployeeID = oReader.GetID("EmployeeID"); oOrganEmp.AssignDate = oReader.GetDateTime("AssignDate").Value; oOrganEmp.CreatedBy = oReader.GetID("CreatedBy"); oOrganEmp.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOrganEmp.ModifiedBy = oReader.GetID("ModifiedBy"); //oOrganEmp.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; this.SetObjectState(oOrganEmp, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee(); MapObject(oOrganogramEmployee, oReader); return oOrganogramEmployee as T; } protected OrganogramEmployee CreateObject(DataReader oReader) { OrganogramEmployee oOrganogramEmployee = new OrganogramEmployee(); MapObject(oOrganogramEmployee, oReader); return oOrganogramEmployee; } #region Service implementation public ID Save(OrganogramEmployee oOrganogramEmployee) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); Save(oOrganogramEmployee); tc.End(); } catch(Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oOrganogramEmployee.ID; } public void SaveEmp(ObjectsTemplate oOrganogramEmployees) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (OrganogramEmployee orgEmp in oOrganogramEmployees) { if (orgEmp.IsNew) { int id = tc.GenerateID("OrganEmployee", "OrganEmpID"); base.SetObjectID(orgEmp, ID.FromInteger(id)); orgEmp.CreatedBy = User.CurrentUser.ID; orgEmp.CreatedDate = DateTime.Today; OrganogramEmployeeDA.Insert(tc, orgEmp); } else { orgEmp.ModifiedBy = User.CurrentUser.ID; orgEmp.ModifiedDate = DateTime.Today; OrganogramEmployeeDA.Update(tc, orgEmp); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID Save(TransactionContext tc, OrganogramEmployee oOrganogramEmployee) { try { if (oOrganogramEmployee.IsNew) { int id = tc.GenerateID("OrganEmployee", "OrganEmpID"); base.SetObjectID(oOrganogramEmployee, ID.FromInteger(id)); OrganogramEmployeeDA.Insert(tc, oOrganogramEmployee); } else { OrganogramEmployeeDA.Update(tc, oOrganogramEmployee); } return oOrganogramEmployee.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //public static void SaveForEmpLIfeCycle(TransactionContext tc, OrganogramEmployee oOrganogramEmployee) //{ // try // { // int id = tc.GenerateID("OrganEmployee", "OrganEmpID"); // OrganogramEmployeeDA.InsertForLifeCycle(tc, oOrganogramEmployee,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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OrganogramEmployeeDA.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 } } public void DeleteByEmp(TransactionContext tc, ID id) { try { OrganogramEmployeeDA.DeleteByEmp(tc, id); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ObjectsTemplate Get(TransactionContext tc, ID nodeID) { ObjectsTemplate oOrganogramEmployee = new ObjectsTemplate(); #region Cache Header oOrganogramEmployee = _cache["Get", nodeID] as ObjectsTemplate; if (oOrganogramEmployee != null) return oOrganogramEmployee; #endregion try { DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID)); oOrganogramEmployee = this.CreateObjects(dr); dr.Close(); } 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(oOrganogramEmployee, "Get", nodeID); #endregion return oOrganogramEmployee; } public ObjectsTemplate GetByEmp(ID empID) { ObjectsTemplate oOrganogramEmployee = new ObjectsTemplate(); #region Cache Header oOrganogramEmployee = _cache["GetByEmp", empID] as ObjectsTemplate; if (oOrganogramEmployee != null) return oOrganogramEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByEmp(tc, empID)); oOrganogramEmployee = 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(oOrganogramEmployee, "GetByEmp", empID); #endregion return oOrganogramEmployee; } public ObjectsTemplate Get(ID nodeID) { ObjectsTemplate oOrganogramEmployee = new ObjectsTemplate(); #region Cache Header oOrganogramEmployee = _cache["Get", nodeID] as ObjectsTemplate; if (oOrganogramEmployee != null) return oOrganogramEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc, nodeID)); oOrganogramEmployee = 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(oOrganogramEmployee, "Get", nodeID); #endregion return oOrganogramEmployee; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oOrganogramEmployee = _cache["Get"] as ObjectsTemplate; if (oOrganogramEmployee != null) return oOrganogramEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.Get(tc)); oOrganogramEmployee = 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(oOrganogramEmployee, "Get"); #endregion return oOrganogramEmployee; } public ObjectsTemplate GetByPositionType(EnumOGPositionType enPositionType) { #region Cache Header ObjectsTemplate oOrganogramEmployee = _cache["GetByPositionType", enPositionType] as ObjectsTemplate; if (oOrganogramEmployee != null) return oOrganogramEmployee; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OrganogramEmployeeDA.GetByPositionType(tc, enPositionType)); oOrganogramEmployee = 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(oOrganogramEmployee, "GetByPositionType", enPositionType); #endregion return oOrganogramEmployee; } #endregion } #endregion }