public async Task <IActionResult> DeleteDeck(long deckId)
        {
            var user = await _userManager.GetUserAsync(User);

            var deck = await _context.Decks.FindAsync(deckId);

            if (deck.CreatorId == user.Id)
            {
                _context.Remove(deck);
                _context.SaveChanges();

                return(RedirectToAction(nameof(ChooseDeck)));
            }

            return(BadRequest());
        }
Beispiel #2
0
        public async Task <IActionResult> RemoveTag(long deckId, long cardId, string tag)
        {
            var user = await _userManager.GetUserAsync(User);

            var deck = await _context.Decks.FindAsync(deckId);

            if (deck.CreatorId == user.Id)
            {
                var card = await _context.Cards
                           .Where(card => card.Id == cardId)
                           .Include(card => card.Tags)
                           .FirstOrDefaultAsync();

                var tagToRemove = await _context.CardTags.FindAsync(tag);

                if (tagToRemove is null)
                {
                    return(BadRequest());
                }

                card.Tags.Remove(tagToRemove);
                _context.Cards.Update(card);
                _context.SaveChanges();
            }

            return(RedirectToAction(nameof(EditCard), new { deckId, cardId }));
        }