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)); }
public CardBrandViewModel GetByName(string name) { return(_mapper.Map <CardBrandViewModel>(_CardBrandRepository.GetByName(name))); }