using System; using System.Collections.Generic; using HRM.BO; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System.Data; using Microsoft.Data.SqlClient; using System.Linq; namespace HRM.DA { public class EmployeeCordinatorService : ServiceTemplate { public EmployeeCordinatorService() { } private void MapObject(EmployeeCordinator oEmployeeCordinator, DataReader oReader) { base.SetObjectID(oEmployeeCordinator, oReader.GetInt32("empCordinatorID").Value); oEmployeeCordinator.EmployeeID = (int)oReader.GetInt32("EmployeeID"); oEmployeeCordinator.CordinatorID = (int)oReader.GetInt32("CordinatorID"); oEmployeeCordinator.ApproveTimeRequest = oReader.GetBoolean("ApproveTimeRequest",true,false); oEmployeeCordinator.EmployeeNo = oReader.GetString("EmployeeNo", true, ""); oEmployeeCordinator.EmployeeName = oReader.GetString("EmployeeName", true, ""); //oEmployeeCordinator.ReportFormat = (EnumSchedularReportFormat)oReader.GetInt32("ReportFormat", (int)EnumSchedularReportFormat.None); //oEmployeeCordinator.Status = (EnumStatus)oReader.GetInt32("STATUS").Value; oEmployeeCordinator.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oEmployeeCordinator.CreatedBy = oReader.GetInt32("CreatedBy").Value; //oEmployeeCordinator.ToEmailAddress = oReader.GetString("TOEMAILADDRESS") != null ? oReader.GetString("TOEMAILADDRESS").ToString().Split(",").ToList() : new List(); this.SetObjectState(oEmployeeCordinator, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmployeeCordinator oEmployeeCordinator = new EmployeeCordinator(); MapObject(oEmployeeCordinator, oReader); return oEmployeeCordinator as T; } private EmployeeCordinator CreateObject(DataReader oReader) { EmployeeCordinator oEmployeeCordinator = new EmployeeCordinator(); MapObject(oEmployeeCordinator, oReader); return oEmployeeCordinator; } public DataTable GetCoordinatorList() { DataTable odata = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); odata = EmployeeCordinatorDA.GetCoordinatorList(tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return odata; } public List Get() { List oEmployeeCordinator = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeCordinatorDA.Get(tc)); oEmployeeCordinator = 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 oEmployeeCordinator; } public List Get(int cordinatorid) { List oEmployeeCordinator = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeCordinatorDA.Get(tc,cordinatorid)); oEmployeeCordinator = 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 oEmployeeCordinator; } public void Insert(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeCordinatorDA.DeleteByCordinator(tc, items[0].CordinatorID); foreach (EmployeeCordinator item in items) { EmployeeCordinatorDA.Insert(tc, item.EmployeeID, (int)item.CordinatorID, item.ApproveTimeRequest, item.CreatedBy); } 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 Update(List emps) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (Employee item in emps) { EmployeeCordinatorDA.Update(tc, item.ID, (int)item.LineManagerID, item.SecondLineManagerID); } 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 Delete(EmployeeCordinator empC) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeCordinatorDA.Delete(tc, empC.ID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }