public ActionResult <List <UserFlashCardDeckWithID> > createUserDeck([FromForm] UserFlashCardDeck newDeck) { deckOptionsDAL.CreateDeck(newDeck); List <UserFlashCardDeckWithID> updatedUserDecks = deckOptionsDAL.GetUserDecks(newDeck.person_id); if (updatedUserDecks != null) { return(updatedUserDecks); } return(NotFound()); }
public void CreateDeck(UserFlashCardDeck newDeck) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_CreateNewDeckInDeckTable, conn); cmd.Parameters.AddWithValue("@DeckName", newDeck.deckName); cmd.Parameters.AddWithValue("@Category_id", newDeck.category_id); cmd.Parameters.AddWithValue("@Share_Deck", newDeck.isSharing); deckID = Convert.ToInt32(cmd.ExecuteScalar()); cmd = new SqlCommand(SQL_CreateNewDeckUserRelationship, conn); cmd.Parameters.AddWithValue("@Person_id", newDeck.person_id); cmd.Parameters.AddWithValue("@Deck_id", deckID); cmd.ExecuteNonQuery(); } } catch (SqlException) { throw; } }