Exemplo n.º 1
0
        public async Task Handle(SubmissionSavedEvent evt)
        {
            var submissions = new[] { evt.Submission }
            .Select(async s => await ResolveEntitiesReferences(s))
            .Select(t => t.Result)
            .MapSubmissions(evt.ReferenceNumber);

            try
            {
                foreach (var submission in submissions)
                {
                    logger.LogDebug(JsonConvert.SerializeObject(submission));

                    dynamic result = await api.ExecuteAction("era_SubmitUnauthInvoices", submission);

                    if (!result.submissionFlag)
                    {
                        throw new Exception($"era_SubmitUnauthInvoices call failed: {result.message}");
                    }
                }
            }
            catch (ValidationException e)
            {
                throw new Exception($"Submission '{evt.ReferenceNumber}' validation error: {e.Message}", e);
            }
            catch (AggregateException e)
            {
                throw new Exception($"Submission '{evt.ReferenceNumber}' validation error: {e.Message}", e);
            }
        }
Exemplo n.º 2
0
        public async Task Handle(SubmissionSavedEvent evt)
        {
            var submissions = new[] { evt.Submission }
            .Select(async s => await ResolveEntitiesReferences(s))
            .Select(t => t.Result)
            .MapSubmissions(evt.ReferenceNumber);

            try
            {
                foreach (var submission in submissions)
                {
                    logger.LogDebug(JsonConvert.SerializeObject(submission));

                    dynamic result = await api.ExecuteAction("era_SubmitUnauthInvoices", submission);

                    if (!result.submissionFlag)
                    {
                        throw new Exception($"era_SubmitUnauthInvoices call failed: {result.message}");
                    }
                }
            }
            catch (ValidationException e)
            {
                var validationError = new ValidationException($"Submission '{evt.ReferenceNumber}' validation errors: {e.Message}", null, evt.ReferenceNumber);
                throw validationError;
            }
            catch (AggregateException e)
            {
                var validationErrors = e.Flatten().InnerExceptions.Where(e => e is ValidationException).Cast <ValidationException>().Select(e => e.Message);
                if (validationErrors.Any())
                {
                    var aggregatedErrors = string.Join(';', validationErrors);
                    var validationError  = new ValidationException($"Submission '{evt.ReferenceNumber}' validation errors: {aggregatedErrors}", null, evt.ReferenceNumber);
                    throw validationError;
                }
                throw;
            }
            catch (Exception e)
            {
                throw new Exception($"Failed to post submission '{evt.ReferenceNumber}' to Dynamics: {e.Message}", e);
            }
        }