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>());
        }
Exemplo n.º 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));
        }
Exemplo n.º 3
0
 private void OnCardCreated(CardCreatedEvent cardAccountCreated)
 {
     Id = cardAccountCreated.HashedPan;
 }
Exemplo n.º 4
0
 private void OnCardCreated(CardCreatedEvent sender)
 {
     Add(sender.View);
 }