1

I have a put method in controller A where i pass in json object and do some checks in dynamo db, based on my output

[HttpPut]
public async Task<IActionResult> ProcessEmployee([FromBody]EmployeeModel em) 

i need to do a post in controller B

[HttpPost]
public async Task<IActionResult> CreateEmployee([FromBody]EmployeeModel em)

or

do a put in controller B

[HttpPut]
public async Task<IActionResult> UpdateEmployee([FromBody]EmployeeModel em) 

how do i redirect to the actions in controller B and also pass in my json object which i pass to the put in controller A.

Thanks for reading.

yonisha
  • 2,956
  • 2
  • 25
  • 32
user2950716
  • 45
  • 1
  • 9

1 Answers1

1

It is not a best practice for a controller to redirect calls to other controllers.
If you want to create/update employee record in your database after the JSON object has been processed by controller A, you may want to implement DAL (Data Access Layer) for db operations, that will be called from controller A.
The DAL interface should be very straightforward:

void CreateEmployee(EmployeeModel em);
void UpdateEmployee(EmployeeModel em);
yonisha
  • 2,956
  • 2
  • 25
  • 32
  • my current implementation is using DAL, i have 1 put which does the processing and then calls the code to either insert or update. i am not sure if using redirecttoaction would be a better implementation v/s having 1 put which does the processing and then does create or update. – user2950716 Jun 06 '16 at 02:58
  • Redirection will create dependencies between controllers, that you definitely want to avoid, and it is more suitable for API deprecation and alike. Therefore I think that the best way is to keep the code as is, using DAL. – yonisha Jun 06 '16 at 06:16
  • thanks for your input, i will keep my changes in DAL, thanks again :) – user2950716 Jun 06 '16 at 17:52