/// <summary> /// /// </summary> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <Unit> Handle(RemoveProductCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { foreach (var error in request.ValidationResult.Errors) { await _eventDispatcher.RaiseEvent(new DomainNotification(request.MessageType, error.ErrorMessage)); } return(Unit.Value); } var product = _productRepository.FindById(request.Id); if (product == null) { await _eventDispatcher.RaiseEvent(new DomainNotification(request.MessageType, @"The product does not exit in system")); return(Unit.Value); } _productRepository.Delete(product); _unitOfWork.Commit(); return(Unit.Value); }
public Task <bool> Handle(RemoveProductCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(Task.FromResult(false)); } _productRepository.Remove(request.ProductId); if (Commit()) { _bus.RaiseEvent(new ProductRemovedEvent(request.ProductId)); } return(Task.FromResult(true)); }
public void Handle(RemoveProductCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } _ProductRepository.Remove(message.Id); if (Commit()) { Bus.RaiseEvent(new ProductRemovedEvent(message.Id)); } }
public Task <bool> Handle(RemoveProductCommand command, CancellationToken cancellationToken) { if (!command.IsValid()) { NotifyErrors(command); return(Task.FromResult(false)); } _productRepository.Remove(command.Id); if (!Commit()) { return(Task.FromResult(false)); } return(Task.FromResult(true)); }
public async Task <Unit> Handle(RemoveProductCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(await Unit.Task); } _productRepository.Remove(message.Id); if (Commit()) { await Bus.RaiseEvent(new ProductRemovedEvent(message.Id)); } return(await Unit.Task); }
public Task <bool> Handle(RemoveProductCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(Task.FromResult(false)); } _productRepository.Remove(message.Id); if (Commit()) { Bus.RaiseEvent(new ProductRemovedEvent(message.Id)); } return(Task.FromResult(true)); }
public async Task <ValidationResult> Handle(RemoveProductCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { return(message.ValidationResult); } var product = await _productRepository.GetById(message.Id); if (product is null) { AddError("The product doesn't exists."); return(ValidationResult); } product.AddDomainEvent(new ProductRemovedEvent(message.Id)); _productRepository.Remove(product); return(await Commit(_productRepository.UnitOfWork)); }
public void RemoveProduct_ShouldBeSuccess() { var command = new RemoveProductCommand(Guid.NewGuid()); Assert.True(command.IsValid()); }
public void RemoveProduct_ShouldReturnErrorWhenIdIsInvalid() { var command = new RemoveProductCommand(Guid.Empty); Assert.False(command.IsValid()); }