I want to insert the data from ASP.NET Web API to my data in SQL Server in pre defined table. First I am getting response after calling REST API and want to insert the response in table in database.
API Controller
[HttpGet]
public async Task<IActionResult> GetOutput(int id)
{
string CheckJob = "exec sp_GetJob "+ "@id= " + id;
var result = _context.Job.FromSqlRaw(CheckJob).ToList().FirstOrDefault();
if(result == null){
string InsertResult = "exec sp_add" + "@result = " + result;
_context.FromSqlRaw(InsertResult); <-- Don't know how to call stored procedure
}
return Ok(result);
}
Stored Procedure
create procedure sp_add @result int
as
begin
insert into School(id, created_date)
values (@result, GetDate());
end
I am facing issue in calling stored procedure to insert data. Can somebody please help me out?
Thank you
_context? Entity Framework?