Пример #1
0
        public async Task <IEnumerable <ResultCard> > RunAsync(Request request)
        {
            request.CheckValidity();
            QueryValidationHelper.CheckUserIsOwnerOfDeck(dbContext, request.CurrentUserId, request.DeckId);

            var heapingAlgorithm = await GetHeapingAlgorithmAsync(request.DeckId);

            var userNames     = dbContext.Users.AsNoTracking().Select(u => new { u.Id, u.UserName }).ToImmutableDictionary(u => u.Id, u => u.UserName);
            var imagesDetails = GetAllImagesDetails();
            var tagNames      = dbContext.Tags.AsNoTracking().Select(t => new { t.Id, t.Name }).ToImmutableDictionary(t => t.Id, t => t.Name);

            if (request.LearnModeIsUnknown)
            {
                return(await GetUnknownCardsAsync(request.CurrentUserId, request.DeckId, request.ExcludedCardIds, request.ExcludedTagIds, heapingAlgorithm, userNames, imagesDetails, tagNames, request.CardsToDownload));
            }
            return(GetCardsToRepeat(request.CurrentUserId, request.DeckId, request.ExcludedCardIds, request.ExcludedTagIds, heapingAlgorithm, userNames, imagesDetails, tagNames, request.CardsToDownload));
        }
Пример #2
0
        public async Task <Result> RunAsync(Request request)
        {
            request.CheckValidity();
            QueryValidationHelper.CheckUserIsOwnerOfDeck(dbContext, request.CurrentUserId, request.DeckId);

            var cardsInDeck = dbContext.CardsInDecks.Where(cardInDeck => cardInDeck.CardId == request.CardId && cardInDeck.DeckId == request.DeckId);

            if (cardsInDeck.Count() != 1)
            {
                throw new RequestInputException($"There are {cardsInDeck.Count()} cards with the given id");
            }

            var cardInDeck = cardsInDeck.Include(cardInDeck => cardInDeck.Card).Include(cardInDeck => cardInDeck.Deck).Single();

            dbContext.CardsInDecks.Remove(cardInDeck);
            await dbContext.SaveChangesAsync();

            return(new Result(cardInDeck.Card.FrontSide, cardInDeck.Deck.Description));
        }
Пример #3
0
        public async Task RunAsync(Request request)
        {
            request.CheckValidity();
            QueryValidationHelper.CheckUserIsOwnerOfDeck(dbContext, request.UserId, request.DeckId);

            var cards = dbContext.CardsInDecks.Where(card => card.DeckId.Equals(request.DeckId) && request.CardIds.Any(cardId => cardId == card.CardId));

            await cards.ForEachAsync(card => { if (card.BiggestHeapReached < request.TargetHeapId)
                                               {
                                                   card.BiggestHeapReached = request.TargetHeapId;
                                               }
                                     });

            await cards.ForEachAsync(card => card.CurrentHeap = request.TargetHeapId);

            if (request.TargetHeapId == 0)
            {
                await cards.ForEachAsync(card => card.NbTimesInNotLearnedHeap++);
            }

            await dbContext.SaveChangesAsync();
        }