using System; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using System.Collections.Generic; using HRM.BO; using System.Data; using Ease.Core; using System.Linq; namespace HRM.DA { #region TrainingSchEmpCost Service class TrainingSchEmpCostService : ServiceTemplate { #region Private functions and declaration private void MapObject(TrainingSchEmpCost oTrainingSchEmpCost, DataReader oReader) { base.SetObjectID(oTrainingSchEmpCost, (oReader.GetInt32("TrainingSchEmpCostID").Value)); oTrainingSchEmpCost.CostHdID = oReader.GetInt32("CostHdID").Value; oTrainingSchEmpCost.Amount = oReader.GetDouble("Amount").Value; oTrainingSchEmpCost.TrunDate = oReader.GetDateTime("TrunDate").Value; oTrainingSchEmpCost.Remarks = oReader.GetString("Remarks"); oTrainingSchEmpCost.EmployeeID = oReader.GetInt32("EmployeeID").Value; oTrainingSchEmpCost.TrainSchEmpID = oReader.GetInt32("TrainSchEmpID").Value; oTrainingSchEmpCost.CreatedBy = oReader.GetInt32("CreatedBy", 0); oTrainingSchEmpCost.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today; oTrainingSchEmpCost.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oTrainingSchEmpCost.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTrainingSchEmpCost, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TrainingSchEmpCost oTrainingSchEmpCost = new TrainingSchEmpCost(); MapObject(oTrainingSchEmpCost, oReader); return oTrainingSchEmpCost as T; } #endregion #region Implementation of ITrainingSchEmpCostService #region Get TrainingSchEmpCost public TrainingSchEmpCost Get(int TrainingSchEmpCostID) { TrainingSchEmpCost oTrainingSchEmpCost = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingSchEmpCostDA.Get(tc, TrainingSchEmpCostID)); oreader.Read(); oTrainingSchEmpCost = CreateObject(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainingSchEmpCost; } #endregion #region Get TrainingSchEmpCosts public List Get() { List oTrainingSchEmpCosts = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingSchEmpCostDA.Get(tc)); oTrainingSchEmpCosts = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainingSchEmpCosts; } public List GetByTrainingScheduleEmpID(TransactionContext tc, int empID, int trainSchEmpID) { List trainingSchEmpCosts = null; try { #region Retrieving data DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetByTrainingScheduleEmpID(tc, empID, trainSchEmpID)); trainingSchEmpCosts = CreateObjects(oreader); oreader.Close(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return trainingSchEmpCosts; } public List GetByTrainingScheduleEmpID(int empID, int trainSchEmpID) { List trainingSchEmpCosts = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetByTrainingScheduleEmpID(tc, empID, trainSchEmpID)); trainingSchEmpCosts = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return trainingSchEmpCosts; } public List GetCostWithoutParent() { List trainingSchEmpCosts = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetCostWithoutParent(tc)); trainingSchEmpCosts = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return trainingSchEmpCosts; } #endregion #region Insert TrainingSchEmpCost public int Save(TrainingSchEmpCost oTrainingSchEmpCost) { try { TransactionContext tc = null; try { #region Saving data tc = TransactionContext.Begin(true); #region Checking Duplicate TrainingSchEmpCost Code //bool result = false; //result = TrainingSchEmpCostDA.IsExists("TrainingSchEmpCost", "Code", oTrainingSchEmpCost.Code, tc); //if ( oTrainingSchEmpCost.IsNew) //{ // throw new ServiceException("Duplicate code is not allowed."); //} #endregion if (oTrainingSchEmpCost.IsNew) { int newID = tc.GenerateID("TrainingSchEmpCost", "TrainingSchEmpCostID"); base.SetObjectID(oTrainingSchEmpCost, (newID)); TrainingSchEmpCostDA.Insert(tc, oTrainingSchEmpCost); } else TrainingSchEmpCostDA.Update(tc, oTrainingSchEmpCost); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { //throw new ServiceException(e.Message, e); throw new Exception(e.Message, e); } return oTrainingSchEmpCost.ID; } public void SaveTrainingSheduleCost(List tsec) { try { TransactionContext tc = null; try { #region Saving data tc = TransactionContext.Begin(true); //TrainingScheduleDA.DeleteTrainingEmployees(tc, oTrainingSchedule.ID); foreach (TrainingSchEmpCost item in tsec) { //enrolledTrainingEmployee.TrainingScheduleID = oTrainingSchedule.ID; //base.SetObjectID(enrolledTrainingEmployee, (tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID"))); //TrainingScheduleDA.InsertTrainingEmployee(tc, enrolledTrainingEmployee); int newID = tc.GenerateID("TrainingSchEmpCost", "TrainingSchEmpCostID"); base.SetObjectID(item, (newID)); item.CreatedBy = item.CreatedBy; item.CreatedDate = DateTime.Today; TrainingSchEmpCostDA.Insert(tc, item); } TrainingSchEmpCostDA.DeleteCommonUpdateUncommon(tc); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { throw new Exception(e.Message, e); } } #endregion #region Delete Trainng public void Delete(int TrainingSchEmpCostID) { try { TransactionContext tc = null; try { #region Deleting data tc = TransactionContext.Begin(true); TrainingSchEmpCostDA.Delete(tc, TrainingSchEmpCostID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } } catch (Exception e) { throw new ServiceException(e.Message, e); } } #endregion #endregion } #endregion }