December 2019
Intermediate to advanced
598 pages
12h 21m
English
Let's create the PostQuestion method in DataRepository.cs to add a new question:
public QuestionGetSingleResponse PostQuestion(QuestionPostRequest question){ using (var connection = new SqlConnection(_connectionString)) { connection.Open(); var questionId = connection.QueryFirst<int>( @"EXEC dbo.Question_Post @Title = @Title, @Content = @Content, @UserId = @UserId, @UserName = @UserName, @Created = @Created", question ); return GetQuestion(questionId); }}
This is a very similar implementation to the methods that read data. We use the QueryFirst Dapper method because the stored procedure returns the ID of the new question after inserting it into the database table. Our method returns ...
Read now
Unlock full access