Reputation: 193
I am using Castle Windsor as DI and using reposity to access and implement the data layers. As I have implemented all the data access layer in my repo, it is time to call those methods in my API controller. However, when I do, I am getting error messages:
The method from repo is below:
public void CreateReport(TReportHeaderModel model)
{
using (var connection = new TReportEntitiesConnection())
{
connection.THeader.Add(new THeader()
{
ClientID=model.ClientID,
ID=model.ID,
THeaderTitle=model.THeaderTitle,
RowNumber=model.RowNumber
});
foreach (var d in model.TReports)
{
connection.TReport.Add(new TReport()
{
ID=d.ID,
TReportName=d.TReportName,
URL=d.URL,
RowNumber=d.RowNumber,
});
}
connection.SaveChanges();
}
throw new NotImplementedException();
}
and when I move it to my API controller as I have to pass these in HTTP Json Format:
[HttpPost]
public CreateReport([FromBody] TReportHeaderModel model) //Method must have a return type
{
try
{
_tReportingService.CreateReport(model);
return new ActionResultModel() //return void, must not be followed by object expression
{
Success = true,
Message = "Report Successfully Created."
};
}
catch (Exception ex)
{
return new ActionResultModel()
{
Success = false,
Message = "Report not created.",
Obj=ex.Message
};
}
}
Upvotes: 0
Views: 1314
Reputation: 3267
your method should have a return type as per the Standard,
[HttpPost]
public ActionResult CreateReport([FromBody] TReportHeaderModel model) //Method must have a return type
{
// Body
}
Upvotes: 1
Reputation: 3169
You can use dynamic here or your model class, it is not a void it is a function, since it returns a value.
[HttpPost]
public dynamic CreateReport([FromBody] TReportHeaderModel model) //Method must have a return type
{
}
Upvotes: 0