using DocumentFormat.OpenXml.Spreadsheet; using HRM.BO; using HRM.BO.Configuration; using HRM.BO.ess; using HRM.BO.Report; //using HRM.BO.Report; using HRM.DA; using iTextSharp.text; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using Newtonsoft.Json; using Org.BouncyCastle.Ocsp; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Threading.Tasks; using static Azure.Core.HttpHeader; using static iTextSharp.text.pdf.AcroFields; namespace HRM.UI.Controllers { [ApiController] [Route("api/Employee")] [Authorize] public class EmployeeController : ControllerBase { private readonly IEmployeeService _EmployeeService; ISearchEmployeeService _serachManager; IHREmployeeService _hrEmployeeService; IEmployeeBankAccountService _employeeBankAccountService; private IEmployeeCostCenterService _employeeCostCenterService; private readonly IDepartmentService _departmentService; private readonly IDesignationService _designationService; private readonly ILocationService _locationService; private readonly ICostcenterService _costCenterService; private readonly IOptions _employeeApiInfo; private readonly IPayrollTypeService _payrollTypeService; private readonly IInstitutionService _institutionService; private readonly IEducationLevelService _educationLevelService; private readonly ICacheManager _cashManager; private readonly IWebHostEnvironment _env; public EmployeeController(ISearchEmployeeService searchManager, IHREmployeeService hREmployee, IEmployeeService empService, IEmployeeBankAccountService employeeBankAccountService, IEmployeeCostCenterService employeeCostCenterService, IDepartmentService departmentService, IDesignationService designationService, ILocationService locationService, ICostcenterService costCenterService, IOptions employeeApiInfo, IPayrollTypeService payrollTypeService, IInstitutionService institutionService, IEducationLevelService educationLevelService, ICacheManager cashManager, IWebHostEnvironment env) { _serachManager = searchManager; _hrEmployeeService = hREmployee; _EmployeeService = empService; _employeeBankAccountService = employeeBankAccountService; _employeeCostCenterService = employeeCostCenterService; _departmentService = departmentService; _designationService = designationService; _locationService = locationService; _costCenterService = costCenterService; _employeeApiInfo = employeeApiInfo; _payrollTypeService = payrollTypeService; _institutionService = institutionService; _educationLevelService = educationLevelService; _cashManager = cashManager; _env = env; } //[HttpGet("getemployees")] //public List GetEmployees() //{ // EmployeeService service = new EmployeeService(); // return service.Get(); //} [HttpPost] [Route("getSearchEmployeeForCordinator")] public ActionResult getSearchEmployeeForCordinator(SearchManager omanager) { List olist = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { olist = _serachManager.FindCordinator((int)currentUser.EmployeeID, currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpPost] [Route("getSearchEmployee")] public ActionResult getSearchEmployee(SearchManager omanager) { List olist = new List(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (omanager.TaxParamID == 0 && currentUser.TaxParamID != null) omanager.TaxParamID = (int)currentUser.TaxParamID; if (currentUser.NextPayProcessDate != null) omanager.LastPayProcessMonth = GlobalFunctions.LastDateOfMonth(((DateTime)currentUser.NextPayProcessDate).AddMonths(-1)); SearchManager.SearchParameter oparam = omanager.Parameter.SearchParameters.FirstOrDefault(x => x.Paramter == EnumSearchParameter.PayrollTypeID); if (oparam == null) { SearchManager.SearchParameter op = new SearchManager.SearchParameter(); op.DataType = EnumSearchObjDataType.Number; op.ParameterValue = currentUser.PayrollTypeID; op.Paramter = EnumSearchParameter.PayrollTypeID; op.SqlOperator = EnumSQLOperator.EqualTo; omanager.Parameter.SearchParameters.Add(op); omanager.payrolltypeID = (int)currentUser.PayrollTypeID; } else { omanager.payrolltypeID = Convert.ToInt32(oparam.ParameterValue); } SearchManager.SearchParameter oparamLM = omanager.Parameter.SearchParameters.FirstOrDefault(x => x.Paramter == EnumSearchParameter.LM); if (oparamLM != null) { oparamLM.DataType = EnumSearchObjDataType.Number; oparamLM.ParameterValue = currentUser.EmployeeID; oparamLM.Paramter = EnumSearchParameter.LM; oparamLM.SqlOperator = EnumSQLOperator.EqualTo; } try { omanager.checkDataPermission = currentUser.hasDataPermission; omanager.userid = currentUser.UserID; olist = _serachManager.Find(omanager); //omanager.checkDataPermission = false; #region data permission //List datapermissions = new DataPermissionService().Get(currentUser.UserID, // (int)currentUser.PayrollTypeID); //if (datapermissions != null && datapermissions.Count != 0) //{ // List items = new List(); // foreach (var dataItem in olist) // { // foreach (DataPermission item in datapermissions) // { // switch (item.PermissionType) // { // case EnumDataPermissionType.Cagtegory: // if (dataItem.CategoryID == item.ReferenceID) // items.Add(dataItem); // break; // case EnumDataPermissionType.Department: // if (dataItem.designationID == item.ReferenceID) // items.Add(dataItem); // break; // case EnumDataPermissionType.Grade: // if (dataItem.GradeID == item.ReferenceID) // items.Add(dataItem); // break; // case EnumDataPermissionType.Location: // if (dataItem.LocationID == item.ReferenceID) // items.Add(dataItem); // break; // } // } // } // olist = items; //} #endregion //if (omanager.withName) //{ // int? payrolltypeid = null; // if(currentUser.PayrollTypeID != null ) // payrolltypeid = (int)currentUser.PayrollTypeID; // else if (oparam != null) // payrolltypeid =Convert.ToInt32( oparam.ParameterValue); // if (payrolltypeid != null) // { // List grades = new GradeService().Get(EnumStatus.Regardless, (int)payrolltypeid); // List designations = // new DesignationService().Get(EnumStatus.Regardless, (int)payrolltypeid); // List departments = // new DepartmentService().Get(EnumStatus.Regardless, (int)payrolltypeid); // olist.ForEach(x => // { // var grd = grades.FirstOrDefault(d => d.ID == x.GradeID); // if (grd != null) x.gradeName = grd.Name; // var designation = designations.FirstOrDefault(d => d.ID == x.designationID); // if (designation != null) x.designationName = designation.Name; // var department = departments.FirstOrDefault(d => d.ID == x.DepartmentID); // if (department != null) x.departmentName = department.Name; // }); // } //} if (omanager.searchForSalary) { if (olist != null) { List salaries = new SalaryMonthlyService().GetWithoutDetail((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID); foreach (SalaryMonthly sl in salaries) { olist.RemoveAll(x => x.EmployeeID == sl.EmployeeID); } } } if (omanager.searchUndoSalary) { if (olist != null) { List salaries = new SalaryMonthlyService().GetWithoutDetail((DateTime)currentUser.NextPayProcessDate, (int)currentUser.PayrollTypeID); olist = salaries.Join(olist, sm => sm.EmployeeID, se => se.EmployeeID, (sm, se) => se).ToList(); } } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpPost] [Route("saveEmployee")] public ActionResult SaveEmployee(Employee item) { int ans; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew == true) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } try { ans = _EmployeeService.Save(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ans); } [HttpPost] [Route("saveHnmEmployee")] public ActionResult saveHnmEmployee(Employee item) { int ans; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DateTime ModifiedDate = new DateTime(); ModifiedDate = DateTime.Today; int ModifiedBy = currentUser.UserID; EmpContact empContact = null; if (item.IsNew == true) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } if (!String.IsNullOrEmpty(item.Address)) { empContact = new EmpContact(); empContact.PermanentAddress = item.Address; } List employeeData = new List(); employeeData.Add(item); employeeData.Add(empContact); try { new EmployeeService().SaveHnmEmployee(employeeData); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("saveEmployeeList")] public ActionResult SaveEmployeeList(List items) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { foreach (var item in items) { if (item.IsNew == true) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } _EmployeeService.Save(item); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("saveHrEmployee")] public ActionResult SaveHrEmployee(HREmployee item) { List items = new List(); items.Add(item); try { _hrEmployeeService.Save(items); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("deleteChildData")] public ActionResult DeleteChildData(dynamic data) { var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int id = item["id"].ToObject(); string tableName = (string)item["tableName"].ToObject(); string columnName = (string)item["columnName"].ToObject(); try { _hrEmployeeService.DeleteChildData(tableName, columnName, id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost] [Route("saveEmployeeContact")] public ActionResult saveEmployeeContact(EmpContact item) { try { item.ID = _hrEmployeeService.SaveContact(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("saveEmployeeSpouce")] public ActionResult saveEmployeeSpouce(EmpSpouse item) { try { item.ID = _hrEmployeeService.SaveSpouce(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("saveEmployeechildren")] public ActionResult saveEmployeechildren(EmpChildren item) { try { item.ID = _hrEmployeeService.Savechildren(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("saveEmployeeAcademic")] public ActionResult saveEmployeeAcademic(EmpAcademic item) { try { if (item.InstituteName == "") { item.InstituteName = _institutionService.Get(item.InstitutionID).Name; } item.ID = _hrEmployeeService.SaveAcademic(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("saveExperience")] public ActionResult saveExperience(EmpExperience item) { try { item.ID = _hrEmployeeService.SaveExperience(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpGet("getEmpExperiences/{empId}")] public ActionResult GetEmpExperiences(int empId) { List empExperiences = null; try { empExperiences = _hrEmployeeService.GetEmpExperiences(empId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(empExperiences); } [HttpPost] [Route("UpdateAcountApprovalStatus")] public ActionResult UpdateAcountApprovalStatus(List bankacpounts) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollId = currentUser.PayrollTypeID.GetValueOrDefault(); try { _employeeBankAccountService.UpdateAcountApprovalStatus(bankacpounts); return Ok(true); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } [HttpGet] [Route("getSearchEmployeesByEmpIds/{empIds}")] public ActionResult GetSearchEmployeesByEmpIds(string empIds) { List items = new List(); List empIdList = new List(); var stringArray = empIds.Split(','); foreach (var s in stringArray) { empIdList.Add(Int32.Parse(s)); } try { items = _serachManager.GetSelectedSearchEmployee(empIdList); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost] [Route("saveEployeeTraining")] public ActionResult saveEployeeTraining(EmpTraining item) { try { item.ID = _hrEmployeeService.SaveEmpTraining(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpPost] [Route("saveHrPersonalInfo")] public ActionResult saveHrPersonalInfo(HREmployee item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew == true) { item.PayrollTypeID = (int)currentUser.PayrollTypeID; item.CreatedDate = DateTime.Today; item.CreatedBy = currentUser.UserID; } else { item.ModifiedDate = DateTime.Today; item.ModifiedBy = currentUser.UserID; } try { _hrEmployeeService.SavePersonalInfo(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item.ID); } [HttpGet] [Route("getSearchEmployeebyid/{empid}")] public ActionResult getSearchEmployeebyid(int empid) { SearchEmployee olist = new SearchEmployee(); try { olist = _serachManager.get(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpGet] [Route("getLineManager/{empid}")] public ActionResult GetLineManager(int empid) { Employee item = new Employee(); if (empid == 0) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); empid = currentUser.EmployeeID.GetValueOrDefault(); } try { item = _EmployeeService.GetLineManager(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet] [Route("getByLineManager/{empid}")] public ActionResult GetByLineManager(int empid) { List item = new List(); if (empid == 0) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); empid = currentUser.EmployeeID.GetValueOrDefault(); } try { item = _EmployeeService.GetSubordinatesByLineManager(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet] [Route("getSearchEmpbyLoginid")] public ActionResult getSearchEmpbyLoginid() { SearchEmployee olist = new SearchEmployee(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { olist = _serachManager.get((int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpGet] [Route("getMyTeamByLoginID")] public ActionResult getMyTeamByLoginID() { List items = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _serachManager.GetTeam((int)currentUser.EmployeeID, EnumStatus.Active); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet] [Route("getMyTeamByLoginIDForAttnReguApprove")] public ActionResult getMyTeamByLoginIDForAttnReguApprove() { List items = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { items = _serachManager.GetTeamForAttnReguApprove((int)currentUser.EmployeeID, EnumStatus.Active); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost] [Route("getSelectedSearchEmployees")] public ActionResult GetSelectedSearchEmployees(dynamic data) { List items = new List(); var empids = JsonConvert.DeserializeObject>(data.dataList.ToString()); try { items = _serachManager.GetSelectedSearchEmployee(empids); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpPost] [Route("getSearchEmployeesByIDs")] public ActionResult getSearchEmployeesByIDs(dynamic data) { List items = new List(); var empids = JsonConvert.DeserializeObject>(data.ToString()); try { items = _serachManager.GetSelectedSearchEmployee(empids); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("GetEmployeeNotYetUser/{payrollTypeID}")] public ActionResult GetEmployeeNotYetUser(int payrollTypeID) { List items = new List(); try { items = this._serachManager.GetEmployeeNotYetUser(payrollTypeID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } [HttpGet("getEmpCodeName/{code}/{name}")] public ActionResult getEmpCodeName(string code, string name) { code = GlobalFunctions.GetApiDefaultData(code); name = GlobalFunctions.GetApiDefaultData(name); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List olist = new List(); try { olist = _serachManager.FindEmpCodeName((int)currentUser.PayrollTypeID, code, name); //List grades = new GradeService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); //List designations = new DesignationService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); //List departments = new DepartmentService().Get(EnumStatus.Regardless, (int)currentUser.PayrollTypeID); //olist.ForEach(x=> //{ // var grd = grades.FirstOrDefault(d => d.ID == x.GradeID); // if(grd != null) x.gradeName = grd.Name; // var designation = designations.FirstOrDefault(d => d.ID == x.designationID); // if (designation != null) x.designationName = designation.Name; // var department = departments.FirstOrDefault(d => d.ID == x.DepartmentID); // if (department != null) x.departmentName = department.Name; //}); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(olist); } [HttpGet("getEmployeeAttachments/{empId}")] public ActionResult GetEmployeeAttachments(int empId) { List items = new List(); try { items = _hrEmployeeService.GetAllAttachmentsById(empId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getEmployeeAttachmentByType/{empId}/{refId}/{type}")] public ActionResult GetEmployeeAttachmentByType(int empId, int refId, enumEmpFileUploadType type) { empFileupload item = new empFileupload(); try { item = _hrEmployeeService.GetAttachmentsByType(empId, refId, type); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getHREmployeeID/{empid}")] public ActionResult getHREmployeeID(int empid) { HREmployee ohrEmp = new HREmployee(); try { ohrEmp = this._hrEmployeeService.Get(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ohrEmp); /*this._hrEmployeeService.Get(empid) var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); HREmployeeService service = new HREmployeeService(); string employeeNo = (string)item["employeeNo"].ToObject(); /*employeeCode = (employeeCode == "undefined" || employeeCode == "null") ? string.Empty : employeeCode; employeeName = (employeeName == "undefined" || employeeName == "null") ? string.Empty : employeeName;#1# return service.GetEmployeeByCode(employeeNo);*/ } [HttpGet("getHREmployee")] public ActionResult GetHREmployee() { HREmployee item = new HREmployee(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); try { item = this._hrEmployeeService.Get(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getCurrentEmployee")] public ActionResult GetCurrentEmployee() { Employee item = new Employee(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); try { item = this._EmployeeService.Get(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getEmployeeForDashboard")] public ActionResult GetEmployeeForDashboard() { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); try { item = this._cashManager.Get(enumMemoryCashType.LandingPageEmployee, enumMemoryCashNature.EmployeeWise, employeeId); if (item == null) { item = this._EmployeeService.GetEmployeeForDashboard(employeeId); this._cashManager.Set(item, enumMemoryCashType.LandingPageEmployee, enumMemoryCashNature.EmployeeWise, employeeId); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getNewJoiners")] public ActionResult GetNewJoiners() { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = this._cashManager.Get(enumMemoryCashType.newJoiner, enumMemoryCashNature.Global); if (item == null) { item = this._EmployeeService.GetNewJoiners((int)currentUser.PayrollTypeID); this._cashManager.Set(item, enumMemoryCashType.newJoiner, enumMemoryCashNature.Global); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getNewJoinersWithSearchText/{searchText}")] public ActionResult GetNewJoinersWithSearchText(string searchText) { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = this._EmployeeService.GetNewJoinersWithSearchText(searchText, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getEmployeeByLinemanagerId/{linemanagerId}/{teamType}")] public ActionResult GetEmployeeByLinemanagerId(int linemanagerId, int teamType) { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { item = this._EmployeeService.GetEmployeeByLinemanagerId(linemanagerId, teamType, (int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getEmployeeActivitiesForDashboard")] public ActionResult getEmployeeActivitiesForDashboard() { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); try { item = this._cashManager.Get(enumMemoryCashType.LandingPageActivity, enumMemoryCashNature.EmployeeWise, employeeId); if (item == null) { item = this._EmployeeService.GetEmployeeActivitiesForDashboard(employeeId); this._cashManager.Set(item, enumMemoryCashType.LandingPageActivity, enumMemoryCashNature.EmployeeWise, employeeId); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } [HttpGet("getUserForLandingPage")] public ActionResult GetUserForLandingPage() { DataTable item = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int userId = currentUser.UserID; try { item = this._EmployeeService.GetUserForLandingPage(userId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(item); } /// /// Function will return 'Employee' Object /// /// /// [HttpGet("getEmployeeByID/{empid}")] public ActionResult getEmployeeByID(int empid) { Employee ohrEmp = null; try { ohrEmp = this._EmployeeService.Get(empid); if (ohrEmp.LineManagerID != null) { Employee linemanager = this._EmployeeService.Get((int)ohrEmp.LineManagerID); ohrEmp.LineManager = linemanager.Name; ohrEmp.LineManagerNo = linemanager.EmployeeNo; } if (ohrEmp.DesignationID != null) { ohrEmp.Designation = _designationService.Get((int)ohrEmp.DesignationID); ohrEmp.DesignationName = ohrEmp.Designation?.Name; } if (ohrEmp.GradeID != null) { ohrEmp.Grade = new GradeService().Get((int)ohrEmp.GradeID); ohrEmp.GradeName = ohrEmp.Grade?.Name; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ohrEmp); } [HttpGet("getEmployeeDetailByEmpID/{empid}")] public ActionResult GetEmployeeDetailByEmpID(int empid) { Employee emp = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); string empIds = Convert.ToString(empid); try { emp = this._EmployeeService.Get(empid); int? payrolltypeid = null; if (currentUser.PayrollTypeID != null) payrolltypeid = (int)currentUser.PayrollTypeID; if (payrolltypeid != null) { List grades = new GradeService().Get(EnumStatus.Regardless, (int)payrolltypeid); List designations = new DesignationService().Get(EnumStatus.Regardless, (int)payrolltypeid); List departments = new DepartmentService().Get(EnumStatus.Regardless, (int)payrolltypeid); var grd = grades.FirstOrDefault(d => d.ID == emp.GradeID); var designation = designations.FirstOrDefault(d => d.ID == emp.DesignationID); var department = departments.FirstOrDefault(d => d.ID == emp.DepartmentID); emp.GradeName = grd != null ? grd.Name : ""; emp.DepartmentName = department != null ? department.Name : ""; emp.DesignationName = designation != null ? designation.Name : ""; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(emp); } /// /// Function will return 'Employee' Object /// /// /// [HttpGet("getLoginEmployee")] public ActionResult getLoginEmployee() { Employee ohrEmp = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (currentUser.EmployeeID == null) { return StatusCode(StatusCodes.Status500InternalServerError, "Employee Not Found"); } try { ohrEmp = this._EmployeeService.Get((int)currentUser.EmployeeID); if (ohrEmp.DesignationID != null) { ohrEmp.DesignationName = _designationService.Get((int)ohrEmp.DesignationID).Name; } if (ohrEmp.DepartmentID != null) { ohrEmp.DepartmentName = _departmentService.Get((int)ohrEmp.DepartmentID).Name; } if (ohrEmp.LineManagerID != null) { Employee linemanager = this._EmployeeService.Get((int)ohrEmp.LineManagerID); ohrEmp.LineManager = linemanager.Name; ohrEmp.LineManagerNo = linemanager.EmployeeNo; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ohrEmp); } // Employee Bank Account [HttpGet("getAllBankAccount")] public ActionResult GetAllBankAccount() { List employeeBankAccountList = new List(); try { employeeBankAccountList = _employeeBankAccountService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccountList); } [HttpGet("getBankAccount/{id}/{effectDate}/{payrollTypeID}")] public ActionResult GetBankAccount(int id, DateTime effectDate, int payrollTypeID) { EmployeeBankAccount employeeBankAccount = new EmployeeBankAccount(); try { employeeBankAccount = _employeeBankAccountService.Get(id, effectDate, payrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccount); } [HttpPost("getBankAccountByDate")] public ActionResult GetBankAccountByDate(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeID = currentUser.PayrollTypeID.GetValueOrDefault(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime fromDate = (DateTime)items["fromDate"].ToObject(); DateTime toDate = (DateTime)items["toDate"].ToObject(); List employeeBankAccountList = new List(); try { employeeBankAccountList = _employeeBankAccountService.GetByDate(fromDate, toDate, payrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccountList); } [HttpPost("getBankAccountForApproval")] public ActionResult getBankAccountForApproval(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeID = currentUser.PayrollTypeID.GetValueOrDefault(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); List employeeBankAccountList = new List(); try { employeeBankAccountList = _employeeBankAccountService.getBankAccountForApproval(payrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccountList); } [HttpGet("getBankAccountByEmpID/{EmpID}")] public ActionResult getBankAccountByEmpID(int EmpID) { List employeeBankAccountList = new List(); try { employeeBankAccountList = _employeeBankAccountService.GetByEmployeeID(EmpID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccountList); } [HttpGet("getBankAccountByEmpIDAndType/{EmpID}/{AccountType}")] public ActionResult getBankAccountByEmpIDAndType(int EmpID, int AccountType) { List employeeBankAccountList = new List(); try { employeeBankAccountList = _employeeBankAccountService.GetByEmployeeIDAndType(EmpID, AccountType); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeBankAccountList); } [HttpPost("saveEmpNominee")] public ActionResult SaveEmpNominee(EmpNominee item) { int id = 0; try { id = _hrEmployeeService.SaveEmpNominee(item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(id); } [HttpPost("DeleteEmpNominee")] public ActionResult DeleteEmpNominee(EmpNominee item) { try { _hrEmployeeService.DeleteChildData("EMPNOMINEE", "NOMINEEID", item.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(true); } [HttpGet("getBankAccountById/{id}")] public ActionResult GetBankAccountById(int id) { EmployeeBankAccount bankAccount = new EmployeeBankAccount(); try { bankAccount = _employeeBankAccountService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(bankAccount); } [HttpPost] [Route("saveBankAccount")] public ActionResult SaveBankAccount(EmployeeBankAccount bankAccount) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (bankAccount.IsNew) { bankAccount.CreatedBy = currentUser.UserID; bankAccount.CreatedDate = DateTime.Today; } else { bankAccount.ModifiedBy = currentUser.UserID; bankAccount.ModifiedDate = DateTime.Today; } try { _employeeBankAccountService.Save(bankAccount); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(bankAccount.ID); } [HttpPost] [Route("deleteBankAccount")] public ActionResult deleteBankAccount(EmployeeBankAccount bankAccount) { try { //CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); //if(bankAccount.EffectDate <= currentUser.LastPayProcessDate){} _employeeBankAccountService.Delete(bankAccount.ID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } // Employee Cost Center [HttpGet("getCostCenterById/{id}")] public ActionResult GetCostCenterById(int id) { EmployeeCostCenter employeeCostCenter = new EmployeeCostCenter(); try { employeeCostCenter = _employeeCostCenterService.Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenter); } [HttpGet("getAllEmployeeCostCenter")] public ActionResult GetAllEmployeeCostCenter() { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } [HttpGet("getCostCenterByEmpId/{id}")] public ActionResult GetCostCenterByEmpId(int id) { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.GetByEmpID(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } [HttpGet("getCostCenterByCCId/{id}")] public ActionResult GetCostCenterByCCId(int id) { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.GetByCCID(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } [HttpGet("getCostCenterByEmpIdCCId/{ccid}/{empId}")] public ActionResult GetCostCenterByEmpIdCCId(int ccid, int empId) { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.GetByEmpIDCCID(ccid, empId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } [HttpGet("getCurrentHeadCount/{departmentId}/{designationId}/{gradeId}")] public ActionResult GetCurrentHeadCount(int departmentId, int designationId, int gradeId) { int empCount = 0; try { empCount = _EmployeeService.GetCurrentHeadCount(departmentId, designationId, gradeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(empCount); } [HttpPost] [Route("saveCostCenter")] public ActionResult SaveCostCenter(EmployeeCostCenter costCenter) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (costCenter.IsNew) { costCenter.CreatedBy = currentUser.UserID; costCenter.CreatedDate = DateTime.Today; } else { costCenter.ModifiedBy = currentUser.UserID; costCenter.ModifiedDate = DateTime.Today; } try { _employeeCostCenterService.Save(costCenter); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(costCenter); } [HttpPost] [Route("saveCostCenterList")] public ActionResult SaveCostCenterList(List costCenters) { try { _employeeCostCenterService.Save(costCenters); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(costCenters); } [HttpPost] [Route("deleteCostCenterById")] public ActionResult DeleteCostCenterById(int id) { try { _employeeCostCenterService.Delete(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet("getCostCenterByMonthStartEnd/{start}/{end}/{payrollTypeId}")] public ActionResult GetCostCenterByMonthStartEnd(DateTime start, DateTime end, int payrollTypeId) { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.GetByMonthStartEnd(start, end, payrollTypeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } [HttpGet("getCostCenter/{costCenter}/{id}")] public ActionResult GetCostCenter(List costCenters, int id) { List employeeCostCenters = new List(); try { employeeCostCenters = _employeeCostCenterService.Get(costCenters, id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeCostCenters); } // Hr DashBoard [HttpGet("getMaritalStats")] public ActionResult GetMaritalStats() { List list = new List(); try { list = _hrEmployeeService.GetMaritalStats(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(list); } [HttpGet("getEmployeeMaleAgeStat")] public ActionResult GetEmployeeMaleAgeStat() { List list = new List(); try { list = _hrEmployeeService.GetEmployeeMaleStatByAge(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(list); } [HttpGet("getEmployeeFemaleAgeStat")] public ActionResult GetEmployeeFemaleAgeStat() { List list = new List(); try { list = _hrEmployeeService.GetEmployeeFemaleStatByAge(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(list); } [HttpGet("getChildrenCount")] public ActionResult GetChildrenCount() { List list = new List(); try { list = _hrEmployeeService.GetChildrenCount(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(list); } [HttpGet("getAcademicStat")] public ActionResult GetAcademicStat() { List list = new List(); try { list = _hrEmployeeService.GetAcademicStat(); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(list); } [HttpGet("getProfileCompletePercentage")] public ActionResult GetProfileCompletePercentage() { int ans; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int empId = currentUser.EmployeeID.GetValueOrDefault(); try { ans = _hrEmployeeService.GetProfileCompletePercentage(empId); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(ans); } [HttpGet("getEmpBasicInfo/{empIds}")] public ActionResult GetEmpBasicInfo(string empIds) { DataSet ds = new DataSet(); List employeeBasicInfos = new List(); try { ds = _EmployeeService.GetEmpBasicInfo(empIds); var list = ds.Tables[0].AsEnumerable() .Select(row => new EmployeeBasicInfo { EmployeeNo = row.Field("EMPLOYEENO"), Name = row.Field("NAME"), Gender = row.Field("GENDER"), RName = row.Field("RName"), BirthDate = row.Field("BIRTHDATE"), JoiningDate = row.Field("JOININGDATE"), // DateOfConfirmation = row.Field("DATEOFCONFIRMATION"), MaritalStatusId = row.Field("MARITALSTATUSID") }).ToList(); employeeBasicInfos = list; } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(employeeBasicInfos); } [HttpGet("getAllEmps")] public ActionResult GetAllEmps() { List employeeList = new List(); try { employeeList = _EmployeeService.GetAllEmps(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeList); } [HttpPost("uploadEmpFile")] //[AllowAnonymous] public ActionResult uploadEmpFile() { empFileupload item = new empFileupload(); string base64String = ""; try { bool directoryUpload = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "attachments", "directoryupload"); var fdata = Request.Form.Files["empfile"]; //Upload Image item.employeeID = Convert.ToInt32(Request.Form["empid"]); item.emplyeeNo = Request.Form["emplyeeNo"].ToString(); if (string.IsNullOrWhiteSpace(item.emplyeeNo)) { // The Angular caller does not post emplyeeNo; without this the photo below // would be written to the thumbnail folder under an empty name. item.emplyeeNo = GetEmployeeNo(item.employeeID); } item.referenceID = Convert.ToInt32(Request.Form["referenceid"]); item.filetype = (enumEmpFileUploadType)Convert.ToInt32(Request.Form["filetype"]); byte[] textAsBytes = null; using (var ms = new MemoryStream()) { fdata.CopyTo(ms); item.fileData = ms.ToArray(); item.fileName = item.filetype.ToString() + $" {item.referenceID}{Path.GetExtension(fdata.FileName)}"; if (item.filetype == enumEmpFileUploadType.Education) { EmpAcademic empAcademicData = _hrEmployeeService.GetEmpAcademic(item.referenceID); if (empAcademicData != null) { item.fileName = _educationLevelService.Get(empAcademicData.EducationLevelID).Description + $"{Path.GetExtension(fdata.FileName)}"; } } } this._hrEmployeeService.uplaodFile(item); if (item.filetype == enumEmpFileUploadType.photo && !string.IsNullOrWhiteSpace(item.emplyeeNo)) { // Without an employee number there is nowhere to file the photo; the row is // already saved, and the first read will build the thumbnail from it. EmployeePhotoService osrv = new EmployeePhotoService(_env); osrv.GenerateThumbnail(item.emplyeeNo, (byte[]) item.fileData,100); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(base64String); } [HttpPost("uploadEmpFileInProfileUpdate")] //[AllowAnonymous] public ActionResult UploadEmpFileInProfileUpdate() { empFileupload item = new empFileupload(); string base64String = ""; try { var fdata = Request.Form.Files["empfile"]; //Upload Image // Lower-cased so the cases below also match a file named e.g. "photo.JPG". string extension = Path.GetExtension(fdata.FileName).ToLowerInvariant(); switch (extension) { case ".png": case ".jpg": case ".jpeg": item.FileFormat = EnumFileFormat.Picture; break; case ".pdf": item.FileFormat = EnumFileFormat.Pdf; break; default: break; } item.fileName = Request.Form["fileName"] + extension; item.employeeID = Convert.ToInt32(Request.Form["empid"]); item.referenceID = Convert.ToInt32(Request.Form["referenceid"]); //if (item.referenceID == 0) item.referenceID = null; item.filetype = (enumEmpFileUploadType)Convert.ToInt32(Request.Form["filetype"]); using (var ms = new MemoryStream()) { fdata.CopyTo(ms); item.fileData = ms.ToArray(); byte[] textAsBytes = ms.ToArray(); if (item.filetype == enumEmpFileUploadType.photo) { // Profile pictures are held on disk, not in empFileuploadUpdateRequest: // the submitted file waits in the pending folder under the employee's // number until an admin approves it on the profile-update screen. if (item.FileFormat != EnumFileFormat.Picture) return BadRequest("Only JPG and PNG images can be used as a profile picture."); string employeeNo = GetEmployeeNo(item.employeeID); if (string.IsNullOrWhiteSpace(employeeNo)) return BadRequest("Employee number not found, profile picture could not be submitted."); new EmployeePhotoService(_env).SavePending(employeeNo, textAsBytes, extension); } else { this._hrEmployeeService.UplaodFileInProfileUpdate(item); } base64String = Convert.ToBase64String(textAsBytes); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(base64String); } /// /// Employee number is what every photo on disk is keyed by, but the upload/read endpoints /// are all called with the internal employee id. /// private string GetEmployeeNo(int employeeID) { SearchEmployee employee = this._serachManager.get(employeeID); return employee == null ? string.Empty : employee.EmployeeNo; } [HttpGet("GetCompanyImage")] public ActionResult GetCompanyImage() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); byte[] img = this._payrollTypeService.GetCompanyImage((int)currentUser.PayrollTypeID); if (img != null) { string base64String = ""; if (img != null) { base64String = Convert.ToBase64String(img); } return Ok(base64String); } else return Ok(""); } [HttpGet] [Route("GetPayrollTypeNameByLoginID")] public ActionResult GetPayrollTypeNameByLoginID() { string payrollType = string.Empty; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { payrollType = this._payrollTypeService.Get((int)currentUser.PayrollTypeID).CompanyName; return Ok(payrollType); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } /// /// The approved photo as a plain image response, so it can be used directly as an /// <img src> instead of being inlined as base64. Anonymous because an img tag /// carries no bearer token; the files themselves already sit under wwwroot and are /// served by UseStaticFiles without auth, so this exposes nothing new. /// [HttpGet("empPhotoFile/{empNo}")] //[AllowAnonymous] public IActionResult GetEmpPhotoFile(string empNo) { string path = new EmployeePhotoService(_env).FindApprovedFile(empNo); if (path == null) return NotFound(); // A ?v= stamp (handed out by empPhotosBatch) identifies one exact version of the file, // so that URL can be cached indefinitely: when the photo changes the stamp changes and // the browser fetches a different URL. Without a stamp the URL is not version-specific, // so it only gets a short life and relies on the ETag to revalidate cheaply. Response.Headers.Append("Cache-Control", Request.Query.ContainsKey("v") ? "public, max-age=31536000, immutable" : "public, max-age=300"); return PhotoFile(path); } /// /// For a whole roster at once (team list, new joiners): which of these employees has a /// photo, and a version stamp for each. This carries no image data — just enough for the /// caller to build a version-specific URL that the browser can then cache permanently. /// /// The images themselves still load as ordinary URLs, so they stay cacheable and lazy /// loadable; this call only saves the guesswork of requesting photos that do not exist. /// /// Called from Angular with the bearer token, so it sits behind the controller's /// [Authorize]. Employees with no photo are left out; the caller shows its default avatar. /// [HttpPost("empPhotosBatch")] public IActionResult GetEmpPhotosBatch([FromBody] List employeeNos) { var photos = new List(); if (employeeNos == null || employeeNos.Count == 0) return Ok(photos); // Generous, because a response row is an employee number and a short stamp — a few // dozen bytes. The old limit of 500 dated from when this returned the images // themselves, and a 500-strong team was enough to fail the whole card. if (employeeNos.Count > 20000) return BadRequest("Too many employees requested in one batch."); var osrv = new EmployeePhotoService(_env); foreach (string employeeNo in employeeNos.Where(x => !string.IsNullOrWhiteSpace(x)).Distinct()) { string path = osrv.FindApprovedFile(employeeNo); if (path == null) continue; photos.Add(new { employeeNo, v = System.IO.File.GetLastWriteTimeUtc(path).Ticks.ToString("x") }); } return Ok(photos); } /// /// The photo waiting for approval, for the profile-update approval screen. /// Always revalidated: an approver must never act on a stale image. /// [HttpGet("empPendingPhotoFile/{empNo}")] //[AllowAnonymous] public IActionResult GetEmpPendingPhotoFile(string empNo) { string path = new EmployeePhotoService(_env).FindPendingFilePath(empNo); if (path == null) return NotFound(); Response.Headers.Append("Cache-Control", "no-cache"); return PhotoFile(path); } /// /// Serves the file with validators, so ASP.NET Core answers a repeat request with 304. /// private IActionResult PhotoFile(string path) { var lastModified = new DateTimeOffset(System.IO.File.GetLastWriteTimeUtc(path)); var length = new FileInfo(path).Length; var etag = new Microsoft.Net.Http.Headers.EntityTagHeaderValue( $"\"{lastModified.ToUnixTimeMilliseconds():x}-{length:x}\""); string contentType = Path.GetExtension(path).ToLowerInvariant() == ".png" ? "image/png" : "image/jpeg"; return PhysicalFile(path, contentType, lastModified, etag); } [HttpGet("GetuploadEmpPhoto/{empNo}")] public async Task GetuploadEmpPhoto(string empNo) { var osrv = new EmployeePhotoService(_env); // 1. Folder cache hit — fastest path if (osrv.ThumbnailExists(empNo)) { var cached = await osrv.GetThumbnailAsync(empNo); if (cached != null) { Response.Headers.Append("Cache-Control", "public, max-age=86400"); return File(cached.Value.Bytes, "image/jpeg"); } } // 2. Cache miss — check DB for the actual photo //var item = this._hrEmployeeService.getuploadedFile(empNo, 0, enumEmpFileUploadType.photo); //if (item != null) //{ // byte[] fullBytes = (byte[])item.fileData; // byte[] thumbBytes = osrv.GenerateThumbnail(empNo, fullBytes, 100); // // GenerateThumbnail should already save to folder internally, per earlier version — // // if not, call osrv.SaveThumbnailToFolder(empNo, thumbBytes) explicitly here // Response.Headers.Append("Cache-Control", "public, max-age=86400"); // return File(thumbBytes, "image/jpeg"); //} // 3. Genuinely no photo on record — let Angular's (error) handler show initials return NoContent(); } [HttpGet("GetuploadEmpFile/{empid}/{referenceid}/{filetype}")] public ActionResult GetuploadEmpFile(int empid, int referenceid, enumEmpFileUploadType filetype) { EmployeePhotoService osrv = new EmployeePhotoService(_env); SearchEmployee searchEmployee = null; if ( filetype == enumEmpFileUploadType.photo) { searchEmployee = new SearchEmployeeService().get(empid); if (searchEmployee != null && osrv.ThumbnailExists(searchEmployee.EmployeeNo)) { var thumbnail = osrv.GetThumbnailAsync(searchEmployee.EmployeeNo).Result; if (thumbnail != null) { string base64String = Convert.ToBase64String(thumbnail.Value.Bytes); return Ok(base64String); } } } empFileupload item = new empFileupload(); item = this._hrEmployeeService.getuploadedFile(empid, referenceid, filetype); if (item != null) { byte[] textAsBytes = (byte[])item.fileData; string base64String = ""; if (item != null) { base64String = Convert.ToBase64String(textAsBytes); } if(filetype == enumEmpFileUploadType.photo && searchEmployee != null && !string.IsNullOrWhiteSpace(searchEmployee.EmployeeNo)) { osrv.GenerateThumbnail(searchEmployee.EmployeeNo, (byte[])item.fileData, 100); } return Ok(base64String); } else return Ok(""); } [HttpGet("getUploadEmpFileInProfileUpdate/{empid}/{referenceid}/{filetype}")] public ActionResult GetUploadEmpFileInProfileUpdate(int empid, int referenceid, enumEmpFileUploadType filetype) { empFileupload item = null; if (filetype == enumEmpFileUploadType.photo) { // A pending profile picture lives in the folder, not the request table. string employeeNo = GetEmployeeNo(empid); var pending = new EmployeePhotoService(_env).GetPending(employeeNo); if (pending != null) { return Ok(new empFileupload { employeeID = empid, referenceID = referenceid, filetype = filetype, FileFormat = EnumFileFormat.Picture, emplyeeNo = employeeNo, fileName = pending.Value.FileName, fileData = Convert.ToBase64String(pending.Value.Bytes) }); } // Nothing pending on disk — fall through to the request table so picture requests // raised before this change are still reviewable. } item = this._hrEmployeeService.GetuploadedFileInProfileUpdate(empid, referenceid, filetype); if (item == null) return Ok(); var extension = Path.GetExtension(item.fileName); if (extension == ".pdf") return Ok(item); byte[] textAsBytes = (byte[])item.fileData; string base64String = ""; item.fileData = Convert.ToBase64String(textAsBytes); return Ok(item); } [HttpPost("getEmpDetailInfo")] public ActionResult GetEmpDetailInfo(List selectedEmps) { string empIds = SearchEmployee.getEmpID(selectedEmps); DataSet ds = new DataSet(); List items = new List(); var companyNameObj = new SystemConfigarationService().GetconfigValue(EnumConfigurationType.Logic, "system", "company"); string companyName = Convert.ToString(companyNameObj); try { ds = _EmployeeService.GetEmpDetailsView(empIds); //SystemConfigarationService ocManager = ocManager.GetAllChildrenByParentNode(EnumConfigurationType.Logic, "department"); List oDepartment = new DepartmentService().GetAll(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); foreach (var row in ds.Tables[0].AsEnumerable()) { EmployeeDetailInfo temp = new EmployeeDetailInfo(); Employee emp = new EmployeeService().GetFromAll(row["EMPLOYEENO"].ToString(), (int)currentUser.PayrollTypeID); Department tempDepartment = null; if (emp != null) { tempDepartment = emp.DepartmentID != null ? oDepartment.Find(item => item.ID == emp.DepartmentID) : null; } temp.EmployeeNo = row["EmployeeNo"] == null ? "" : row.Field("EmployeeNo"); temp.Name = row["Name"] == null ? "" : row.Field("Name"); temp.BasicSalary = row["BASICSALARY"] == null ? 0 : row.Field("BASICSALARY"); temp.GrossSalary = row["GrossSalary"] == null ? 0 : row.Field("GrossSalary"); temp.TaxAmount = row["TAXAMOUNT"] == null ? 0 : row.Field("TAXAMOUNT"); temp.FatherName = row["Fathername"] == null ? "" : row.Field("Fathername"); temp.FatherOccupation = row["FatherOccupation"] == null ? "" : row.Field("FatherOccupation"); temp.MotherOccupation = row["MotherOccupation"] == null ? "" : row.Field("MotherOccupation"); temp.MotherName = row["MotherName"] == null ? "" : row.Field("MotherName"); temp.Gender = row["Gender"] == null ? "" : row.Field("Gender"); temp.BirthDate = row["BIRTHDATE"] == null ? null : row.Field("BIRTHDATE"); temp.BirthPlace = row["BIRTHPlace"] == null ? "" : row.Field("BIRTHPlace"); temp.TinNo = row["TINNO"] == null ? "" : row.Field("TINNO"); temp.JoiningDate = row["JOININGDATE"] == null ? null : row.Field("JOININGDATE"); temp.EmailAddress = row["EMAILADDRESS"] == null ? "" : row.Field("EMAILADDRESS"); temp.Category = row["Category"] == null ? "" : row.Field("Category"); temp.Status = row["Status"] == null ? "" : row.Field("Status"); temp.Location = row["Location"] == null ? "" : row.Field("Location"); temp.Division = row["Division"] == null ? "" : row.Field("Division"); temp.Company = row["Company"] == null ? "" : row.Field("Company"); temp.Department = row["Department"] == null ? "" : row.Field("Department"); temp.Section = row["Section"] == null ? "" : row.Field("Section"); Department tire5 = null; Department tire4 = null; Department tire3 = null; Department tire2 = null; Department tire1 = null; if (tempDepartment != null) { if (tempDepartment.ParentID != null) { for (int i = (int)tempDepartment.Tier; i > 0; i--) { if (i == 5) { tire5 = oDepartment.Find(x => x.ID == tempDepartment.ID); } if (i == 4) { if (tire5 != null) { tire4 = oDepartment.Find(x => x.ID == tire5.ParentID); } else { tire4 = oDepartment.Find(x => x.ID == tempDepartment.ID); } } if (i == 3) { if (tire4 != null) { tire3 = oDepartment.Find(x => x.ID == tire4.ParentID); } else { tire3 = oDepartment.Find(x => x.ID == tempDepartment.ID); } } if (i == 2) { if (tire3 != null) { tire2 = oDepartment.Find(x => x.ID == tire3.ParentID); } else { tire2 = oDepartment.Find(x => x.ID == tempDepartment.ID); } } if (i == 1) { if (tire2 != null) { tire1 = oDepartment.Find(x => x.ID == tire2.ParentID); } else { tire1 = oDepartment.Find(x => x.ID == tempDepartment.ID); } } } } temp.deptireOne = (tire1 == null) ? "" : tire1.Name; temp.deptireTwo = (tire2 == null) ? "" : tire2.Name; temp.deptireThree = (tire3 == null) ? "" : tire3.Name; temp.deptireFour = (tire4 == null) ? "" : tire4.Name; temp.deptireFive = (tire5 == null) ? "" : tire5.Name; } temp.Designation = row["DESIGNATION"] == null ? "" : row.Field("DESIGNATION"); temp.Grade = row["GRADE"] == null ? "" : row.Field("GRADE"); temp.Designation = row["DESIGNATION"] == null ? "" : row.Field("DESIGNATION"); temp.Religion = row["Religion"] == null ? "" : row.Field("Religion"); temp.MaritalStatus = row["MaritalStatus"] == null ? "" : row.Field("MaritalStatus"); temp.MobileNo = row["MOBILENO"] == null ? "" : row.Field("MOBILENO"); temp.DateOfConfirmation = row["DATEOFCONFIRMATION"].ToString() == string.Empty ? null : row.Field("DATEOFCONFIRMATION"); temp.NationalId = row["NATIONALID"] == null ? "" : row.Field("NATIONALID"); temp.PassportNo = row["PassPortNo"] == null ? "" : row.Field("PassPortNo"); temp.PhotoPath = row["PhotoPath"] == null ? "" : row.Field("PhotoPath"); temp.BloodGroup = row["bloodgroup"] == null ? GlobalExtensions.BloodGroupToFriendlyName(EnumBloodGroup.None) : GlobalExtensions.BloodGroupToFriendlyName((EnumBloodGroup)row.Field("bloodgroup")); temp.LineManagerNo = row["LineManagerNo"] == null ? "" : row.Field("LineManagerNo"); temp.LineManagerName = row["LineManagerName"] == null ? "" : row.Field("LineManagerName"); temp.LineManagerEmail = row["LineManagerEmail"] == null ? "" : row.Field("LineManagerEmail"); temp.LineManagerDes = row["LineManagerDes"] == null ? "" : row.Field("LineManagerDes"); temp.LmDivision = row["lmDivision"] == null ? "" : row.Field("lmDivision"); temp.LineManagerName = row["LineManagerName"] == null ? "" : row.Field("LineManagerName"); temp.LmDepartment = row["lmDepartment"] == null ? "" : row.Field("lmDepartment"); temp.EmpStatus = row["EmpStatus"] == null ? "" : row.Field("EmpStatus"); if (row.Table.Columns.Contains("CostCenter")) temp.CostCenter = row["CostCenter"] == null ? "" : row.Field("CostCenter"); temp.Nationality = row["NATIONALITY"] == null ? "" : row.Field("NATIONALITY"); temp.OutPayBank = row["OUTPayBank"] == null ? "" : row.Field("OUTPayBank"); temp.OutPayBranch = row["OUTPayBranch"] == null ? "" : row.Field("OUTPayBranch"); temp.OutPayAccountNo = row["OutPayAccountNo"] == null ? "" : row.Field("OutPayAccountNo"); temp.AccountNo = (row.Field("AccountNo") == null || row.Field("AccountNo") == "") ? temp.OutPayAccountNo : row.Field("ACCOUNTNO"); temp.Bank = (row.Field("Bank") == null || row.Field("Bank") == "") ? temp.OutPayBank : row.Field("Bank"); temp.Branch = (row.Field("Branch") == null || row.Field("Branch") == "") ? temp.OutPayBranch : row.Field("Branch"); items.Add(temp); } } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(items); } //[HttpPost("getEmpApiResponse")] //[AllowAnonymous] //public ActionResult GetEmpApiResponse(EmployeeApiInfo userData) //{ // EmployeeApiInfo employeeApiInfo = _employeeApiInfo.Value; // List employees = new List(); // List empApiResponses = new List(); // List departments = new List(); // List designations = new List(); // List locations = new List(); // List costCenters = new List(); // try // { // if (!(userData.UserId == employeeApiInfo.UserId && userData.Password == employeeApiInfo.Password)) // return BadRequest("UserId or Password Is Invalid"); // employees = _EmployeeService.GetAllEmps(); // departments = _departmentService.GetAll(1); // designations = _designationService.GetAllDesignation(1, EnumStatus.Active, String.Empty, String.Empty); // locations = _locationService.GetLocations(); // costCenters = _costCenterService.Get(); // foreach (var employee in employees) // { // var empApiResponse = new EmpApiResponse(); // empApiResponse.EmpCode = employee.GeId; // empApiResponse.EmpDName = employee.ExtraField1; // empApiResponse.EmpFName = employee.FirstName; // empApiResponse.EmpLName = employee.LastName; // empApiResponse.EmpEmail = employee.EmailAddress; // empApiResponse.EmpMobile = employee.MobileNo; // empApiResponse.PayrollId = employee.EmployeeNo; // empApiResponse.GenderName = Enum.GetName(typeof(EnumGender), employee.Gender); // var dept = departments.Find(x => x.ID == employee.DepartmentID); // empApiResponse.DepartmentName = dept == null ? "" : dept.Name; // var designation = designations.Find(x => x.ID == employee.DesignationID); // empApiResponse.DesignationName = designation == null ? "" : designation.Name; // var lineManager = employees.Find((x => x.ID == employee.LineManagerID)); // empApiResponse.LineManager = lineManager == null ? "" : lineManager.Name; // empApiResponse.BaseStation = Enum.GetName(typeof(EnumBaseStation), employee.ExtraField2); // empApiResponse.VendorCode = employee.VendorCode; // var costCenter = costCenters.Find(x => x.ID == employee.CrgId); // empApiResponse.CostCenterCode = costCenter == null ? "" : costCenter.Code; // empApiResponse.CostCenterName = costCenter == null ? "" : costCenter.Name; // empApiResponse.BaseStation = Enum.GetName(typeof(EnumBaseStation), employee.ExtraField2); // var location = locations.Find(x => x.ID == employee.LocationID); // empApiResponse.Location = location == null ? "" : location.Name; // empApiResponse.TypeName = employee.ExtraField3; // empApiResponse.EmpActive = Enum.GetName(typeof(EnumEmpStatus), employee.Status); // empApiResponse.MinValue = employee.ExtraField4; // empApiResponse.MaxValue = employee.ExtraField5; // empApiResponses.Add(empApiResponse); // } // } // catch (Exception ex) // { // return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); // } // return Ok(empApiResponses); //} [HttpPost("getEmployeesByEmpIDs")] public ActionResult GetEmployeesByEmpIDs(dynamic data) { List employeeList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empIds = (string)item["dataList"].ToObject(); try { employeeList = _EmployeeService.GetByEmpIDs(empIds); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeList); } [HttpPost("updateBanglaInformation")] public ActionResult updateBanglaInformation(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string empNo = (string)item["employeeNo"].ToObject(); string banglaName = (string)item["banglaName"].ToObject(); string banglaSpouseName = (string)item["banglaSpouseName"].ToObject(); string banglaFathersName = (string)item["banglaFathersName"].ToObject(); string banglaMothersName = (string)item["banglaMothersName"].ToObject(); DateTime ModifiedDate = new DateTime(); ModifiedDate = DateTime.Today; int ModifiedBy = currentUser.UserID; List employeBanglaInfo = new List(); employeBanglaInfo.Add(empNo); employeBanglaInfo.Add(banglaName); employeBanglaInfo.Add(banglaSpouseName); employeBanglaInfo.Add(banglaFathersName); employeBanglaInfo.Add(banglaMothersName); employeBanglaInfo.Add(ModifiedDate); employeBanglaInfo.Add(ModifiedBy); try { new EmployeeService().UpdateBanglaInformation(employeBanglaInfo); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpPost("updateBanglaContactInformation")] public ActionResult updateBanglaContactInformation(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); string employeeNo = (string)item["employeeNo"].ToObject(); string presentPOInBangla = (string)item["presentPOInBangla"].ToObject(); string presentAddressInBangla = (string)item["presentAddressInBangla"].ToObject(); string parmanentPOInBangla = (string)item["parmanentPOInBangla"].ToObject(); string permanentAddressInBangla = (string)item["permanentAddressInBangla"].ToObject(); DateTime ModifiedDate = new DateTime(); ModifiedDate = DateTime.Today; int ModifiedBy = currentUser.UserID; List employeBanglaInfo = new List(); employeBanglaInfo.Add(employeeNo); employeBanglaInfo.Add(presentPOInBangla); employeBanglaInfo.Add(presentAddressInBangla); employeBanglaInfo.Add(parmanentPOInBangla); employeBanglaInfo.Add(permanentAddressInBangla); employeBanglaInfo.Add(ModifiedDate); employeBanglaInfo.Add(ModifiedBy); try { new EmployeeService().UpdateBanglaContactInformation(employeBanglaInfo); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet("getEmployeeByIDforHNM/{empid}")] public ActionResult getEmployeeByIDforHNM(int empid) { Employee ohrEmp = null; try { ohrEmp = this._EmployeeService.GetEmployeeForHnm(empid); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ohrEmp); } [HttpPost("getEmployeeDetailByEmpIDs")] public ActionResult GetEmployeeDetailByEmpIDs(dynamic data) { List employeeList = new List(); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); string empIds = (string)item["dataList"].ToObject(); try { employeeList = _EmployeeService.GetByEmpIDs(empIds); int? payrolltypeid = null; if (currentUser.PayrollTypeID != null) payrolltypeid = (int)currentUser.PayrollTypeID; if (payrolltypeid != null) { List grades = new GradeService().Get(EnumStatus.Regardless, (int)payrolltypeid); List designations = new DesignationService().Get(EnumStatus.Regardless, (int)payrolltypeid); List departments = new DepartmentService().Get(EnumStatus.Regardless, (int)payrolltypeid); employeeList.ForEach(x => { var grd = grades.FirstOrDefault(d => d.ID == x.GradeID); if (grd != null) x.GradeName = grd.Name; var designation = designations.FirstOrDefault(d => d.ID == x.DesignationID); if (designation != null) x.DesignationName = designation.Name; var department = departments.FirstOrDefault(d => d.ID == x.DepartmentID); if (department != null) x.DepartmentName = department.Name; }); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeList); } [HttpGet] [Route("getDashBoardGraphData")] public ActionResult GetDashBoardGraphData() { DataSet ds = new DataSet(); try { ds = _EmployeeService.GetDashBoardGraphData(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds); } [HttpGet] [Route("getSelfServiceBasicData")] public ActionResult GetSelfServiceBasicData() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _EmployeeService.GetSelfServiceBasicData(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("getNomineesForEss/{employeeId}")] public ActionResult GetSelfServiceBasicData(int employeeId) { DataTable dt = new DataTable(); try { dt = _hrEmployeeService.GetNomineesForEss(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getTrainingForEss/{employeeId}")] public ActionResult GetTrainingForEss(int employeeId) { DataTable dt = new DataTable(); try { dt = _hrEmployeeService.GetTrainingForEss(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getSelfServiceContactData")] public ActionResult GetSelfServiceContactData() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _EmployeeService.GetSelfServiceContactData(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("getSelfServiceAcademic")] public ActionResult GetSelfServiceAcademic() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfServiceAcademic(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("getSelfServiceFamilyInfo")] public ActionResult GetSelfServiceFamilyInfo() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfServiceFamilyInfo(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("getLandingPageData/{isEmployee}/{isLeave}/{isAttendance}")] public ActionResult GetLandingPageData(int isEmployee, int isLeave, int isAttendance) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _EmployeeService.GetLandingPageData(isEmployee, isLeave, isAttendance, payrollTypeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("GetHolidayInfoForDashboard")] public ActionResult GetHolidayInfoForDashboard() { DataSet ds = new DataSet(); try { ds = _EmployeeService.GetHolidayInfoForDashboard(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet("getOtEligibleEmployees")] public ActionResult GetOtEligibleEmployees() { DataTable dt = new DataTable(); CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); try { dt = _EmployeeService.GetOtEligibleEmployees((int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost("getEmployeeConfirmationData")] public ActionResult getEmployeeConfirmationData(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime fromDate = DateTime.Today; DateTime toDate = DateTime.Today; if (items["fromDate"] != null) fromDate = (DateTime)items["fromDate"].ToObject(); if (items["toDate"] != null) toDate = (DateTime)items["toDate"].ToObject(); List employeeConfirmations = new EmployeeConfirmationService().GetByDateRange(fromDate, toDate, (int)currentUser.PayrollTypeID); return Ok(employeeConfirmations); } [HttpPost] [Route("deleteEmployeeConfirmationData")] public ActionResult DeleteEmployeeConfirmationData(EmployeeConfirmation item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int payrollTypeId = currentUser.PayrollTypeID.GetValueOrDefault(); try { new EmployeeConfirmationService().Delete(item.ID); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpPost] [Route("saveEmployeeConfirmationData")] public ActionResult SaveEmployeeConfirmationData(EmployeeConfirmation item) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); if (item.IsNew == true) { item.CreatedBy = currentUser.UserID; item.CreatedDate = DateTime.Today; // item.PayrollTypeID = (int)currentUser.PayrollTypeID; } else { item.ModifiedBy = currentUser.UserID; item.ModifiedDate = DateTime.Today; } item.ConfirmDate = item.JoiningDate.AddMonths(item.Month + item.gradeConfirmDuration); try { new EmployeeConfirmationService().Save(item); } catch (Exception e) { return StatusCode(StatusCodes.Status500InternalServerError, e.Message); } return Ok(); } [HttpGet] [Route("getMyTeam")] public ActionResult GetMyTeam() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); try { dt = _EmployeeService.GetMyTeam((int)currentUser.EmployeeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getEssLandingpageMyTeam")] public ActionResult getEssLandingpageMyTeam() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); try { dt = this._cashManager.Get(enumMemoryCashType.LandingPageTeamMembers, enumMemoryCashNature.EmployeeWise, id); if (dt == null) { dt = _EmployeeService.GetMyTeam((int)currentUser.EmployeeID); this._cashManager.Set(dt, enumMemoryCashType.LandingPageTeamMembers, enumMemoryCashNature.EmployeeWise, id); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("deletecordinator")] public ActionResult deletecordinator(EmployeeCordinator empCordinator) { try { new EmployeeCordinatorService().Delete(empCordinator); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet] [Route("GetCordinatorTeam")] public ActionResult GetCordinatorTeam() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); Employee oEmp = _EmployeeService.Get(id); try { dt = _EmployeeService.GetCordinatorTeam(oEmp); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getLiveEmployee")] public ActionResult getLiveEmployee() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int id = currentUser.EmployeeID.GetValueOrDefault(); Employee oEmp = _EmployeeService.Get(id); try { dt = _EmployeeService.GetEmployeeCount(oEmp); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getEmpOrganogramInfo")] public ActionResult getEmpOrganogramInfo() { DataTable dt = null; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int? id = currentUser.EmployeeID; int PayrollTypeID = (int)currentUser.PayrollTypeID; Employee oEmp = null; // _EmployeeService.Get(id); if (id != null && currentUser.UserType == EnumUserType.Employee) { oEmp = new Employee(); oEmp.ID = (int)id; } try { dt = _EmployeeService.GetEmpOrganogramInfo(oEmp, PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getEmpInfoForGateman/{ID}")] public ActionResult getEmpInfoForGateman(int id) { //var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); //EnumGatePassStatus status = item["status"].ToObject(); //DateTime fromDate = item["fromDate"].ToObject(); //DateTime toDate = item["toDate"].ToObject(); //CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); DataTable dt = null; try { dt = _EmployeeService.getEmpInfoForGateman(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet] [Route("getupcomingConfirmation/{confirmMonth}")] public ActionResult getEmpInfoForGateman(string confirmMonth) { DateTime salaryMonth = GlobalFunctions.GetApiDefaultDateData(confirmMonth); DataTable dt = null; try { dt = new EmployeeConfirmationService().GetUpComingConfirmation(salaryMonth); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpGet("GetMaternityLeaveEmployee")] public ActionResult GetMaternityLeaveEmployee() { List employeeList = new List(); DateTime fromDate = DateTime.Now.AddDays(-12), toDate = DateTime.Now; ; try { employeeList = _EmployeeService.GetMaternityLeaveEmployee(fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeList); } [HttpPost] [Route("GetMaternityLeaveEmployee")] public ActionResult GetMaternityLeaveEmployee(dynamic data) { List employeeList = new List(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime toDate = items.toDate; DateTime fromDate = items.fromDate; try { //_SchedularSetup = new SchedularSetupService().Get(statusValue, schedulerValue, fromDateValue, toDateValue); employeeList = _EmployeeService.GetMaternityLeaveEmployee(fromDate, toDate); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employeeList); } [HttpGet] [Route("GetCoordinatorList")] public ActionResult GetCoordinatorList() { DataTable oData = null; try { oData = new EmployeeCordinatorService().GetCoordinatorList(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(oData); } [HttpGet] [Route("GetEmployeeByCoordinator/{corID}")] public ActionResult GetEmployeeByCoordinator(int corID) { List employees = null; try { employees = new EmployeeCordinatorService().Get(corID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employees); } [HttpGet] [Route("GetEmployeeByCoordinatorID")] public ActionResult GetEmployeeByCoordinatorID() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List employees = null; int id = (int)currentUser.EmployeeID; try { employees = _EmployeeService.GetEmployeeByCoordinator(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employees); } [HttpGet] [Route("GetLgoinCordinatorEmps")] public ActionResult GetLgoinCordinatorEmps() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); List employees = null; int id = (int)currentUser.EmployeeID; try { employees = new EmployeeCordinatorService().Get(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(employees); } [HttpGet] [Route("GetSchedulerData")] public ActionResult GetSchedulerData() { List _SchedularSetup = null; try { _SchedularSetup = new SchedularSetupService().Get(EnumStatus.Active); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(_SchedularSetup); } [HttpPost] [Route("GetSchedulerBasedOnType")] public ActionResult GetSchedulerBasedOnType(dynamic data) { DataTable dataTable = null; var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); EnumSchedularType schedulerValue = items.scheduler; bool statusValue = items.status; DateTime toDateValue = items.toDate; DateTime fromDateValue = items.fromDate; try { //_SchedularSetup = new SchedularSetupService().Get(statusValue, schedulerValue, fromDateValue, toDateValue); dataTable = new MailSenderErrorListService().GetMailHistory(statusValue, schedulerValue, fromDateValue, toDateValue); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dataTable); } [HttpGet("getAuthorizedPerson")] public ActionResult getAuthorizedPerson() { List items = new List(); try { AuthorizedPersonService AuthorizedPersonService = new AuthorizedPersonService(); items = AuthorizedPersonService.Get(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("getProfilePermission")] public ActionResult getProfilePermission() { List items = new List(); try { string hnmProfilePermission = new SystemConfigarationService().GetconfigStringValue(EnumConfigurationType.UI, "hrinterface", "hnmprofilenotneeded").ToString(); items = hnmProfilePermission.Split(',').ToList(); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(items); } [HttpGet("dashboardAttnRemoved")] public ActionResult DashboardAttnRemoved() { bool attnRemove = false; try { attnRemove = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.UI, "hrinterface", "dashboardattnremove"); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(attnRemove); } [HttpGet("hnmdropdownactive")] public ActionResult hnmdropdownactive() { bool hnmdropdownactive = false; try { hnmdropdownactive = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.UI, "hrinterface", "hnmdropdown"); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(hnmdropdownactive); } [HttpGet("generateEmployeeNo")] public ActionResult GenerateEmployeeNo() { string code = ""; CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); bool autoGenerate = new SystemConfigarationService().GetconfigBooleanValue(EnumConfigurationType.Logic, "employee", "codeautogenerate"); try { if (autoGenerate) code = _EmployeeService.GetNextCode((int)currentUser.PayrollTypeID); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(code); } [HttpGet] [Route("getPFExceptionData")] public ActionResult getPFExceptionData() { List pfExceptions = new List(); try { pfExceptions = new PFExceptionService().Get(); List employees = new EmployeeService().GetAllEmps(); foreach (PFException item in pfExceptions) { item.EmployeeNo = employees.Find(x => x.ID == item.EmployeeID).EmployeeNo; item.EmployeeName = employees.Find(x => x.ID == item.EmployeeID).Name; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(pfExceptions); } [HttpPost("updatePFExceptionData")] public ActionResult updatePFExceptionData(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var item = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); int? id = item["PFExceptionID"].ToObject(); int employeeID = (int)item["employeeID"].ToObject(); int? epfPercent = item["epfPercent"].ToObject(); int? epfAmount = item["epfAmount"].ToObject(); int? cpfPercent = item["cpfPercent"].ToObject(); int? cpfAmount = item["cpfAmount"].ToObject(); PFException pfException = new PFException(); pfException.ID = id == null ? 0 : id.Value; pfException.EmployeeID = employeeID; pfException.EPFPercent = epfPercent == null ? 0 : epfPercent.Value; pfException.EPFAmount = epfAmount == null ? 0 : epfAmount.Value; pfException.CPFPercent = cpfPercent == null ? 0 : cpfPercent.Value; pfException.CPFAmount = cpfAmount == null ? 0 : cpfAmount.Value; pfException.CreatedBy = currentUser.UserID; pfException.StartDate = DateTime.Now; pfException.CreatedDate = DateTime.Now; pfException.ModifiedDate = DateTime.Now; pfException.ModifiedBy = currentUser.UserID; try { new PFExceptionService().Save(pfException); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [HttpGet] [Route("deletePFExceptionById/{id}")] public ActionResult deletePFExceptionById(int id) { try { new PFExceptionService().Delete(id); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(); } [Route("GetAcademicDataByEmployeId/{employeeId}")] public ActionResult GetAcademicDataByEmployeId(int employeeId) { DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfServiceAcademic(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("GetSelfAchievement")] public ActionResult GetSelfAchievement() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfAchievement(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("GetSelfCurricularActivitys")] public ActionResult GetSelfCurricularActivitys() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfCurricularActivitys(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("GetSelfOtherTalents")] public ActionResult GetSelfOtherTalents() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfOtherTalents(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpGet] [Route("GetSelfHobbys")] public ActionResult GetSelfHobbys() { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); int employeeId = currentUser.EmployeeID.GetValueOrDefault(); DataSet ds = new DataSet(); try { ds = _hrEmployeeService.GetSelfHobbys(employeeId); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [Route("SearchOtherQualificationEmp")] [HttpPost] public ActionResult SearchOtherQualificationEmp(SearchOtherQualificationRequest data) { DataSet ds = new DataSet(); try { ds = _hrEmployeeService.SearchOtherQualificationEmp(data.EmpIds, data.QualificationTypeId, data.Item); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(ds.Tables[0]); } [HttpPost("uploadEmpFileFromAdmin")] //[AllowAnonymous] public ActionResult uploadEmpFileFromAdmin() { empFileupload item = new empFileupload(); string base64String = ""; try { var fdata = Request.Form.Files["empfile"]; //Upload Image string extension = Path.GetExtension(fdata.FileName); switch (extension) { case ".png": case ".jpg": case ".jpeg": item.FileFormat = EnumFileFormat.Picture; break; case ".pdf": item.FileFormat = EnumFileFormat.Pdf; break; default: break; } item.fileName = Request.Form["fileName"] + extension; item.employeeID = Convert.ToInt32(Request.Form["empid"]); item.referenceID = Convert.ToInt32(Request.Form["referenceid"]); item.filetype = (enumEmpFileUploadType)Convert.ToInt32(Request.Form["filetype"]); using (var ms = new MemoryStream()) { fdata.CopyTo(ms); item.fileData = ms.ToArray(); byte[] textAsBytes = ms.ToArray(); this._hrEmployeeService.uplaodFile(item); base64String = Convert.ToBase64String(textAsBytes); } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(base64String); } [HttpPost] [Route("getEmployeeForFundContribution")] public ActionResult GetEmployeeForFundContribution(dynamic data) { DataTable dt = new DataTable(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime month = (DateTime)items["month"].ToObject(); int payrollTypeID = (int)items["payrollTypeID"].ToObject(); try { dt = _EmployeeService.GetEmployeeForFundContribution(payrollTypeID, GlobalFunctions.LastDateOfMonth(month)); List odesignations = new DesignationService().GetAll(); dt.Columns.Add("designation"); foreach (DataRow row in dt.Rows) { row["designation"] = odesignations.Find(x => x.ID == Convert.ToInt32(row["designationid"]))?.Name; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("getEmployeeForFundLoanDeduction")] public ActionResult GetEmployeeForFundLoanDeduction(dynamic data) { DataTable dt = new DataTable(); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime month = (DateTime)items["month"].ToObject(); int payrollTypeID = (int)items["payrollTypeID"].ToObject(); try { dt = _EmployeeService.GetEmployeeForFundLoanDeduction(payrollTypeID, GlobalFunctions.LastDateOfMonth(month)); List odesignations = new DesignationService().GetAll(); dt.Columns.Add("designation"); foreach (DataRow row in dt.Rows) { row["designation"] = odesignations.Find(x => x.ID == Convert.ToInt32(row["designationid"]))?.Name; } } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } return Ok(dt); } [HttpPost] [Route("GetAttritionReportData")] public ActionResult GetAttritionReportData(dynamic data) { CurrentUser currentUser = CurrentUser.GetCurrentUser(HttpContext.User); var items = Newtonsoft.Json.JsonConvert.DeserializeObject(Convert.ToString(data)); DateTime fromMonth = (DateTime)items["fromMonth"].ToObject(); DateTime toMonth = (DateTime)items["toMonth"].ToObject(); int selectedGroup = (int)items["selectedGroup"].ToObject(); int? selectedGroupTwo = (int)items["selectedGroupTwo"].ToObject(); try { var result = new EmployeeService().GetEmployeeAttritionReportData(fromMonth, toMonth, currentUser.PayrollTypeID ?? 0, selectedGroup, selectedGroupTwo); return Ok(result); } catch (Exception ex) { return StatusCode(StatusCodes.Status500InternalServerError, ex.Message); } } } }