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; using System.Text; namespace HRM.DA { #region TrainingAssessment Service class TrainingAssessmentService : ServiceTemplate { #region Private functions and declaration private void MapObject(TrainingAssessment oTrainingAssessment, DataReader oReader) { base.SetObjectID(oTrainingAssessment, (oReader.GetInt32("TrainingAssessmentID").Value)); oTrainingAssessment.TrainingId = oReader.GetInt32("TrainingId", 0); oTrainingAssessment.EmployeeId = oReader.GetInt32("EmployeeId", 0); oTrainingAssessment.Duration = oReader.GetString("Duration"); oTrainingAssessment.IsAssessmentCompleted = oReader.GetBoolean("IsAssessmentCompleted").Value; oTrainingAssessment.IvaluationPoint = oReader.GetInt32("IvaluationPoint", 0); oTrainingAssessment.ObtainedIvaluationPoint = oReader.GetInt32("ObtainedIvaluationPoint", 0); oTrainingAssessment.Location = oReader.GetString("Location"); oTrainingAssessment.Remarks = oReader.GetString("Remarks"); oTrainingAssessment.CreatedBy = oReader.GetInt32("CreatedBy", 0); oTrainingAssessment.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today; oTrainingAssessment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oTrainingAssessment.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTrainingAssessment, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { TrainingAssessment oTrainingAssessment = new TrainingAssessment(); MapObject(oTrainingAssessment, oReader); return oTrainingAssessment as T; } #endregion #region Implementation of ITrainingService #region Get Training public TrainingAssessment Get(int id) { TrainingAssessment oTrainingAssessment = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingAssessmentDA.Get(tc, id)); if (oreader.Read()) { oTrainingAssessment = CreateObject(oreader); } oreader.Close(); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainingAssessment; } #endregion #region Get Trainings public List Get() { List oTrainingAssessments = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingAssessmentDA.Get(tc)); oTrainingAssessments = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainingAssessments; } #endregion #region Insert Training public int Save(TrainingAssessment oTrainingAssessment) { try { TransactionContext tc = null; try { #region Saving data tc = TransactionContext.Begin(true); if (oTrainingAssessment.IsNew) { int newID = tc.GenerateID("TrainingAssessment", "TrainingAssessment"); base.SetObjectID(oTrainingAssessment, (newID)); TrainingAssessmentDA.Insert(tc, oTrainingAssessment); } else TrainingAssessmentDA.Update(tc, oTrainingAssessment); 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 oTrainingAssessment.ID; } #endregion #region Delete Trainng public void Delete(int id) { try { TransactionContext tc = null; try { #region Deleting data tc = TransactionContext.Begin(true); TrainingAssessmentDA.Delete(tc, id); 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 }