public async Task <ICommandResult> Handle(DeleteProductCommand request, CancellationToken cancellationToken) { request.Validate(); if (!request.IsValid) { return(new CommandResult(false, "Problemas ao cadastrar o produto..", request.Notifications)); } var deletedProduct = await _productRepository.GetProductAsync(request.Id); if (deletedProduct == null) { return(new CommandResult(false, "O produto não foi encontrado.", null)); } await _productRepository.DeleteProductAsync(deletedProduct); var buyingProduct = false; var productDomainEvent = new ProductOperationDomainEvent(EventAction.DELETE, deletedProduct, buyingProduct); await _domainEntityEventHandler.Raise(productDomainEvent); return(new CommandResult(true, "Produto excluído com sucesso!", request)); }
public ProductViewModel(ProductDataService productDataService, IEventAggregator eventAggregator) { this.productDataService = productDataService; SearchProductCommand = new SearchProductCommand(this); DeleteProductCommand = new DeleteProductCommand(this); EditProductCommand = new EditProductCommand(this); }
public async Task <IActionResult> DeleteProduct(UpdateProductCommand command) { var deleteCommand = new DeleteProductCommand(command); var result = await _mediator.Send(deleteCommand); return(result == 0 ? RedirectToAction("Error", new Error(Operation.Name.Delete)) : RedirectToAction("Index")); }
public async Task <IActionResult> Delete(int id) { try { //Log Information - Request _logger.LogInformation($"Received Request: HTTPDELETE api/products/{id}"); //Check if Product exists. Product productInDb = await _mediator.Send(new FindProductByIdQuery() { ProductId = id }); if (productInDb == null) { // Log warning and return HTTP 404 _logger.LogWarning($"Not Found : HTTPDELETE api/products/{id}"); return(NotFound()); } //Create command object DeleteProductCommand deleteCmd = new DeleteProductCommand { ProductId = id }; //Send command await _mediator.Send(deleteCmd); //Return return(NoContent()); } catch (Exception ex) { // Log the failure and return HTTP 500 _logger.LogError($"Error at HTTPDELETE api/products/{id}:{ex}"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <IActionResult> DeleteProduct([FromBody] DeleteProductCommand command) { var response = false; var Ids = command.ProductIds; foreach (var id in Ids) { response = await _repo.DeleteProduct(id); } if (!response) { return(BadRequest( new DeleteRespObj { Deleted = false, Status = new APIResponseStatus { Message = new APIResponseMessage { FriendlyMessage = "Unsuccessful" } } })); } return(Ok( new DeleteRespObj { Deleted = true, Status = new APIResponseStatus { Message = new APIResponseMessage { FriendlyMessage = "Successful" } } })); }
public async Task Execution_should_fail_when_product_id_greater_than_0_is_not_supplied_async() { var command = new DeleteProductCommand(0, Mock.Of<IProductDataProxy>(), Mock.Of<IInventoryItemService>(), Mock.Of<IOrderDataProxy>(), Mock.Of<ITransactionContext>()); var result = await command.ExecuteAsync(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(1); }
public async Task <IActionResult> DeleteProduct(int id) { var command = new DeleteProductCommand(id); var result = await _mediatr.Send(command); return(result != null ? (IActionResult)Ok(new { Message = "success" }) : NotFound(new { Message = "not found" })); }
public async Task DeleteProduct_CommandHandle_DeletesExistingProducty() { //Arrange var productCategory = new AllMarkt.Entities.ProductCategory { Name = "category", Description = "description" }; AllMarktContextIM.ProductCategories.Add(productCategory); await AllMarktContextIM.SaveChangesAsync(); AllMarktContextIM.Products.Add(new AllMarkt.Entities.Product { Name = "Test Name1", Description = "Test Description1", Price = 10, ImageURI = "", State = true, ProductCategory = productCategory }); await AllMarktContextIM.SaveChangesAsync(); var existingProduct = AllMarktContextIM.Products.First(); var deleteProductCommand = new DeleteProductCommand { Id = existingProduct.Id }; //Act await _deleteProductCommandHandler.Handle(deleteProductCommand, CancellationToken.None); //Assert AllMarktContextIM.Products .Should() .NotContain(product => product.Id == deleteProductCommand.Id); }
public async Task <IActionResult> DeleteProductAsync( [FromBody] DeleteProductCommand command) { await Mediator.SendAsync(command).ConfigureAwait(false); return(Ok()); }
public async Task <ActionResult <TodoItem> > DeleteTodoItem(long id) { DeleteProductCommand command = new DeleteProductCommand(id); var result = await _mediator.Send(command); return(result); }
public async Task <ICommandResult> Handle(DeleteProductCommand command) { // Validar ID if (command.Id == Guid.Empty) { AddNotification("Id", "Parametro inválido."); } var product = _productRepository.GetById(command.Id); // Verificar se Escola já está cadastrado if (product == null) { AddNotification("Produto", "Produto não cadastrada"); return(new CommandResult(false, "Dados de entrada in válidos.", this)); } // Checar as notificações if (Invalid) { return(new CommandResult(false, "Não foi possível realizar o cadastro da Escola", this)); } // Escluindo a escola _productRepository.Remove(product); // Retornar informações return(new CommandResult(true, "Exclusão realizada com sucesso!", null)); }
public ActionResult Delete(int id) { var command = new DeleteProductCommand(id); var product = command.Execute(); return(Json(new { success = true }, JsonRequestBehavior.AllowGet)); }
public static DeleteProductCommand DeleteProduct(int productId) { var delete = new DeleteProductCommand(); delete.ProductId = productId; return(delete); }
public async Task SubcribeProductDeleted( DeleteProductCommand command, [FromServices] IMediator mediator, CancellationToken cancellationToken) { await mediator.Send(command, cancellationToken); }
public async Task <IActionResult> DeleteProduct(string id) { try { if (string.IsNullOrWhiteSpace(id)) { throw new Exception("Product Id is not valid"); } var client = _bus.CreateRequestClient <IDeleteProductCommand, IProductDeletedEvent>(_serviceAddress, TimeSpan.FromSeconds(20)); var deleteCompanyCommand = new DeleteProductCommand(id); var response = await client.Request(deleteCompanyCommand); return(Ok(response)); } catch (DbUpdateConcurrencyException ex) { return(Conflict(ex)); } catch (Exception e) { return(BadRequest($"Delete product exception: {e.Message}")); } }
public void DeleteProductValidCommand() { var command = new DeleteProductCommand(new Guid("11111111111111111111111111111111")); command.Validate(); Assert.AreEqual(command.Valid, true); }
public GenericCommandResult Delete( [FromBody] DeleteProductCommand command, [FromServices] ProductHandler handler ) { return((GenericCommandResult)handler.Handle(command)); }
public void Execution_deletes_product_and_associated_inventory_items() { var orderProxy = new Mock <IOrderDataProxy>(); orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(Enumerable.Empty <Order>()); var product = new Product() { ProductID = 1 }; var productDataProxy = new ProductRepository(); productDataProxy.Clear(); productDataProxy.Insert(product); var inventoryDataProxy = new InventoryItemRepository(); inventoryDataProxy.Clear(); inventoryDataProxy.Insert(new InventoryItem() { ProductID = 1 }); var command = new DeleteProductCommand(1, productDataProxy, new InventoryItemService(inventoryDataProxy), orderProxy.Object, new TransactionContextStub()); var result = command.Execute(); result.Success.ShouldBe(true); result.Errors.ShouldBe(null); productDataProxy.GetAll().Count().ShouldBe(0); inventoryDataProxy.GetAll().Count().ShouldBe(0); }
public Task Delete(Guid id) { var command = new DeleteProductCommand(id); _commandBus.ExecuteAsync(command).Wait(); return(Task.CompletedTask); }
public void Handle_GivenInvalidId_ThrowsException() { var command = new DeleteProductCommand { Id = 99 }; Should.ThrowAsync <NotFoundException>(() => _handler.Handle(command, CancellationToken.None)); }
public async Task Execution_should_fail_when_product_id_greater_than_0_is_not_supplied_async() { var command = new DeleteProductCommand(0, Mock.Of <IProductDataProxy>(), Mock.Of <IInventoryItemService>(), Mock.Of <IOrderDataProxy>(), Mock.Of <ITransactionContext>()); var result = await command.ExecuteAsync(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(1); }
public async Task <IActionResult> Delete(int id) { var command = new DeleteProductCommand(id); await _deleteHandler.HandleAsync(command); return(Ok()); }
public void DeleteProductInvalidCommand() { Guid guidID = Guid.Empty; var command = new DeleteProductCommand(guidID); command.Validate(); Assert.AreEqual(command.Valid, false); }
public Task <HttpResponseMessage> Delete(int id) { var command = new DeleteProductCommand(id: id); var product = _service.Delete(command); return(CreateResponse(HttpStatusCode.OK, product)); }
public async Task <IActionResult> DeleteProductAsync(DeleteProductCommand deleteProductCommand) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(await _productService.DeleteProductAsync(deleteProductCommand))); }
public void DeleteProductValidTest() { var command = new DeleteProductCommand(new Guid("11111111111111111111111111111111")); var handler = new ProductHandler(new FakeProductsRepository()); var result = (GenericCommandResult)handler.Handle(command); Assert.AreEqual(result.Sucess, true); }
public async Task <IActionResult> Delete(int id) { var command = new DeleteProductCommand(id); await _mediator.Send(command); return(NoContent()); }
private void InvalidateCommands() { SaveCommand.RaiseCanExecuteChanged(); AddProductCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); DeleteProductCommand.RaiseCanExecuteChanged(); FilterCommand.RaiseCanExecuteChanged(); }
public async Task Handle(DeleteProductCommand command) { var product = new Product(command.Id, command.Name, command.Description, command.Price); await this._repoProduct.Update(product); await this._repoOutbox.New(new Outbox(product.GetType().Name, "Delete", product)); }
public async Task <IHttpActionResult> Delete(Guid id) { var command = new DeleteProductCommand(id); await _productService.DeleteProduct(command); return(Ok()); }
public DeleteProductCommandHandlerTest() { productRepository = new Mock <IProductRepository>(); bus = new Mock <IBus>(); command = new DeleteProductCommand(productId); product = new Product(); commandHandler = new DeleteProductCommandHandler(productRepository.Object, bus.Object); }
public void Execution_should_fail_when_product_is_associated_with_orders_items() { var orderProxy = new Mock<IOrderDataProxy>(); orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(new[] { new Order() }); var command = new DeleteProductCommand(1, Mock.Of<IProductDataProxy>(), Mock.Of<IInventoryItemService>(), orderProxy.Object, Mock.Of<ITransactionContext>()); var result = command.Execute(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(1); }
public void Execution_deletes_product_and_associated_inventory_items() { var orderProxy = new Mock<IOrderDataProxy>(); orderProxy.Setup(proxy => proxy.GetByProduct(1)).Returns(Enumerable.Empty<Order>()); var product = new Product() { ProductID = 1 }; var productDataProxy = new ProductRepository(); productDataProxy.Clear(); productDataProxy.Insert(product); var inventoryDataProxy = new InventoryItemRepository(); inventoryDataProxy.Clear(); inventoryDataProxy.Insert(new InventoryItem() { ProductID = 1 }); var command = new DeleteProductCommand(1, productDataProxy, new InventoryItemService(inventoryDataProxy), orderProxy.Object, new TransactionContextStub()); var result = command.Execute(); result.Success.ShouldBe(true); result.Errors.ShouldBe(null); productDataProxy.GetAll().Count().ShouldBe(0); inventoryDataProxy.GetAll().Count().ShouldBe(0); }
public async Task Execution_should_fail_when_product_is_associated_with_orders_items_async() { var orderProxy = new Mock<IOrderDataProxy>(); orderProxy.Setup(proxy => proxy.GetByProductAsync(1)).Returns(Task.FromResult<IEnumerable<Order>>(new[] { new Order() })); var command = new DeleteProductCommand(1, Mock.Of<IProductDataProxy>(), Mock.Of<IInventoryItemService>(), orderProxy.Object, Mock.Of<ITransactionContext>()); var result = await command.ExecuteAsync(); result.Success.ShouldBe(false); result.Errors.Count().ShouldBe(1); }