Esempio n. 1
0
        public async Task <Result> Handle(ConstructReport request, CancellationToken cancellationToken)
        {
            try
            {
                var schedule = request.Schedule.AsEntity();

                var command = new ConstructReports()
                {
                    ReportDescriptors = new List <ReportConstructionDescriptor>()
                    {
                        new ReportConstructionDescriptor()
                        {
                            ReportTemplateId        = schedule.ReportTemplate,
                            AssignedOrganizationIds = schedule.AssignedOrganizations,
                            DeadlineDate            = DateTime.Now.ToUniversalTime() + schedule.DeadlinePeriod
                        }
                    }
                };

                await _service.CommandAsync(command, "constructor", "api/cs/report/construct");

                return(Result.Success());
            }
            catch (Exception e)
            {
                _logger.LogError(e.StackTrace);
                return(Result.Fail(e));
            }
        }
Esempio n. 2
0
        public async Task Handle(NewDay notification, CancellationToken cancellationToken)
        {
            var today = _date.Now();

            try
            {
                var schedules = await _repository.GetReportSchedulesAsync();

                var reportConstructConfigurations = schedules
                                                    .Where(x => _date.IsEarlier(today, x.EmissionEnd) && _date.IsEarlier(x.EmissionStart, today))
                                                    .Where(x => ShouldBeEmittedToday(x))
                                                    .Select(x => new ReportConstructionDescriptor()
                {
                    ReportTemplateId        = x.ReportTemplate,
                    AssignedOrganizationIds = x.AssignedOrganizations,
                    DeadlineDate            = today + x.DeadlinePeriod
                })
                                                    .ToList();

                if (reportConstructConfigurations is null || reportConstructConfigurations.Count() == 0)
                {
                    return;
                }

                var command = new ConstructReports()
                {
                    ReportDescriptors = reportConstructConfigurations
                };

                await _service.CommandAsync(command, "constructor", "api/cs/report/construct");
            }
            catch (Exception e)
            {
                throw e;
            }
        }