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

            _categoriaRepository.Remove(message.Id);

            if (Commit())
            {
                Bus.RaiseEvent(new CategoriaRemovedEvent(message.Id));
            }

            return(Task.FromResult(true));
        }
        public async Task <ValidationResult> Handle(RemoveCategoriaCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                return(message.ValidationResult);
            }

            var categoria = await _categoriaRepository.GetById(message.Id);

            if (categoria is null)
            {
                AddError("A categoria não exite.");
                return(ValidationResult);
            }

            categoria.AddDomainEvent(new CategoriaRemovedEvent(message.Id));

            _categoriaRepository.Remove(categoria);

            return(await Commit(_categoriaRepository.UnitOfWork));
        }