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());
        }
예제 #2
0
        public async Task <IActionResult> RemoveProduct(RemoveProductCommand command)
        {
            command.UserId = UserId;
            await bus.SendAsync(command);

            return(Response());
        }
예제 #3
0
        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);
        }
예제 #5
0
        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));
        }
예제 #7
0
        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));
        }
예제 #8
0
 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);
        }
예제 #11
0
        public Task <bool> Handle(RemoveProductCommand message, CancellationToken cancellationToken)
        {
            _productRepository.Remove(message.Id);

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

            return(Task.FromResult(true));
        }
예제 #12
0
        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);
        }
예제 #14
0
        private void RefreshSource()
        {
            _products.Clear();
            var returnedProducts = new DbService().ReadFromDb;

            foreach (var p in returnedProducts)
            {
                _products.Add(p);
            }

            EditProductCommand.RaiseCanExecuteChanged();
            RemoveProductCommand.RaiseCanExecuteChanged();
        }
예제 #15
0
        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));
        }
예제 #16
0
        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());
        }
예제 #17
0
 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));
 }
예제 #18
0
        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
                    }
                }
            };
        }
예제 #21
0
        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));
        }
예제 #22
0
        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);
        }
예제 #23
0
        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));
        }
예제 #25
0
        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
            });
        }
예제 #26
0
        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));
        }
예제 #28
0
        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);
        }
예제 #29
0
        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);
        }
예제 #30
0
        public void RemoveProduct_ShouldBeSuccess()
        {
            var command = new RemoveProductCommand(Guid.NewGuid());

            Assert.True(command.IsValid());
        }