EchoTex_Payroll/HRM.DA/Service/PMP/PeerAppraisalService.cs

514 lines
18 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Ease.Core.Model;
using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core;
using Ease.Core.Utility;
using Payroll.Service;
namespace HRM.DA
{
#region PeerAppraisal Service
public class PeerAppraisalService : ServiceTemplate
{
public PeerAppraisalService()
{
}
private void MapObject(PeerAppraisal oPeerAppraisal, DataReader oReader)
{
base.SetObjectID(oPeerAppraisal, oReader.GetInt32("PeerAppraisalID").Value);
oPeerAppraisal.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oPeerAppraisal.PMPYearID = oReader.GetInt32("PMPYearID", 0);
oPeerAppraisal.AppraiserID = oReader.GetInt32("AppraiserID", 0);
oPeerAppraisal.Competency = oReader.GetInt32("Competency").Value;
oPeerAppraisal.Cooparation = oReader.GetInt32("Cooparation").Value;
oPeerAppraisal.Resourcefulness = oReader.GetInt32("Resourcefulness").Value;
oPeerAppraisal.Productivity = oReader.GetInt32("Productivity").Value;
oPeerAppraisal.Leadership = oReader.GetInt32("Leadership").Value;
oPeerAppraisal.OverallRating = oReader.GetDouble("OverallRating").Value;
oPeerAppraisal.Remarks = oReader.GetString("Remarks");
oPeerAppraisal.AppraisalDate = oReader.GetDateTime("AppraisalDate") == null
? DateTime.MinValue
: oReader.GetDateTime("AppraisalDate").Value;
oPeerAppraisal.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oPeerAppraisal.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oPeerAppraisal.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oPeerAppraisal.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oPeerAppraisal, ObjectState.Saved);
}
private void EmployeeMapObject(Employee oEmployee, DataReader oReader)
{
base.SetObjectID(oEmployee, oReader.GetInt32("EmployeeID").Value);
oEmployee.GlobalID = oReader.GetString("globalID");
oEmployee.EmployeeNo = oReader.GetString("employeeNo");
oEmployee.Name = oReader.GetString("name");
oEmployee.Gender = (EnumGender)oReader.GetInt32("gender").Value;
//oEmployee.IsManager = oReader.GetBoolean("IsManager").Value;
oEmployee.BirthDate = oReader.GetDateTime("birthDate").Value;
oEmployee.JoiningDate = oReader.GetDateTime("joiningDate").Value;
oEmployee.EndOfContractDate =
oReader.GetDateTime(
"endOfContractDate"); // ? oReader.GetDateTime("endOfContractDate").Value : DateTime.MinValue;
oEmployee.CardDate = oReader.GetDateTime("CardDate");
oEmployee.EmailAddress = oReader.GetString("emailAddress");
oEmployee.MobileNo = oReader.GetString("mobileNo");
oEmployee.TinNo = oReader.GetString("tinNo");
oEmployee.CategoryID = oReader.GetInt32("categoryID", 0);
oEmployee.ForeignExPat = oReader.GetBoolean("foreignExPat").Value;
oEmployee.ContinueGratuity = oReader.GetDouble("continueGratuity").HasValue
? oReader.GetDouble("continueGratuity").Value
: 0.0;
// oEmployee.TaxCircle = (EnumTaxCircle)oReader.GetInt32("taxCircle").Value;
//oEmployee.TaxCircle = oReader.GetString("taxCircle");
oEmployee.IsConfirmed = oReader.GetBoolean("isConfirmed").Value;
oEmployee.Status = (EnumEmployeeStatus)oReader.GetInt32("status").Value;
oEmployee.IsShownInTaxSheet = oReader.GetBoolean("isShownInTaxSheet").Value;
oEmployee.PFMemberType = (EnumPFMembershipType)oReader.GetInt32("pFMemberType").Value;
oEmployee.PFMemberShiptDate = oReader.GetDateTime("pfMemberShipDt").HasValue
? oReader.GetDateTime("pfMemberShipDt").Value
: DateTime.Now;
oEmployee.BranchID = oReader.GetInt32("branchID", 0);
oEmployee.AccountNo = oReader.GetString("accountNo");
oEmployee.OutPayBranchID = oReader.GetInt32("OUTPAYBRANCHID", 0);
oEmployee.OutPayAccountNo = oReader.GetString("outPayAccountNo");
oEmployee.DepartmentID = oReader.GetInt32("departmentID", 0);
oEmployee.LocationID = oReader.GetInt32("locationID", 0);
oEmployee.ReligionID = oReader.GetInt32("religionID", 0);
oEmployee.MaritalStatus = (EnumMaritalStatus)oReader.GetInt32("maritalStatusID").Value;
oEmployee.DesignationID = oReader.GetInt32("designationID", 0);
oEmployee.GradeID = oReader.GetInt32("gradeID", 0);
oEmployee.BasicSalary = oReader.GetDouble("basicSalary").Value;
oEmployee.PrevBasic = oReader.GetDouble("prevBasic").Value;
oEmployee.PaymentMode = (EnumPaymentMode)oReader.GetInt32("paymentMode").Value;
oEmployee.PaymentMode = (EnumPaymentMode)oReader.GetInt32("paymentMode").Value;
oEmployee.OutPayPaymentMode = (EnumPaymentMode)oReader.GetInt32("OutPayPaymentMode").Value;
oEmployee.FatherName = oReader.GetString("fatherName");
oEmployee.IsEligibleOT = oReader.GetBoolean("isEligibleOT").Value;
oEmployee.DescriptionText = oReader.GetString("desigDescription");
oEmployee.DesktopUserPass = oReader.GetString("desktopUserPass");
oEmployee.PayrollTypeID = oReader.GetInt32("payrollTypeID", 0);
oEmployee.IsAutoProcess = oReader.GetBoolean("IsAutoProcess").Value;
oEmployee.CardID = oReader.GetInt32("cardID", 0);
oEmployee.GrossSalary = oReader.GetDouble("grossSalary").Value;
oEmployee.PhotoPath = oReader.GetString("PhotoPath");
oEmployee.PayScaleId = oReader.GetInt32("payScaleId", 0);
oEmployee.TaxAmount = oReader.GetDouble("taxAmount").Value;
oEmployee.CurrentHistoryID = oReader.GetInt32("EmpHistoryID", 0);
oEmployee.MonthStatusUpdate = oReader.GetInt32("MonthStatusUpdate").HasValue
? (EnumEmployeeStatus)oReader.GetInt32("MonthStatusUpdate")
: EnumEmployeeStatus.Live;
//Diu to few clients already gets 0 default values;
if (oEmployee.MonthStatusUpdate == 0) oEmployee.MonthStatusUpdate = EnumEmployeeStatus.Live;
oEmployee.ConfirDate = oReader.GetDateTime("dateOfConfirmation").HasValue
? oReader.GetDateTime("dateOfConfirmation").Value
: DateTime.MinValue;
oEmployee.DiscontinueDate = oReader.GetDateTime("dateOfExpiry") != null
? oReader.GetDateTime("dateOfExpiry").Value
: DateTime.MinValue;
oEmployee.VendorCode = oReader.GetString("VendorCode");
oEmployee.Role = (EnumRoleType)oReader.GetInt32("Role").Value;
//oEmployee.Role = oReader.GetBoolean("Role").Value;
oEmployee.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oEmployee.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oEmployee.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oEmployee.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oEmployee.PersonType = (EnumPersonType)oReader.GetInt32("PersonType").Value;
oEmployee.LineManagerID = oReader.GetInt32("LineManagerID", 0);
oEmployee.SecondLineManagerID = oReader.GetInt32("SecondLineManagerID", 0);
this.SetObjectState(oEmployee, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PeerAppraisal oPeerAppraisal = new PeerAppraisal();
MapObject(oPeerAppraisal, oReader);
return oPeerAppraisal as T;
}
protected PeerAppraisal CreateObject(DataReader oReader)
{
PeerAppraisal oPeerAppraisal = new PeerAppraisal();
MapObject(oPeerAppraisal, oReader);
return oPeerAppraisal;
}
protected List<Employee> CreateEmployeeObjects(DataReader oReader)
{
List<Employee> employees = new List<Employee>();
while (oReader.Read())
{
employees.Add(CreateEmployeeObject(oReader));
}
return employees;
}
protected Employee CreateEmployeeObject(DataReader oReader)
{
Employee oEmployee = new Employee();
EmployeeMapObject(oEmployee, oReader);
return oEmployee;
}
#region Service implementation
public PeerAppraisal Get(int id)
{
PeerAppraisal oPeerAppraisal = new PeerAppraisal();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PeerAppraisalDA.Get(tc, id));
if (oreader.Read())
{
oPeerAppraisal = this.CreateObject<PeerAppraisal>(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 oPeerAppraisal;
}
public List<PeerAppraisal> GetByEmployeeID(int id)
{
List<PeerAppraisal> oPeerAppraisal = new List<PeerAppraisal>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PeerAppraisalDA.GetByEmployeeID(tc, id));
oPeerAppraisal = this.CreateObjects<PeerAppraisal>(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 oPeerAppraisal;
}
public List<Employee> GetEmployeeByPeerAppraisalsEmpId(int id, int pmpYearID)
{
List<Employee> oPeerAppraisal = new List<Employee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(PeerAppraisalDA.GetEmployeeByPeerAppraisalsEmpId(tc, id, pmpYearID));
oPeerAppraisal = this.CreateEmployeeObjects(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 oPeerAppraisal;
}
public List<PeerAppraisal> GetByPmpYearId(int pmpYearId)
{
TransactionContext tc = null;
List<PeerAppraisal> oPeerAppraisal = new List<PeerAppraisal>();
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PeerAppraisalDA.GetByPmpYearId(tc, pmpYearId));
oPeerAppraisal = this.CreateObjects<PeerAppraisal>(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 oPeerAppraisal;
}
public List<PeerAppraisal> Get()
{
List<PeerAppraisal> oPeerAppraisal = new List<PeerAppraisal>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PeerAppraisalDA.Get(tc));
if (dr.Read())
{
oPeerAppraisal = this.CreateObjects<PeerAppraisal>(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 oPeerAppraisal;
}
public List<PeerAppraisal> GetByAppraiserId(int appraisalID, int pMPYearID)
{
List<PeerAppraisal> oPeerAppraisal = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PeerAppraisalDA.GetByAppraiserId(tc, appraisalID, pMPYearID));
oPeerAppraisal = this.CreateObjects<PeerAppraisal>(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 oPeerAppraisal;
}
public PeerAppraisal Get(int EmployeeID, int AppraisalID, int PMPYearID)
{
PeerAppraisal oPeerAppraisal = new PeerAppraisal();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PeerAppraisalDA.Get(tc, EmployeeID, AppraisalID, PMPYearID));
if (dr.Read())
{
oPeerAppraisal = this.CreateObject<PeerAppraisal>(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 oPeerAppraisal;
}
public PeerAppraisal GetByEmpIdAppraiserId(int EmployeeID, int AppraisalID, int PmpYearID)
{
PeerAppraisal oPeerAppraisal = new PeerAppraisal();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr =
new DataReader(PeerAppraisalDA.GetByEmpIdAppraiserId(tc, EmployeeID, AppraisalID, PmpYearID));
if (dr.Read())
{
oPeerAppraisal = this.CreateObject<PeerAppraisal>(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 oPeerAppraisal;
}
public int Save(PeerAppraisal oPeerAppraisal)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPeerAppraisal.IsNew)
{
int id = tc.GenerateID("PeerAppraisal", "PeerAppraisalID");
base.SetObjectID(oPeerAppraisal, id);
PeerAppraisalDA.Insert(tc, oPeerAppraisal);
}
else
{
PeerAppraisalDA.Update(tc, oPeerAppraisal);
}
tc.End();
return oPeerAppraisal.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void SavePeerApprisals(List<PeerAppraisal> oPeerApprisals)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("PeerAppraisal", "PeerAppraisalID");
foreach (PeerAppraisal oPeerAppraisal in oPeerApprisals)
{
PeerAppraisalDA.Delete(tc, oPeerAppraisal.PMPYearID, oPeerAppraisal.EmployeeID);
}
foreach (PeerAppraisal oPeerAppraisal in oPeerApprisals)
{
base.SetObjectID(oPeerAppraisal, id);
PeerAppraisalDA.Insert(tc, oPeerAppraisal);
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 Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PeerAppraisalDA.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
}
}
#endregion
}
#endregion
}