public async Task DeleteAbsence(Absence absence)
        {
            var integration = await GetIntegrationRecursive(absence.UnitId);

            var validationResult = await Validate(absence, integration);

            if (validationResult.SkipFurtherProcessing)
            {
                Logger.LogInformation($"{validationResult.Message}. Absence will not be processed. UnitId:{absence?.UnitId}");
                return;
            }

            var externalSystem = (ExternalEconomySystem)integration.ExternalSystem;
            var absenceExport  = await GetExistingAbsenceExport(absence.UnitId, absence.LocalId);

            if (absenceExport == null)
            {
                return;
            }
            try
            {
                var externalSystemAdapter = _externalSystemFactory.CreateSystemAdapter(externalSystem);
                absenceExport.Action = AbsenceExportAction.Delete;
                await externalSystemAdapter.DeleteAbsence(integration.UnitId, absenceExport.Absence);

                absenceExport.Status = AbsenceExportStatus.Success;
            }
            catch (ExternalSystemCommunicationException ex)
            {
                absenceExport.Status  = AbsenceExportStatus.Failed;
                absenceExport.Message = $"Communication with external system failed: {ex.Message}";
                Logger.LogInformation($"Communication with external system failed: {ex.Message}");
            }
            catch (Exception ex)
            {
                absenceExport.Status  = AbsenceExportStatus.Failed;
                absenceExport.Message = ex.Message;
                Logger.LogInformation(ex.Message);
            }
            finally
            {
                await _absenceExportService.UpdateAbsenceExport(absenceExport);
            }
        }
示例#2
0
        public async Task <HourBalance> GetHourBalance(int unitId, int employeeId)
        {
            var integration = await _integrationService.GetTimeregIntegration(unitId);

            var validationResult = await Validate(unitId, employeeId, integration);

            if (!validationResult.IsValid)
            {
                Logger.LogInformation($"{validationResult.Message}. HourBalance can not be fetched");
                if (validationResult.SkipFurtherProcessing)
                {
                    return(null);
                }
                throw new ForbiddenException(validationResult.Message);
            }

            var externalSystem        = (ExternalEconomySystem)integration.ExternalSystem;
            var externalSystemAdapter = _externalSystemFactory.CreateSystemAdapter(externalSystem);

            return(await externalSystemAdapter.GetHourBalance(unitId, employeeId));
        }