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

            //var cardBrand = new CardBrand(Guid.NewGuid(), message.Name);
            var cardBrand = new CardBrand(message.Id, message.Name);

            if (_cardBrandRepository.GetByName(message.Name) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card brand name has already been taken."));
                return(Task.FromResult(false));
            }

            if (_cardBrandRepository.GetById(message.Id) != null)
            {
                Bus.RaiseEvent(new DomainNotification(message.MessageType, "The card brand id has already been taken."));
                return(Task.FromResult(false));
            }

            _cardBrandRepository.Add(cardBrand);

            if (Commit())
            {
                Bus.RaiseEvent(new CardBrandRegisteredEvent(cardBrand.Id, cardBrand.Name));
            }

            return(Task.FromResult(true));
        }
コード例 #2
0
 public CardBrandViewModel GetByName(string name)
 {
     return(_mapper.Map <CardBrandViewModel>(_CardBrandRepository.GetByName(name)));
 }