Ejemplo n.º 1
0
        public async Task <Result> Handle(GetStatistics request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Getting Report Constructor statistics");

            try
            {
                var templates = await _repository.GetReportTemplatesAsync();

                return(Result.Success(new
                {
                    TotalTemplates = templates.Count()
                }));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "In Get Statistics Handler");
                return(Result.Fail(e));
            }
        }
Ejemplo n.º 2
0
        public async Task <Result> Handle(
            GetReportTemplateInfos request,
            CancellationToken cancellationToken)
        {
            try
            {
                IQueryable <ReportTemplate> templates = await _repository.GetReportTemplatesAsync();

                return(Result
                       .Success(templates
                                .Select(x => x.AsInfoDto())
                                .AsEnumerable()));
            }
            catch (Exception e)
            {
                return(Result
                       .Fail(e));
            }
        }
Ejemplo n.º 3
0
        public async Task <Result> Handle(ConstructReports request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Started constructing reports");
            try
            {
                var command = new PublishReports()
                {
                    ReportDescriptors = new List <ReportPublishDescriptor>()
                };

                var templates = await _repository.GetReportTemplatesAsync();

                foreach (var descriptor in request.ReportDescriptors)
                {
                    var template = templates.FirstOrDefault(x => x.Id == descriptor.ReportTemplateId);

                    if (template is null)
                    {
                        throw new Exception(
                                  $"APPLICATION Can't find report template with id: {descriptor.ReportTemplateId}");
                    }

                    _logger.LogInformation($"Constructing report for template: {template.Title}");

                    command.ReportDescriptors.Add(new ReportPublishDescriptor()
                    {
                        ConstructionDescriptor = descriptor,
                        Template = new ReportTemplateDto()
                        {
                            Title          = template.Title,
                            Questionnaires = template.GetArray()
                                             .Where(m => m is QuestionnaireModuleTemplate)
                                             .Select(m => m as QuestionnaireModuleTemplate)
                                             .Select(m => new QuestionnaireModuleTemplateDto()
                            {
                                Title    = m.Title,
                                Order    = m.Order,
                                Sections = m.GetArray()
                                           .Select(s => new SectionTemplateDto()
                                {
                                    Title     = s.Title,
                                    Order     = s.Order,
                                    Questions = s.GetArray()
                                                .Select(q => new QuestionTemplateDto()
                                    {
                                        Title     = q.QuestionText,
                                        Order     = q.Order,
                                        InputType = q.InputType switch
                                        {
                                            InputType.ShortText => "ShortText",
                                            InputType.LongText => "LongText",
                                            InputType.Email => "Email",
                                            InputType.PhoneNumber => "PhoneNumber",
                                            InputType.Label => "Label",
                                            InputType.Integer => "Integer",
                                            InputType.Decimal => "Decimal",
                                            InputType.Financial => "Financial",
                                            InputType.MultipleChoiceOptionList => "MultipleChoiceOptionList",
                                            InputType.SingleOptionSelect => "SingOptionSelect",
                                            InputType.Boolean => "Boolean",
                                            _ => ""
                                        }
                                    }).ToList()
                                }).ToList()