Recommended in many software architecture books is that you shouldn't put any business logic in your (API)controller code. Assuming you implement it the right way, for instance that your Controller code currently accesses the business logic through a Service class or facade, my suggestion is that you reuse the same Service class/facade for that purpose, instead of going through the 'front door' (so by doing the JSON call from code behind)
For basic and naieve example:
public class MyController1: ApiController {
public string CreateFile() {
var appService = new AppService();
var result = appService.CreateFile();
return result;
}
}
public class MyController2: ApiController {
public string CreateFile() {
var appService = new AppService();
var result = appService.CreateFile();
return result;
}
}
AppService class encapsulates your business logic (and does live on another layer) and makes it easier for you to access your logic:
public class AppService: IAppService {
public string MyBusinessLogic1Method() {
....
return result;
}
public string CreateFile() {
using (var writer = new StreamWriter..blah die blah {
.....
return 'whatever result';
}
}
...
}