public async Task <RemoveProductValidationResult> Validate(RemoveProductCommand command) { if (command == null) { throw new ArgumentNullException(nameof(command)); } var product = await _repository.Get(command.ProductId); if (product == null) { return(new RemoveProductValidationResult(ErrorDescriptions.TheProductDoesntExist)); } var shop = await _shopRepository.Get(product.ShopId); if (shop == null) { return(new RemoveProductValidationResult(ErrorDescriptions.TheShopDoesntExist)); } if (shop.Subject != command.Subject) { return(new RemoveProductValidationResult(ErrorDescriptions.TheProductCannotBeRemovedByYou)); } return(new RemoveProductValidationResult()); }
public async Task <IActionResult> RemoveProduct(RemoveProductCommand command) { command.UserId = UserId; await bus.SendAsync(command); return(Response()); }
private void OnCloseTab(object obj) { var returnedObject = obj as Product; if (returnedObject == null) { RemoveProductCommand.RaiseCanExecuteChanged(); return; } RefreshSource(); if (ProductCollection.Count == 0) { return; } SelectedProduct = ProductCollection.First(); foreach (var p in ProductCollection) { if (p.Code.Equals(returnedObject.Code)) { SelectedProduct = p; } } }
/// <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 void TestMethodRemoveProduct() { var command = new RemoveProductCommand(); var result = _tyrion.Execute(command).Result; Assert.IsTrue(result.Successed); }
public async Task <IActionResult> RemoveProduct(int id, int productId, int quantity = 1) { var command = new RemoveProductCommand { CartId = id, ProductId = productId, Quantity = quantity }; var cart = await _mediator.Send(command); return(Ok(cart)); }
public IActionResult delete([FromRoute] int sku) { var command = new RemoveProductCommand { sku = sku }; var result = (CommandResult)handler.handle(command); return(result.success ? Ok(result) : (IActionResult)BadRequest(result)); }
public void Handle(RemoveProductCommand message) { Validate(message); _productRepository.Remove(message.Id); if (Commit()) { RaiseEvent(new ProductRemovedEvent(message.Id)); } }
public void RemoveProduct_ShouldReturnErrorWhenCommandIsInvalid() { // Arrange var productCommand = new RemoveProductCommand(Guid.Empty); // Act var result = productCommandHandler.Handle(productCommand, new CancellationToken()); // Assert Assert.False(result.Result); }
public void RemoveProduct_ShouldBeSuccess() { // Arrange var productCommand = new RemoveProductCommand(Guid.NewGuid()); // Act var result = productCommandHandler.Handle(productCommand, new CancellationToken()); // Assert Assert.True(result.Result); }
public Task <bool> Handle(RemoveProductCommand message, CancellationToken cancellationToken) { _productRepository.Remove(message.Id); if (Commit()) { Bus.RaiseEvent(new ProductRemovedEvent(message.Id)); } return(Task.FromResult(true)); }
private void EditProductCommandExecute() { NavigationParameters parameters = new NavigationParameters(); parameters.Add("selectedProduct", SelectedProduct); CurrentRegionManager.Regions[RegionNames.TabRegion].RequestNavigate("ProductAddEditView", parameters); _usageControlService.SetUsed(SelectedProduct); RemoveProductCommand.RaiseCanExecuteChanged(); }
public async Task<IActionResult> DeleteProductAsync(int productId) { var removeProductCommand = new RemoveProductCommand(productId); _logger.LogInformation($"Sending command for deleting product with id {productId}"); var commandResult = await _mediator.Send(removeProductCommand); _logger.LogInformation($"Command handled successfuly for removing product with id {productId}"); return Ok(commandResult); }
private void RefreshSource() { _products.Clear(); var returnedProducts = new DbService().ReadFromDb; foreach (var p in returnedProducts) { _products.Add(p); } EditProductCommand.RaiseCanExecuteChanged(); RemoveProductCommand.RaiseCanExecuteChanged(); }
public ICommandResult handle(RemoveProductCommand command) { AddNotifications(command.Notifications); if (Invalid) { return(new CommandResult(false, "Por favor, corrija os campos abaixo", Notifications)); } var deleted = productRepository.delete(command.sku); return(deleted ? new CommandResult(true, "Produto removido com êxito", command) : new CommandResult(false, "sku não encontrada", command)); }
public Result Handle(RemoveProductCommand command) { var product = _productsRepository.GetById(command.Id); if (product == null) { return(Result.Failure("Product with given ID does not exist.")); } product.Remove(); _productsRepository.Update(product); return(Result.Success()); }
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 override void OnNavigatedTo(NavigationContext navigationContext) { if (!IsBeenNavigated) { RefreshSource(); if (ProductCollection.Count > 0) { SelectedProduct = ProductCollection[0]; } IsBeenNavigated = true; } RemoveProductCommand.RaiseCanExecuteChanged(); }
public void Handle(RemoveProductCommand message) { if (!message.IsValid()) { NotifyValidationErrors(message); return; } _ProductRepository.Remove(message.Id); if (Commit()) { Bus.RaiseEvent(new ProductRemovedEvent(message.Id)); } }
public RemoveProductCommandHandlerTest() { basketRedisService = new Mock <IBasketRedisService>(); command = new RemoveProductCommand(userId, productId); commandHandler = new RemoveProductCommandHandler(basketRedisService.Object); basketDto = new UserBasketDto { Products = new List <BasketProduct>() { new BasketProduct { Id = productId } } }; }
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 request, CancellationToken cancellationToken) { var order = await GetOpenenedOrderFromUser(request.UserId); if (order == null) { return(Unit.Value); } order.RemoveItemByProductId(request.ProductId); await orderRepository.UpdateAsync(order); Commit(); await bus.InvokeAsync(new RemoveProductEvent(order.Id, request.ProductId)); return(Unit.Value); }
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 Handle(RemoveProductCommand message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var product = await _productRepository.Get(message.ProductId); await _productRepository.Delete(message.ProductId); _eventPublisher.Publish(new ProductRemovedEvent { ProductId = message.ProductId, CommonId = message.CommonId, ShopId = product.ShopId }); }
public async Task <IActionResult> Execute(RemoveProductCommand removeProductCommand) { if (removeProductCommand == null) { throw new ArgumentNullException(nameof(removeProductCommand)); } var validationResult = await _validator.Validate(removeProductCommand); if (!validationResult.IsValid) { var error = _responseBuilder.GetError(ErrorCodes.Server, validationResult.Message); return(_controllerHelper.BuildResponse(System.Net.HttpStatusCode.BadRequest, error)); } _commandSender.Send(removeProductCommand); return(new OkResult()); }
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 CallRemoveProductInProductService_WhenProductIdIsPassedAndUserIsLogged() { // Arange var contextMock = new Mock <IStoreContext>(); var writerMock = new Mock <IWriter>(); var readerMock = new Mock <IReader>(); var productServiceMock = new Mock <IProductService>(); var userServiceMock = new Mock <IUserService>(); var loggedUserProviderMock = new Mock <ILoggedUserProvider>(); userServiceMock.Setup(m => m.IsUserLogged()).Returns(true); var command = new RemoveProductCommand(contextMock.Object, writerMock.Object, readerMock.Object, productServiceMock.Object, userServiceMock.Object, loggedUserProviderMock.Object); // Act command.Execute(); // Assert productServiceMock.Verify(m => m.RemoveProductWithId(It.IsAny <string>()), Times.Once); }
public void ReturnCustomMessage_WhenUserIsNotLogged() { // Arange var contextMock = new Mock <IStoreContext>(); var writerMock = new Mock <IWriter>(); var readerMock = new Mock <IReader>(); var productServiceMock = new Mock <IProductService>(); var userServiceMock = new Mock <IUserService>(); var loggedUserProviderMock = new Mock <ILoggedUserProvider>(); userServiceMock.Setup(m => m.IsUserLogged()).Returns(false); var command = new RemoveProductCommand(contextMock.Object, writerMock.Object, readerMock.Object, productServiceMock.Object, userServiceMock.Object, loggedUserProviderMock.Object); string expectedResult = "You must Login First!"; // Act var actualResul = command.Execute(); // Assert Assert.AreEqual(expectedResult, actualResul); }
public void RemoveProduct_ShouldBeSuccess() { var command = new RemoveProductCommand(Guid.NewGuid()); Assert.True(command.IsValid()); }