Beispiel #1
0
        public SearchViewModel Search(string query)
        {
            SearchViewModel results = new SearchViewModel();

            results.Card = new Card();

            string[] tags = query.Split(' ', ',', '+');
            foreach (string tag in tags)
            {
                results.SearchTerms.Add(new Tag()
                {
                    Name = tag.ToLower()
                });
            }

            HashSet <int> uniqueCardIds = new HashSet <int>();

            foreach (Tag tag in results.SearchTerms)
            {
                uniqueCardIds = cardSqlDAL.SearchForCard(tag);
            }

            foreach (int id in uniqueCardIds)
            {
                results.SearchResults.Add(cardSqlDAL.GetCardById(id));
            }

            results.UserDecksSelectList = decksSqlDAL.GetUserDecksSelectList(authProvider.GetCurrentUser().Id);

            return(results);
        }
Beispiel #2
0
        public IActionResult ViewDeck(int deckId)
        {
            Deck deck = decksSqlDAL.GetDeckById(deckId);

            if (authProvider.GetCurrentUser() == null)
            {
                if (IsDeckPublic(deckId))
                {
                    return(View("AnonViewDeck", deck));
                }
                else
                {
                    return(NotFound());
                }
            }
            int userId = authProvider.GetCurrentUser().Id;

            if (IsCurrentUserTheOwner(deckId))
            {
                return(View(deck));
            }
            else if (IsDeckPublic(deckId))
            {
                OtherUsersDeckViewModel oudvm = new OtherUsersDeckViewModel()
                {
                    Deck = deck
                };
                oudvm.DeckOwnerName       = decksSqlDAL.GetUserNameFromDeckId(deck.Id);
                oudvm.UserDecksSelectList = decksSqlDAL.GetUserDecksSelectList(userId);
                return(View("NotOwnersDeck", oudvm));
            }
            else
            {
                return(NotFound());
            }
        }