- Product version? ANZ 9.3
- Product type: MVC
- Framework type: CORE
Thanks in advance, and sorry for the lack of DevExpress (Xtra Report) Knowledge.
Guide: https://docs.aspnetzero.com/en/aspnet-core-mvc/latest/DevExpress-Reporting-Implementation
What I would like to do is limit a reports to a single tenant and stop a tenant from specifying another tenant's Id eg. using url App/SampleReport?tenantId=2. When I pass the model in this way (see below) to the view the tenantId is received (and works for a blank report and a labled to show the passed in parameter) but if I use a DevExpress:Table Report which is bound to a datasource the report wont load.
My assumption is because the datasource is being removed when creating a
new SampleReport()
An example scenario might be I want a report for Today's Completed Sales and I use a table to store these sales called "CompletedSales" and I want to show/filter all the completed sales for the current Tenant and Filter by creation time today.
Any insight in how to tackle this would be much appreciated :) Hope you all have a wonderful day!
Controller:
...
public IActionResult Index()
{
var report = new SampleReport();
report.Parameters["tenantId"].Value = AbpSession.TenantId;
return View(report);
}
...
View:
@model XtraReport;
...
<div class="container-fluid">
<div class="row">
<!-- Report -->
<div class="d-flex flex-column flex-column-fluid">
<div class="@(await GetContainerClass())">
<div class="card card-custom gutter-b">
<div class="card-body">
@(Html.DevExpress()
.WebDocumentViewer("DocumentViewer")
.Height("820px")
.Bind(Model)
)
</div>
</div>
</div>
</div>
</div>
</div>
...
Thanks again =)
3 Answer(s)
-
0
Again, Thank you for your time to read over this.
Following on my above, the only way I can get it to populate a report with data is by:
- setting the data source manually
- using a custom query string
There has to be an easier way to achieve my desired outcome right ?
Example scenario again for reference: I want a report for Completed Sales that is filtered by current Tenant and creation time.
If someone could provide a working example that uses a Table Report and queries an SQL Table with a tenantId parameter and date parameter (that is not using a URL using url App/SampleReport?tenantId=2) it would be greatly appreciated.
Updated Controller
public IActionResult CompletedSales() { return View(CreateReport()); }
private XtraReport CreateReport() { // Create a new report instance. XtraReport report = new CompletedSales(); // Assign the data source to the report. report.DataSource = BindToData(); report.DataMember = "customQuery"; return report; }
private SqlDataSource BindToData() { // Create a data source with the required connection parameters. MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters( ".\\SQLExpress", "ExampleDb", "sa", "supersecurepassword", MsSqlAuthorizationType.SqlServer); SqlDataSource ds = new SqlDataSource(connectionParameters); // Create an SQL query to access the Products table. CustomSqlQuery query = new CustomSqlQuery(); query.Name = "customQuery"; query.Sql = "SELECT * FROM CompletedSales"; // Add the query to the collection. ds.Queries.Add(query); // Make the data source structure displayed // in the Field List of an End-User Report Designer. ds.RebuildResultSchema(); return ds; }
-
0
Hi @dexmox
Since you are using a raw SQL query, multi tenancy filter will not be included in your query. Have you tried getting the value of AbpSession.TenantId in your
BindToData
method and add it to your query ? -
0
Hi @ismcagdas,
I've managed to work it out =)
Thanks.