public int Insert(CardInsertRequest card) { int cardId = 0; string user = _userService.GetCurrentUserId(); string connectionString = WebConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("dbo.Flashcards_Insert", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@Front", card.Front); command.Parameters.AddWithValue("@Back", card.Back); command.Parameters.AddWithValue("@UserId", user); SqlParameter p = new SqlParameter("@Id", cardId); p.Direction = ParameterDirection.Output; command.Parameters.Add(p); connection.Open(); command.ExecuteNonQuery(); int.TryParse(command.Parameters["@Id"].Value.ToString(), out cardId); } } return(cardId); }
public HttpResponseMessage Insert(CardInsertRequest card) { if (!ModelState.IsValid && card != null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } int id = _flashcardServices.Insert(card); int response = id; return(Request.CreateResponse(HttpStatusCode.OK, response)); }