Ejemplo n.º 1
0
        /// <inheritdoc />
        public async Task <ExportFileModel> BuildReport(DateTimeOffset date, ExportFormatOption format)
        {
            var exchangeRates = await _context.ExchangeRates.AsNoTracking()
                                .Where(a => a.Date.Year == date.Year && a.Date.Month == date.Month)
                                .Where(a => _currencies.Contains(a.Code))
                                .ToListAsync();

            var reportModel = CreateReportModel(exchangeRates, date);

            return(await _buildersFactory.DefineBuilder <ExchangeRatesReportModel>(format)
                   .BuildReport(reportModel));
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public ISpecificFormatReportBuilder <TModel> DefineBuilder <TModel>(ExportFormatOption exportFormat)
        {
            switch (exportFormat)
            {
            case ExportFormatOption.Txt:
                return(_serviceProvider.GetService <ITxtReportBuilder <TModel> >());

            case ExportFormatOption.Json:
                return(_serviceProvider.GetService <IJsonReportBuilder <TModel> >());

            default:
                throw new ArgumentOutOfRangeException(nameof(exportFormat), exportFormat, null);
            }
        }
        public async Task <FileStreamResult> GetReport([FromQuery] DateTimeOffset date, [FromQuery] ExportFormatOption format = ExportFormatOption.Txt)
        {
            var exportFileModel = await _service.BuildReport(date, format);

            return(File(exportFileModel.Stream, "application/octet-stream", exportFileModel.FileName));
        }