public void Apply(VotingCreatedEvent @event) { Id = @event.VotingId; _topics = @event.Topics; _votingPair = VotingPair.Empty(); _winner = string.Empty; }
public static VotingAggregate CreateFrom(VotingSnapshot votingSnapshot) { var votingAggregate = new VotingAggregate(); votingAggregate._winner = votingSnapshot.Winner; votingAggregate._votingPair = VotingPair.CreateFrom(votingSnapshot.Topics); return(votingAggregate); }
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); } }
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()))); } }
public void Apply(TopicVotedEvent @event) { Id = @event.VotingId; _votingPair = _votingPair.VoteForTopic(@event.Topic); }
public void Apply(VotingStartedEvent @event) { Id = @event.VotingId; _votingPair = @event.VotingPair; _topics = @event.RemainingTopics; }