private void ValidateContract(CreateEmployeeContract contract) { try { _createEmployeeContractValidator.ValidateAndThrow(contract, $"{ValidatorConstants.RULESET_CREATE}"); } catch (ValidationException ex) { throw new CreateContractInvalidException(ex.ToListOfMessages()); } }
public CreatedEmployeeContract Create(CreateEmployeeContract contract) { _logger.LogInformation($"Validating contract {contract.Name}"); ValidateContract(contract); ValidateEmailExistence(0, contract.EmailAddress); ValidateDniExistence(0, contract.DNI); _logger.LogInformation($"Mapping contract {contract.Name}"); var employee = _mapper.Map <Employee>(contract); this.AddRecruiterToEmployee(employee, contract.RecruiterId); this.AddRoleToEmployee(employee, contract.RoleId); if (contract.ReviewerId != null) { this.AddReviewerToEmployee(employee, contract.ReviewerId); } var createdEmployee = _employeeRepository.Create(employee); _logger.LogInformation($"Complete for {contract.Name}"); _unitOfWork.Complete(); _logger.LogInformation($"Return {contract.Name}"); return(_mapper.Map <CreatedEmployeeContract>(createdEmployee)); }