December 2019
Intermediate to advanced
598 pages
12h 21m
English
The last method we are going to implement is for adding an answer to a question:
public AnswerGetResponse PostAnswer(AnswerPostRequest answer){ using (var connection = new SqlConnection(_connectionString)) { connection.Open(); return connection.QueryFirst<AnswerGetResponse>( @"EXEC dbo.Answer_Post @QuestionId = @QuestionId, @Content = @Content, @UserId = @UserId, @UserName = @UserName, @Created = @Created", answer ); }}
As well as inserting the answer into the database table, the stored procedure returns the saved answer. So, we use the Dapper QueryFirst method to execute the stored procedure and return the saved answer.
We also need to create the AnswerPostRequest model class in the models ...
Read now
Unlock full access