public int AddThread(ThreadAddRequest model, string userId) { int id = 0; DataProvider.ExecuteNonQuery(GetConnection, "dbo.ForumThreads_Insert" , inputParamMapper: delegate(SqlParameterCollection paramCollection) { paramCollection.AddWithValue("@TopicId", model.TopicId); paramCollection.AddWithValue("@Title", model.Title); paramCollection.AddWithValue("@Content", model.Content); paramCollection.AddWithValue("@UserId", userId); SqlParameter p = new SqlParameter("@Id", System.Data.SqlDbType.Int); p.Direction = System.Data.ParameterDirection.Output; paramCollection.Add(p); } , returnParameters: delegate(SqlParameterCollection param) { int.TryParse(param["@Id"].Value.ToString(), out id); } ); return id; }
public HttpResponseMessage AddThread(ThreadAddRequest model) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } ItemResponse<int> response = new ItemResponse<int>(); string userId = _userService.GetCurrentUserId(); response.Item = _forumService.AddThread(model, userId); return Request.CreateResponse(response); }