public List <UserFlashCardDeckWithID> GetUserDecks(int userID) { List <UserFlashCardDeckWithID> deckList = new List <UserFlashCardDeckWithID>(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GetUserDecks, conn); cmd.Parameters.AddWithValue("@userID", userID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { UserFlashCardDeckWithID tempDeck = new UserFlashCardDeckWithID(); tempDeck.deck_id = Convert.ToInt32(reader["Deck_id"]); tempDeck.deckName = Convert.ToString(reader["Name"]); tempDeck.category_id = Convert.ToInt32(reader["Category_id"]); tempDeck.isSharing = Convert.ToBoolean(reader["Share_Deck"]); tempDeck.person_id = Convert.ToInt32(reader["Person_id"]); deckList.Add(tempDeck); } } } catch (SqlException) { throw; } return(deckList); }
public UserFlashCardDeckWithID GetSingleDeck(int deckID) { UserFlashCardDeckWithID tempDeck = new UserFlashCardDeckWithID(); try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(SQL_GetSingleDeck, conn); cmd.Parameters.AddWithValue("@deckID", deckID); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { tempDeck.deck_id = Convert.ToInt32(reader["Deck_id"]); tempDeck.deckName = Convert.ToString(reader["Name"]); tempDeck.category_id = Convert.ToInt32(reader["Category_id"]); tempDeck.isSharing = Convert.ToBoolean(reader["Share_Deck"]); tempDeck.person_id = Convert.ToInt32(reader["Person_id"]); } } } catch (Exception) { throw; } return(tempDeck); }
public UserFlashCardDeckWithID updateDeck(UserFlashCardDeckWithID updatedDeck) { try { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); int affectedRows = 0; SqlCommand cmd = new SqlCommand(SQL_UpdateDeck, conn); cmd.Parameters.AddWithValue("@deckName", updatedDeck.deckName); cmd.Parameters.AddWithValue("@shareDeck", updatedDeck.isSharing); cmd.Parameters.AddWithValue("@categoryID", updatedDeck.category_id); cmd.Parameters.AddWithValue("@deckID", updatedDeck.deck_id); affectedRows = cmd.ExecuteNonQuery(); return(affectedRows == 0 ? (UserFlashCardDeckWithID)null : updatedDeck); } } catch (SqlException) { throw; } }
public ActionResult <List <UserFlashCardDeckWithID> > updateDeck(int deckID, [FromForm] UserFlashCardDeckWithID deck) { UserFlashCardDeckWithID existingDeck = deckOptionsDAL.GetSingleDeck(deckID); if (existingDeck == null) { return(NotFound()); } existingDeck.deckName = String.IsNullOrEmpty(deck.deckName) ? existingDeck.deckName : deck.deckName; existingDeck.isSharing = deck.isSharing; existingDeck.category_id = deck.category_id; UserFlashCardDeckWithID updatedDeck = deckOptionsDAL.updateDeck(existingDeck); List <UserFlashCardDeckWithID> updatedUserDecks = new List <UserFlashCardDeckWithID>(); if (updatedDeck != null) { return(updatedUserDecks = deckOptionsDAL.GetUserDecks(updatedDeck.person_id)); } return(NotFound()); }