Exemplo n.º 1
0
        private void CardAnswered(Guid cardId, SessionCardStatus status)
        {
            var sessionCard = _sessionCards.FirstOrDefault(sc => sc.CardId == cardId);

            if (sessionCard == null)
            {
                throw new DomainException.SessionCardNotFoundException();
            }

            if (sessionCard.Status != SessionCardStatus.NotAnswered)
            {
                throw new DomainException.CardAlreadyAnsweredException();
            }

            sessionCard.Status = status;
        }
Exemplo n.º 2
0
 public ApplySessionCardCommand(Guid cardId, SessionCardStatus status)
 {
     CardId = cardId;
     Status = status;
 }
Exemplo n.º 3
0
        public async Task ApplySessionCardAsync(Guid userId, string deck, Guid cardId, SessionCardStatus status)
        {
            var session = _cache.Get <SessionStateDto>(GetSessionStateKey(userId, deck));
            var cards   = _cache.Get <List <SessionCardDto> >(GetSessionCardsKey(session.Id));

            var card = cards.First(x => x.CardId == cardId);

            cards.Remove(card);

            if (status == SessionCardStatus.DoNotYet)
            {
                if (cards.Count > 5)
                {
                    cards.Insert(5, card);
                }
                else
                {
                    cards.Add(card);
                }
            }
            else if (status == SessionCardStatus.NotSure)
            {
                cards.Add(card);
            }
            else
            {
                session.IncrementCounter();
            }

            if (cards.Count > 0)
            {
                session.SetCard(cards.First());
                _cache.Set(GetSessionStateKey(userId, deck), session, TimeSpan.FromHours(1));
                _cache.Set(GetSessionCardsKey(session.Id), cards, TimeSpan.FromHours(1));
            }
            else
            {
                session.Finish();
                _cache.Set(GetSessionStateKey(userId, deck), session, TimeSpan.FromSeconds(1));
                _cache.Remove(GetSessionCardsKey(session.Id));
            }

            await Task.CompletedTask;
        }