コード例 #1
0
        private void RaiseClaimDisbursedEvent(DisburseClaim command, string electionId)
        {
            var claimDisbursed = new ClaimDisbursedEvent
            {
                ClaimAmount        = _state.ClaimAmount.Amount,
                ClaimId            = command.ClaimId,
                DisbursementAmount = _state.ClaimAmount.Amount,
                ElectionId         = electionId,
            };

            ApplyEvent(claimDisbursed, @event => _state.Apply(@event));
        }
コード例 #2
0
        private void RaiseClaimNotDisbursedEvent(DisburseClaim command, string reason)
        {
            var claimNotDisbursedEvent = new ClaimNotDisbursedEvent
            {
                ClaimAmount = _state.ClaimAmount.Amount,
                ClaimId     = command.ClaimId,
                ClaimType   = _state.ClaimType,
                Reason      = reason,
            };

            ApplyEvent(claimNotDisbursedEvent, @event => _state.Apply(@event));
        }
コード例 #3
0
        public void DisburseClaim(DisburseClaim command, IElectionsReadModel electionsReadModel)
        {
            var         elections = electionsReadModel.GetElectionsForParticipant(command.ParticipantId);
            ElectionDto election  = null;

            if (TryGetElection(elections, _state.ClaimType, out election))
            {
                var electionBalance = electionsReadModel.GetElectionBalance(election.Id).BalanceRemaining;
                if (electionBalance - _state.ClaimAmount.Amount < 0)
                {
                    RaiseClaimNotDisbursedEvent(command,
                                                string.Format(
                                                    "Your remaining election balance is {0} which is not enough to cover your claim for {1}",
                                                    electionBalance, _state.ClaimAmount.Amount));
                    return;
                }
                RaiseClaimDisbursedEvent(command, election.Id);
            }
            else
            {
                RaiseClaimNotDisbursedEvent(command, string.Format("No election matches the claim type '{0}'", _state.ClaimType));
            }
        }