Beispiel #1
0
        public ActionResult AddCardToDeck(Deck deck)
        {
            string userID = GetUserID();

            if (deck.NewCardFront == null || deck.NewCardBack == null)
            {
                TempData["empty-card"] = true;
                return(RedirectToAction("EditDeck", "Deck", new { deckID = deck.DeckID, newBackground = false }));
            }

            Card newCard = new Card()
            {
                UserID = userID,
                Front  = deck.NewCardFront,
                Back   = deck.NewCardBack
            };

            newCard = cardSql.CreateCard(newCard, userID);
            cardSql.AddCardToDeck(newCard, deck.DeckID);

            deck = deckSql.GetDeckByID(deck.DeckID);

            TempData["card-added"] = true;
            return(RedirectToAction("EditDeck", "Deck", new { deckID = deck.DeckID, newBackground = false }));
        }
Beispiel #2
0
        public ActionResult UserHome()
        {
            if (Session["userid"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            //leaderboard
            Dictionary <int, int>    activeUsersSql = studySql.MostActiveUsers();
            Dictionary <string, int> activeUsers    = new Dictionary <string, int>();

            foreach (KeyValuePair <int, int> kvp in activeUsersSql)
            {
                User   user = userSql.GetUserByID(kvp.Key.ToString());
                string name = user.DisplayName;
                activeUsers.Add(name, kvp.Value);
            }

            Dictionary <int, int>  activeDecksSql = studySql.MostActiveDecks();
            Dictionary <Deck, int> activeDecks    = new Dictionary <Deck, int>();

            foreach (KeyValuePair <int, int> kvp in activeDecksSql)
            {
                Deck deck = deckSql.GetDeckByID(kvp.Key.ToString());
                if (deck.IsPublic)
                {
                    activeDecks.Add(deck, kvp.Value);
                }
            }

            List <Tag>            popularTagsSql = tagSql.GetAllTagsByPopularity();
            Dictionary <Tag, int> popularTags    = new Dictionary <Tag, int>();

            for (int i = 0; i < popularTagsSql.Count; i++)
            {
                Tag tag        = popularTagsSql[i];
                int decksUsing = tag.DecksUsing.Count;
                popularTags.Add(tag, decksUsing);
            }

            Stats stats = new Stats
            {
                ActiveDecks = activeDecks,
                ActiveUsers = activeUsers,
                PopularTags = popularTags,
            };

            Session["background"] = GetBackground();
            return(View(stats));
        }
Beispiel #3
0
        public ActionResult ChangeDeckName(Deck deck)
        {
            GetUserID();

            Deck currentDeck = deckSql.GetDeckByID(deck.DeckID);

            if (deck.DeckName != currentDeck.DeckName)
            {
                deckSql.ChangeDeckName(deck.DeckName, deck.DeckID);
                TempData["deckname-changed"] = true;
            }

            return(RedirectToAction("EditDeck", new { deckID = deck.DeckID, newBackground = false }));
        }