The interface IReportDesignerController
has the declaration of action methods that are defined in Web API Controller to retrieve data, save, edit and browse reports from the server. The IReportDesignerController has the following action methods declaration.
Methods | Description |
---|---|
PostDesignerAction | Action (HttpPost) method for posting the request for designer actions. |
UploadReportAction | Action (HttpPost) method for posted file actions. |
GetImage | Action (HttpGet) method for getting resource of images in the report. |
SetData | Writes the resource into storage location. |
GetData | Reads the resource from storage location. |
PostReportAction | Action (HttpPost) method for posting the request for report process. |
GetResource | Action (HttpGet) method for getting resource for report. |
OnInitReportOptions | Report initialization method that is triggered when report begins to be processed. |
OnReportLoaded | Report loaded method that is triggered when report and sub report begin loading. |
The class ReportDesignerHelper
contains helper methods that help to process Post or Get request from the Report Designer control and returns the response to the Report Designer control. It has the following methods.
Methods | Description |
---|---|
GetResource | Returns the report resource for the requested key. |
ProcessReport | Processes the report request and returns the result. |
The class ReportHelper
contains helper methods that help process Post or Get request from the Report Viewer control and returns the response to the Report Viewer control. It has the following methods.
Methods | Description |
---|---|
GetResource | Returns the report resource for the requested key. |
ProcessReport | Processes the report request and returns the result. |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using BoldReports.Web;
using BoldReports.Web.ReportViewer;
using BoldReports.Web.ReportDesigner;
namespace ReportDesignerAPIService
{
[System.Web.Http.Cors.EnableCors(origins: "*", headers: "*", methods: "*")]
public class ReportingAPIController : ApiController, IReportDesignerController
{
/// <summary>
/// Action (HttpGet) method for getting resource of images in the report.
/// </summary>
/// <param name="key">The unique key for request identification.</param>
/// <param name="image">The name of requested image.</param>
/// <returns>Returns the image as HttpResponseMessage content.</returns>
[System.Web.Http.ActionName("GetImage")]
[AcceptVerbs("GET")]
public object GetImage(string key, string image)
{
return ReportDesignerHelper.GetImage(key, image, this);
}
/// <summary>
/// Action (HttpPost) method for posting the request for designer actions.
/// </summary>
/// <param name="jsonData">A collection of keys and values to process the designer request.</param>
/// <returns>Json result for the current request.</returns>
public object PostDesignerAction(Dictionary<string, object> jsonData)
{
//Processes the designer request and returns the result.
return ReportDesignerHelper.ProcessDesigner(jsonData, this, null);
}
/// <summary>
/// Sets the resource into storage location.
/// </summary>
/// <param name="key">The unique key for request identification.</param>
/// <param name="itemId">The unique key to get the required resource.</param>
/// <param name="itemData">Contains the resource data.</param>
/// <param name="errorMessage">Returns the error message, if the write action is failed.</param>
/// <returns>Returns true, if resource is successfully written into storage location.</returns>
[NonAction]
public bool SetData(string key, string itemId, ItemInfo itemData, out string errorMessage)
{
//You can implement the file save logic
}
/// <summary>
/// Gets the resource from storage location.
/// </summary>
/// <param name="key">The unique key for request identification.</param>
/// <param name="itemId">The unique key to get the required resource.</param>
/// <returns>Returns the resource data and error message.</returns>
[NonAction]
public ResourceInfo GetData(string key, string itemId)
{
//You can implement the file download logic
}
/// <summary>
/// Action (HttpPost) method for posted or uploaded file actions.
/// </summary>
public void UploadReportAction()
{
//Processes the designer file upload request's.
ReportDesignerHelper.ProcessDesigner(null, this, System.Web.HttpContext.Current.Request.Files[0]);
}
/// <summary>
/// Send a GET request and returns the requested resource for a report.
/// </summary>
/// <param name="key">The unique key to get the desired resource.</param>
/// <param name="resourcetype">The type of the requested resource.</param>
/// <param name="isPrint">If set to <see langword="true"/>, then the resource is generated for printing.</param>
/// <returns> Resource object for the given key</returns>
[System.Web.Http.ActionName("GetResource")]
[AcceptVerbs("GET")]
public object GetResource(string key, string resourcetype, bool isPrint)
{
return ReportHelper.GetResource(key, resourcetype, isPrint);
}
/// <summary>
/// Report Initialization method that is triggered when report begin processed.
/// </summary>
/// <param name="reportOptions">The ReportViewer options.</param>
[NonAction]
public void OnInitReportOptions(ReportViewerOptions reportOption)
{
//You can update report options here
}
/// <summary>
/// Report loaded method that is triggered when report and sub report begins to be loaded.
/// </summary>
/// <param name="reportOptions">The ReportViewer options.</param>
[NonAction]
public void OnReportLoaded(ReportViewerOptions reportOption)
{
//You can update report options here
}
/// <summary>
/// Action (HttpPost) method for posting the request for report process.
/// </summary>
/// <param name="jsonData">The JSON data posted for processing report.</param>
/// <returns>The object data.</returns>
public object PostReportAction(Dictionary<string, object> jsonData)
{
//Processes the report request and returns the result.
return ReportHelper.ProcessReport(jsonData, this as IReportController);
}
}
}