コード例 #1
0
        public async Task Resend(string absenceExportId)
        {
            var query = new SearchQueryAbsenceExport()
            {
                Id = absenceExportId
            };
            var absenceExport = (await _absenceExportService.Search(query)).FirstOrDefault();

            if (absenceExport == null)
            {
                throw new NotFoundException("Absence doesn't exist");
            }

            var absenceResult = JsonConvert.DeserializeObject <Absence>(absenceExport.AbsenceJson);

            var integration = await GetIntegrationRecursive(absenceResult.UnitId);

            var validationResult = await Validate(absenceResult, integration);

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

            try
            {
                if (!validationResult.IsValid)
                {
                    absenceExport.Status  = AbsenceExportStatus.Failed;
                    absenceExport.Message = validationResult.Message;
                    return;
                }

                absenceExport.Absence = await externalSystemAdapter.ResendAbsence(integration.UnitId, absenceResult);

                absenceExport.Status  = AbsenceExportStatus.Success;
                absenceExport.Message = "Absence successfully exported";
            }catch (ExternalSystemCommunicationException ex)
            {
                absenceExport.Status  = AbsenceExportStatus.Failed;
                absenceExport.Message = $"Communication with external system failed: {ex.Message}";
            }
            catch (Exception ex)
            {
                absenceExport.Status  = AbsenceExportStatus.Failed;
                absenceExport.Message = ex.Message;
            }
            finally
            {
                await _absenceExportService.UpdateAbsenceExport(absenceExport);
            }
        }
コード例 #2
0
        public async Task <ActionResult <IEnumerable <contracts.AbsenceExport> > > GetAbsenceExports([FromQuery] contracts.SearchQueryAbsenceExport query)
        {
            var mapQuery = _mapper.Map <contracts.SearchQueryAbsenceExport, SearchQueryAbsenceExport>(query);

            var absenceExports = await _absenceExportService.Search(mapQuery);

            var absenceExportContracts = _mapper.Map <IEnumerable <contracts.AbsenceExport> >(absenceExports);

            return(Ok(absenceExportContracts));
        }