Exemplo n.º 1
0
        public static async Task AddCardAsync(DbContextOptions <MemCheckDbContext> testDB, Guid deck, Guid card, int?heap = null, DateTime?lastLearnUtcTime = null, DateTime?addToDeckUtcTime = null)
        {
            heap ??= RandomHelper.Heap();
            lastLearnUtcTime ??= RandomHelper.Date();

            using var dbContext = new MemCheckDbContext(testDB);

            DateTime expiryTime;

            if (heap.Value != CardInDeck.UnknownHeap)
            {
                var heapingAlgo = await HeapingAlgorithm.OfDeckAsync(dbContext, deck);

                expiryTime = heapingAlgo.ExpiryUtcDate(heap.Value, lastLearnUtcTime.Value);
            }
            else
            {
                expiryTime = DateTime.MinValue;
            }

            var cardForUser = new CardInDeck()
            {
                CardId                  = card,
                DeckId                  = deck,
                CurrentHeap             = heap.Value,
                LastLearnUtcTime        = lastLearnUtcTime.Value,
                ExpiryUtcTime           = expiryTime,
                AddToDeckUtcTime        = addToDeckUtcTime ?? DateTime.UtcNow,
                NbTimesInNotLearnedHeap = 1,
                BiggestHeapReached      = heap.Value
            };

            dbContext.CardsInDecks.Add(cardForUser);
            await dbContext.SaveChangesAsync();
        }