public async Task <EmployeeAll> GetEmployeeLeavesAllDetailsAsync(EmployeeLeavesAllDetailsRequestDTO employeeLeavesAllDetailsRequestDTO) { //String queryEmployee = @QueryConstants.EMPLOYEE_TRAINING + QueryConstants.EMPLOYEE_VACATION + QueryConstants.EMPLOYEE_WFH; //String queryEmployee = @QueryConstants.EMPLOYEE_TRAINING + QueryConstants.EMPLOYEE_VACATION + QueryConstants.EMPLOYEE_WFH; StringBuilder queryEmpDetails = new StringBuilder(); if (employeeLeavesAllDetailsRequestDTO.EmployeeId != null) { queryEmpDetails.Append(@QueryConstants.EMPLOYEE_DETAILS); queryEmpDetails.Append($" where emp.id=" + employeeLeavesAllDetailsRequestDTO.EmployeeId + ";"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_TRAINING); queryEmpDetails.Append($" where emp.id=" + employeeLeavesAllDetailsRequestDTO.EmployeeId + " and "); queryEmpDetails.Append(" et.DateFrom >= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateFrom + "',3) and et.DateTo <= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateTo + "',3);"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_VACATION); queryEmpDetails.Append($" where emp.id=" + employeeLeavesAllDetailsRequestDTO.EmployeeId + " and "); queryEmpDetails.Append("ev.DateFrom >= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateFrom + "',3) and ev.DateTo <= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateTo + "',3);"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_WFH).Append($" where emp.id=" + employeeLeavesAllDetailsRequestDTO.EmployeeId + ";");; } else { queryEmpDetails.Append(@QueryConstants.EMPLOYEE_DETAILS + ";"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_TRAINING + " and "); queryEmpDetails.Append(" et.DateFrom >= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateFrom + "',3) and et.DateTo <= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateTo + "',3);"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_VACATION + " and "); queryEmpDetails.Append("ev.DateFrom >= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateFrom + "',3) and ev.DateTo <= CONVERT(varchar, '" + employeeLeavesAllDetailsRequestDTO.DateTo + "',3);"); queryEmpDetails.Append(QueryConstants.EMPLOYEE_WFH); } EmployeeAll employeeAll = new EmployeeAll(); using (var conn = _context.Connection) { conn.Open(); var multi = await conn.QueryMultipleAsync(queryEmpDetails.ToString(), null); var employeeAllDetails = await multi.ReadAsync <EmployeeAllDetails>(); var employeesTrainingDetails = await multi.ReadAsync <EmployeeAllDetailsTraining>(); var employeeAllDetailsVacation = await multi.ReadAsync <EmployeeAllDetailsVacation>(); var employeeAllDetailsWFH = await multi.ReadAsync <EmployeeAllDetailsWFH>(); employeeAll.EmployeeAllDetails = employeeAllDetails.First(); employeeAll.EmployeeAllDetailsTraining = employeesTrainingDetails; employeeAll.EmployeeAllDetailsVacation = employeeAllDetailsVacation; employeeAll.EmployeeAllDetailsWFH = employeeAllDetailsWFH; conn.Close(); } return(employeeAll); }
//[Route("getEmployeeLeavesAllDetails")] //int employeeId, DateTime dateFrom, DateTime dateTo public async Task <IActionResult> GetEmployeeLeavesAllDetails(DateTime dateFrom, DateTime dateTo) { _logger.LogInformation($"Performing GetEmployeeLeavesAllDetails operation having values " + $"+ dateFrom={dateFrom} + dateTo={dateTo}"); EmployeeLeavesAllDetailsRequestDTO employeeLeavesAllDetailsRequestDTO = new EmployeeLeavesAllDetailsRequestDTO(); employeeLeavesAllDetailsRequestDTO.DateFrom = dateFrom; employeeLeavesAllDetailsRequestDTO.DateTo = dateTo; _logger.LogDebug("payload employeeLeavesAllDetailsRequestDTO =" + employeeLeavesAllDetailsRequestDTO); var employeeLeavesDTO = await _employeeLeavesService.GetEmployeeLeavesAllDetails(employeeLeavesAllDetailsRequestDTO); return(Ok(employeeLeavesDTO)); }
public async Task <EmployeeAll> GetEmployeeLeavesAllDetails(EmployeeLeavesAllDetailsRequestDTO employeeLeavesAllDetailsRequestDTO) { try { _logger.LogInformation("Calling Repository operation GetEmployeeLeavesAllDetailsAsync "); var employeeAllDetailsEntities = await _employeeLeavesRepository.GetEmployeeLeavesAllDetailsAsync(employeeLeavesAllDetailsRequestDTO); _logger.LogDebug("Payload returned List of all employees in a given date range for a specific vacationTypeId"); return(employeeAllDetailsEntities); } catch (Exception ex) { _logger.LogError("Exception occured while retrieving employee leaves data " + ex); throw; } }