public async Task <bool> Handle(UpdateFulanoCommand message, CancellationToken cancellationToken) { _fulanoRepository.Update(message.Entity); if (await Commit()) { await _mediatorHandler.RaiseDomainEventAsync(new FulanoUpdatedEvent(message.Entity.Id)); } return(true); }
public override async Task UpdateAsync(FulanoModel model) { var command = new UpdateFulanoCommand(model.Id) { Entity = _mapper.Map <Fulano>(model) }; if (!command.IsValid()) { await RaiseValidationErrorsAsync(command); return; } var dbEntity = await _fulanoRepository.GetByIdAsync(command.Entity.Id); if (dbEntity == null) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.RegistroNaoEncontrado.Message)); return; } var listaFulano = await _fulanoRepository.GetAllAsync(); if (listaFulano.Any(c => c.Id != command.Entity.Id && string.Equals(c.Nome, command.Entity.Nome, StringComparison.CurrentCultureIgnoreCase))) { await _mediatorHandler.RaiseDomainNotificationAsync(new DomainNotification(command.MessageType, CoreUserMessages.ValorDuplicadoO.Format("Nome").Message)); return; } _mapper.Map(command.Entity, dbEntity); command.Entity = dbEntity; await _mediatorHandler.SendCommandAsync(command); }