Beispiel #1
0
 public void Apply(VotingCreatedEvent @event)
 {
     Id          = @event.VotingId;
     _topics     = @event.Topics;
     _votingPair = VotingPair.Empty();
     _winner     = string.Empty;
 }
Beispiel #2
0
        public static VotingAggregate CreateFrom(VotingSnapshot votingSnapshot)
        {
            var votingAggregate = new VotingAggregate();

            votingAggregate._winner     = votingSnapshot.Winner;
            votingAggregate._votingPair = VotingPair.CreateFrom(votingSnapshot.Topics);
            return(votingAggregate);
        }
Beispiel #3
0
        public VotingSnapshot(Guid votingId, VotingPair votingPair, string winner)
        {
            VotingId = votingId;
            Winner   = winner;

            votingPair = votingPair ?? VotingPair.Empty();
            Topics     = new Dictionary <string, int> ();
            if (!votingPair.IsEmpty)
            {
                Topics.Add(votingPair.TopicA.topic, votingPair.TopicA.votes);
                Topics.Add(votingPair.TopicB.topic, votingPair.TopicB.votes);
            }
        }
Beispiel #4
0
        public void StartNextVoting()
        {
            AssertNotFinishedVoting();
            _topics = _topics.Concat(_votingPair.GetWinners()).ToArray();

            if (_topics.Count() == 1)
            {
                RaiseEvent(new VotingFinishedEvent(Id, _topics.Single()));
            }
            else
            {
                RaiseEvent(new VotingStartedEvent(Id, _topics.Skip(2).ToArray(), VotingPair.Create(_topics.Take(2).ToArray())));
            }
        }
Beispiel #5
0
 public void Apply(TopicVotedEvent @event)
 {
     Id          = @event.VotingId;
     _votingPair = _votingPair.VoteForTopic(@event.Topic);
 }
Beispiel #6
0
 public void Apply(VotingStartedEvent @event)
 {
     Id          = @event.VotingId;
     _votingPair = @event.VotingPair;
     _topics     = @event.RemainingTopics;
 }