Exemple #1
0
        //[Route("addEmployeeLeaves")]
        public async Task <IActionResult> AddEmployeeTraining([FromBody] EmployeeTrainingsCreationDTO employeeTrainingCreationDTO)
        {
            _logger.LogDebug("Employee Training DTO = " + employeeTrainingCreationDTO);

            if (employeeTrainingCreationDTO.VacationTypeId < 1)
            {
                ModelState.AddModelError(
                    "Vacation Type", "It can not be less than or equal to zero.");
            }

            if (employeeTrainingCreationDTO == null)
            {
                return(NotFound());
            }
            var employeeTrainingDTOAdded = await _employeeTrainingsAddService.AddEmployeeTrainings(employeeTrainingCreationDTO);

            return(Ok(employeeTrainingDTOAdded));
        }
        public async Task <EmployeeTrainingsResponseDTO> AddEmployeeTrainings(EmployeeTrainingsCreationDTO employeeTrainingsCreationDTO)
        {
            try
            {
                _logger.LogDebug("Payload employeeTrainingsCreationDTO = " + employeeTrainingsCreationDTO);
                var employeeTrainingsEntity    = _mapper.Map <EmployeeTrainingsEntity>(employeeTrainingsCreationDTO);
                var newTrainingRecordCreatedID = await _employeeTrainingsAddRepository.AddEmployeeTrainings(employeeTrainingsEntity);

                var employeeTrainingsEntityAdded = await _employeeTrainingsRepository.GetEmployeeTrainingsByPrimaryKeyId(newTrainingRecordCreatedID);

                var employeeTrainingsResponseDTO = _mapper.Map <EmployeeTrainingsResponseDTO>(employeeTrainingsEntityAdded);
                return(employeeTrainingsResponseDTO);
            }
            catch (Exception ex)
            {
                _logger.LogError("Exception occured while calling AddEmployeeTrainings method" + ex);
                throw;
            }
        }