Beispiel #1
0
        public void GetCardByDeckIdShouldReturnCorrectCards()
        {
            List <Card> cards = new List <Card>();

            Card card = new Card()
            {
                Front     = "testFront",
                Back      = "testBack",
                CardOrder = 1,
                DeckId    = testDeckId,
                ImageURL  = "",
            };

            cards.Add(card);
            dal.AddCardToDeck(card);

            card = new Card()
            {
                Front     = "testFront 2",
                Back      = "testBack 2",
                CardOrder = 2,
                DeckId    = testDeckId,
                ImageURL  = "",
            };

            cards.Add(card);
            dal.AddCardToDeck(card);

            List <Card> result = dal.GetCardsByDeckId(testDeckId);

            Assert.AreEqual(cards[0].Front, result[0].Front);
            Assert.AreEqual(cards[0].Id, result[0].Id);
            Assert.AreEqual(cards[1].Front, result[1].Front);
            Assert.AreEqual(cards[1].Id, result[1].Id);
        }
Beispiel #2
0
        public IActionResult UpdateCard(Card updatedCard)
        {
            Card card = cardSqlDAL.GetCardById(updatedCard.Id);

            // Check if new Card Order is within range of valid options
            if (updatedCard.CardOrder > cardSqlDAL.GetCardsByDeckId(updatedCard.DeckId).Count || updatedCard.CardOrder < 1)
            {
                return(View("Error"));
            }

            if (cardSqlDAL.UpdateCard(updatedCard) == null)
            {
                if (updatedCard.Front == card.Front &&
                    updatedCard.Back == card.Back &&
                    updatedCard.ImageURL == card.ImageURL &&
                    updatedCard.CardOrder == card.CardOrder)
                {
                    return(RedirectToAction("ViewDeck", new { deckId = updatedCard.DeckId }));
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(RedirectToAction("ViewDeck", new { deckId = updatedCard.DeckId }));
            }
        }
Beispiel #3
0
        //Deck GetDeckById();
        public Deck GetDeckById(int deckId)
        {
            Deck result = new Deck();

            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(sql_GetDeckById, conn);
                    cmd.Parameters.AddWithValue("@id", deckId);
                    SqlDataReader reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        Deck deck = new Deck
                        {
                            Id          = Convert.ToInt32(reader["id"]),
                            Name        = Convert.ToString(reader["name"]),
                            DateCreated = Convert.ToDateTime(reader["date_created"]),
                            PublicDeck  = Convert.ToBoolean(reader["is_public"]),
                            UserId      = Convert.ToInt32(reader["users_id"]),
                            ForReview   = Convert.ToBoolean(reader["for_review"]),
                            Description = Convert.ToString(reader["description"]),
                            DeckColor   = Convert.ToString(reader["color"]),
                            TextColor   = Convert.ToString(reader["text_color"])
                        };

                        result = deck;
                    }
                }
                result.Cards = cardSqlDAL.GetCardsByDeckId(result.Id);
            }
            catch (SqlException ex)
            {
                //Deck deck = new Deck();
            }
            return(result);
        }