示例#1
0
        public Task <bool> Handle(UpdateCardTypeCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var transactionType  = new CardType(message.Id, message.Name);
            var existingCardType = _cardTypeRepository.GetByName(transactionType.Name);

            if (existingCardType != null && existingCardType.Id != transactionType.Id)
            {
                if (!existingCardType.Equals(transactionType))
                {
                    Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card type name has already been taken."));
                    return(Task.FromResult(false));
                }
            }

            _cardTypeRepository.Update(transactionType);

            if (Commit())
            {
                Bus.RaiseEvent(new CardTypeUpdatedEvent(message.Id, message.Name));
            }

            return(Task.FromResult(true));
        }
示例#2
0
        // PUT api/cardtype/5
        public WebApiResult <CardTypeItem> Put(int id, [FromBody] UpdateCardTypeCommand command)
        {
            var result = _repository.ExecuteCommand(command);

            return(AutoMapper.Mapper.Map <CommandResult <CardType>, WebApiResult <CardTypeItem> >(result));
        }