public async Task <CreateCardCommandResult> Handle(CreateCardCommand command)
        {
            if (cardRepository.IsDuplicatedCardNumber(command.Number))
            {
                notificationHandler.AddNotification(nameof(CreateCardCommand.Number), $"Card number already exists {command.Number}");
            }

            var newCard = Card.CreateNewCard(command.Number, command.CardHolder, command.ExpirationDate);

            newCard.Validate(notificationHandler);

            if (newCard.Valid)
            {
                var success = await cardRepository.Add(newCard);

                if (success)
                {
                    var cardCreatedEvent = new CardCreatedEvent(newCard);

                    eventBus.Publish(cardCreatedEvent);
                }

                return(new CreateCardCommandResult(newCard.Id, newCard.Number, newCard.CardHolder, newCard.ExpirationDate, success));
            }

            return(CommandResult.CreateFailResult <CreateCardCommandResult>());
        }
예제 #2
0
        public async Task <CreateCardCommandResult> Handle(CreateCardCommand command)
        {
            var newCard = Card.CreateNewCard(command.Number, command.CardHolder, command.ExpirationDate);

            var success = await cardRepository.Add(newCard);

            if (success)
            {
                var cardCreatedEvent = new CardCreatedEvent(newCard);

                eventBus.Publish(cardCreatedEvent);
            }

            return(new CreateCardCommandResult(newCard.Id, newCard.Number, newCard.CardHolder, newCard.ExpirationDate, success));
        }
예제 #3
0
 private void OnCardCreated(CardCreatedEvent cardAccountCreated)
 {
     Id = cardAccountCreated.HashedPan;
 }
예제 #4
0
 private void OnCardCreated(CardCreatedEvent sender)
 {
     Add(sender.View);
 }