private static EmployeeCostRate GetEmployeeCostRate() { EmployeeCostRate _costPrice = null; var _costPriceResult = FinancialHandler.Instance.FinancialClient.GetEmployeeCostRates(FinancialHandler.Instance.Token); foreach (var _apiMessage in _costPriceResult.Messages) { if (Logger.IsDebugEnabled) { Logger.Debug(_apiMessage.Message); } } if (_costPriceResult.ResponseState == TransactionalApi.SDK.FinancialService.ExecutionStatus.Success) { _costPrice = _costPriceResult.Return.FirstOrDefault(); } if (_costPrice == null) { throw new ArgumentException("No employee cost rate found"); } if (Logger.IsDebugEnabled) { Logger.Debug("Employee cost rate selected: " + _costPrice); } return(_costPrice); }
public static void Consume() { // For getting the raw XML SecurityHandler.Instance.CollectRawRequestResponse = true; OrganisationHandler.Instance.CollectRawRequestResponse = true; SalaryHandler.Instance.CollectRawRequestResponse = true; if (SecurityHandler.Instance.TryAuthenticate(out var _messages)) { RawMessageHelper.Instance.SaveRecentRequestResponsePair("c:\\temp\\TryAuthenticate.txt"); if (Logger.IsInfoEnabled) { Logger.Info("Sucessfully authenticated on transactional API"); } var _employeeGuid = Guid.NewGuid(); Department _department = null; var _departmentResult = OrganisationHandler.Instance.OrganisationClient.GetDepartments(OrganisationHandler.Instance.Token); foreach (var _apiMessage in _departmentResult.Messages) { if (Logger.IsDebugEnabled) { Logger.Debug(_apiMessage.Message); } } if (_departmentResult.ResponseState == ExecutionStatus.Success) { _department = _departmentResult.Return.FirstOrDefault(); } if (_department == null) { throw new ArgumentException("No department found"); } NormalWorkingTime _normalWorkingTime = GetNormalWorkingTime(); HolidayCalendar _holidayCalendar = GetHolidayCalendar(); Allowance _allowance = GetAllowance(); HourlyRate _hourlyRate = GetHourlyRate(); EmployeeCostRate _employeeCostRate = GetEmployeeCostRate(); var _employeeResult = OrganisationHandler.Instance.OrganisationClient.CreateEmployee( _employeeGuid, "*****@*****.**", "PN", "Peter", "Nielsen", "007", "*****@*****.**", "Senior Developer", "+45 12345678", "+45 87654321", _normalWorkingTime.Name, _holidayCalendar.Name, _allowance.Name, "Employee", _hourlyRate.Name, _employeeCostRate.Name, "peter.nielsen", _department.ID, OrganisationHandler.Instance.Token); RawMessageHelper.Instance.SaveRecentRequestResponsePair("c:\\temp\\InsertEmployee.txt"); if (_employeeResult.ResponseState == ExecutionStatus.Success) { Logger.Info("Employee created"); var _employee = _employeeResult.Return.FirstOrDefault(); if (_employee != null) { } else { if (Logger.IsWarnEnabled) { Logger.Warn("Employee not created"); } } } else { foreach (var _apiMessage in _employeeResult.Messages) { if (Logger.IsErrorEnabled) { Logger.Error(_apiMessage.Message); } } } } else { if (Logger.IsWarnEnabled) { Logger.Warn("Failed to authenticate to transactional API"); Logger.Warn(string.Join(",", _messages)); } } }