Beispiel #1
0
        private static async Task RunAsync()
        {
            var messageDispatcher = ServiceProvider.GetRequiredService <IMessageDispatcher>();
            var dataStore         = ServiceProvider.GetRequiredService <IDataStore>();

            var command       = new ProductCreateCommand(Guid.NewGuid(), "myProduct");
            var commandResult = await messageDispatcher.DispatchAsync(command);

            await Console.Out.WriteLineAsync(commandResult.ToString());

            var product = await LoadProductUncachedAsync(command.Id);

            await Console.Out.WriteLineAsync(product.ProductName);

            var listModel = await LoadProductListModelUncachedAsync(command.Id);

            await Console.Out.WriteLineAsync(listModel.ProductName);

            var deleteModel = await dataStore.FindOneAsync <ProductDeleteModel>(p => p.Id == command.Id);

            var deleteCommand       = new ProductDeleteCommand(deleteModel.Id, deleteModel.ConcurrencyToken);
            var deleteCommandResult = await messageDispatcher.DispatchAsync(deleteCommand);

            product = await LoadProductUncachedAsync(command.Id);

            await Console.Out.WriteLineAsync($"Product is{(product == null ? "" : " not")} deleted.");

            listModel = await LoadProductListModelUncachedAsync(command.Id);

            await Console.Out.WriteLineAsync($"Product is{(listModel == null ? "" : " not")} deleted.");

            await Console.In.ReadLineAsync();
        }
Beispiel #2
0
        public async Task <ICommandResult> Handle(ProductDeleteCommand command)
        {
            //FFV
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(
                           false,
                           HttpStatusCode.BadRequest,
                           command.Notifications));
            }

            var _verify = await _productRepository.FindById(command.Id);

            if (_verify == null)
            {
                return(new GenericCommandResult(false, HttpStatusCode.NotFound, "Não localizado na base"));
            }

            var product = new Product
            {
                Id = command.Id
            };

            var _result = await _productRepository.Delete(product);

            //retorna o resultado
            if (!_result)
            {
                return(new GenericCommandResult(false, HttpStatusCode.BadRequest, _result));
            }

            return(new GenericCommandResult(true, HttpStatusCode.OK, _result));
        }
Beispiel #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var command = new ProductDeleteCommand {
                Id = id
            };

            return(Ok(await mediator.Send(command)));
        }
Beispiel #4
0
        public async Task <GenericCommandResult> DeleteProduct(
            [FromQuery] int id,
            [FromServices] IHandler <ProductDeleteCommand> handler)
        {
            var command = new ProductDeleteCommand(id);

            return((GenericCommandResult)await handler.Handle(command));
        }
        public CommandResult Handle(ProductDeleteCommand command)
        {
            var product = _repository.GetById(command.Id);

            if (product == null)
            {
                return(new CommandResult(false, "Produto não encontrado na base de dados. ", null));
            }

            _repository.Delete(product.Id);

            return(new CommandResult(true, "Produco excluído com sucesso! ", product));
        }
        public void DeleteProductHandler_NotExists_Invalid()
        {
            var repository = new FakeProductRepository();
            var handler    = new ProductHandler(repository);

            string id = repository.GetAll().FirstOrDefault().Id;

            var command = new ProductDeleteCommand();

            command.Id = id;

            var result = handler.Handle(command);

            Assert.True(result.Success, result.Message);
        }
Beispiel #7
0
        public async Task <string> Handle(ProductDeleteCommand request, CancellationToken cancellationToken)
        {
            var product = await repository.GetById(request.Id);

            await repository.Delete(product);

            await mediator.Publish(new ProductActionNotification
            {
                Action = ActionNotification.Deleted,
                Id     = product.Id,
                Name   = product.Name,
                Price  = product.Price
            });

            return(await Task.FromResult("Produto excluído com sceusso."));
        }
Beispiel #8
0
        public CommandResult Delete(ProductDeleteCommand productDelete)
        {
            if (productDelete.IsValid() == false)
            {
                return(CommandResult.Error(productDelete.ValidationResult.ToString()));
            }

            if (_productRepository.Exists(productDelete.Sku) == false)
            {
                return(CommandResult.Error("Sku do produto não existe."));
            }

            _productRepository.Delete(productDelete.Sku);
            _warehouseRepository.Delete(productDelete.Sku);

            return(CommandResult.Ok());
        }
        public CommandResult Delete(ProductDeleteCommand command)
        {
            var result = _handler.Handle(command);

            return(result);
        }
 public void Handle(ProductDeleteCommand command)
 {
     MarkAsDeleted();
 }
 /// <summary>
 /// Yapıcı metod. Her yeni Ürün ViewModel nesnesi oluşturulduğunda çalışır.
 /// </summary>
 public ProductViewModel()
 {
     _product      = new ProductModel(1, "Macbook Pro", "i5 işlemcili Macbook Pro", 3400);
     UpdateCommand = new ProductUpdateCommand(this);
     DeleteCommand = new ProductDeleteCommand(this);
 }
Beispiel #12
0
        public async Task <ActionResult> Delete(ProductDeleteCommand command)
        {
            await MediatorService.ExecuteHandler(command);

            return(NoContent());
        }