I have a controller action that performs a particular task. I am trying to execute another method in a different class. I happen to be trying to use Hangfire, but that is not relevant to the issue I don't think.
The code won't compile because the method call UpdatePlayerStats.Process(originalresult.Id); errors with On object reference is required for the non-static field, method, or property call ...
How can I make this work?
Controller
[HttpPost]
public async Task<IActionResult> CommitScorecard(ScorecardViewModel vm)
{
//Other code
UpdatePlayerStats.Process(originalresult.Id);
//With hangfire
var jobId = _backgroundJobs.Enqueue(() => UpdatePlayerStats.Process(originalresult.Id));
//Other code
}
Service
public class UpdatePlayerStats
{
private readonly ApplicationDbContext _context;
public UpdatePlayerStats(ApplicationDbContext context)
{
_context = context;
}
public async Task<bool> Process(long resultid)
{
var result = _context.Results.FirstOrDefault(i => i.Id == resultid);
return true;
}
}