-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathReportController.cs
More file actions
61 lines (53 loc) · 2.36 KB
/
ReportController.cs
File metadata and controls
61 lines (53 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using Microsoft.FeatureManagement;
using referenceApp.Api.System;
using referenceApp.Common.Models.System;
using referenceApp.PowerBi.Models;
using referenceApp.PowerBi;
using System;
using System.Threading.Tasks;
using referenceApp.Lib.Report.Commands;
using referenceApp.Lib.Report.Queries;
using Microsoft.AspNetCore.Authorization;
namespace referenceApp.Api.Controllers
{
[Authorize]
[Route("api/[controller]/[action]")]
public class ReportController : ApiControllerBase
{
private readonly IPowerBiEmbedService _powerBiService;
private readonly IOptions<PowerBIConfigModel> _powerBiOptions;
public ReportController(IFeatureManager featureManager, IUserSecurityService userSecurity, ISettingsData settingsData, IPowerBiEmbedService powerBiService, IOptions<PowerBIConfigModel> powerBiOptions)
: base(featureManager, userSecurity, settingsData)
{
_powerBiService = powerBiService ?? throw new ArgumentNullException(nameof(powerBiService));
_powerBiOptions = powerBiOptions ?? throw new ArgumentNullException(nameof(powerBiOptions));
}
[HttpGet]
[Produces("application/json")]
public async Task<ActionResult<ReportEmbedResponseModel>> GetReportIdEmbedToken(int reportEnumId)
{
// get new Embed Token and report info
var reportEmbedResponse = await Mediator.Send(new GetReportEmbedQuery(new ReportEmbedRequestModel() { ReportEnumId = reportEnumId }));
// return report info with EmbedParameters needed for UI Http Request to Power BI server
return ModelResponse(reportEmbedResponse);
}
[HttpPost]
public async Task<IActionResult> ExportReport(ExportReportRequestModel request)
{
var response = await Mediator.Send(new ExportReportCommand(request));
if (response.Success && response.ReportStream != null)
{
//response.ReportStream.Flush();
var file = new FileStreamResult(response.ReportStream, response.DownloadMimeType);
file.FileDownloadName = response.ReportName + response.ResourceFileExtension;
return file;
}
else
{
return ModelResponse(response);
}
}
}
}