public async Task <IActionResult> Post(EmployeeForAddDTO model) { var vesting = _vestingRulesService.GetVestingRules(); var maxvalue = _appSettingService.GetPensionMaxPercent(); Employee employee = mapper.Map <Employee>(model); employeeService.CreateEmployee(employee); EmployeeForViewDTO empResult = mapper.Map <EmployeeForViewDTO>(employee); await unitOfWork.Commit(); empResult.Id = employee.Id; return(Ok(empResult)); }
public async Task <IActionResult> Post(EmployeeForAddDTO employeeForAddDTO) { try { if (!ModelState.IsValid) { return(BadRequest()); } var _employeeNew = _mapper.Map <Employee>(employeeForAddDTO); await _repo.Create(_employeeNew); var _employeeToReturn = _mapper.Map <EmployeeDTO>(_employeeNew); return(CreatedAtAction("GetEmployee", new { id = _employeeNew.Id }, _employeeToReturn)); } catch (Exception ex) { string _errorMessage = $"Could not add new employee. Please try again or consult administrator!"; _logger.LogError(_errorMessage); return(BadRequest(_errorMessage)); } }