The following code is a function that I wrote in my API controller to call my business logic:
[HttpGet]
[Route("api/file/{id}")]
public async Task<HttpResponseMessage> GetSysMaintExcelFile(int id)
{
var wb = await rbs.GetSystemMaintenanceExcelFile(id);
return CreateFileResponse(rbs.GetSystemMaintenanceExcelFile(id));
}
The business logic that I wanted to call is as follows:
public async Task<byte[]> GetSystemMaintenanceExcelFile(int id)
{
Systems sysRec = await dataAccess.GetSystemById(id);
return BuildSysMaintExcelFile(sysRec);
}
What is confusing me is on the HTTPGET
function does not have a connected reference to the business logic function I am trying to call. Am I missing something with this? I have the proper using statement needed to connect the business logic file. And I did add a reference to the API project as well for my business.
Edit
The purpose of these two functions were to start the build of an excel file through functions built with closedXML. The entire closedXML function through my Business logic function is as follow:
public class ReportBS : IReportsBS
{
private IAppDataAccess dataAccess;
private IAuthManager authManager;
#region Constructor
public ReportBS(IAppDataAccess da, IAuthManager am)
{
this.dataAccess = da;
this.authManager = am;
}
#endregion
#region System Maintenance Reports
public async Task<byte[]> GetSystemMaintenanceExcelFile(int id)
{
Systems sysRec = await dataAccess.GetSystemById(id);
return BuildSysMaintExcelFile(sysRec);
}
public byte[] BuildSysMaintExcelFile(Systems dataRec)
{
//Creating the workbook
const int dataRowStart = 3;
string templateName = "~/App_Data/SystemMaintenance_Template.xlsx";
var workbook = new XLWorkbook(templateName);
var worksheet = workbook.Worksheet(1);
string folderPath = @"~\Downloads\";
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
string fileName = templateName + folderPath + "SystemMaintenance_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx";
var dt = BuildSysDetailLoaExcelTable(dataRec, fileName);
worksheet.Cell(dataRowStart, 3).InsertData(dt.AsEnumerable());
workbook.SaveAs(fileName);
using (var ms = new MemoryStream())
{
workbook.SaveAs(fileName);
return ms.ToArray();
}
}
//Building the tables
private DataTable BuildSysDetailLoaExcelTable(Systems record, string fileName)
{
DataTable dt = new DataTable(fileName);
dt.Columns.Add("systemName", typeof(string));
dt.Columns.Add("isActive", typeof(bool));
dt.Columns.Add("localIAO", typeof(bool));
dt.Columns.Add("localStaff", typeof(bool));
dt.Columns.Add("informationOfficerRequired", typeof(bool));
dt.Columns.Add("iaoRequired", typeof(bool));
dt.Columns.Add("IAOs", typeof(string));
dt.Columns.Add("StaffProcessors", typeof(string));
dt.Columns.Add("StaffRevalidators", typeof(string));
var dr = dt.NewRow();
dr[0] = record.systemName;
dr[1] = record.isActive;
dr[2] = record.localIAO;
dr[3] = record.localStaff;
dr[4] = record.informationOfficerRequired;
dr[5] = record.iaoRequired;
dr[6] = record.IAOs;
dr[9] = record.StaffProcessors;
dr[11] = record.StaffRevalidators;
return dt;
}
#endregion
}
Thanks for any help