コード例 #1
0
            public async Task <MediatR.Unit> Handle(DeleteProductCategoryCommand request, CancellationToken cancellationToken)
            {
                // get productCategory by id
                var productCategoryFromRepo = await _productCategoryRepository.FindByIdAsync(request.ProductCategoryId);

                if (productCategoryFromRepo == null)
                {
                    throw new ProductCategoryNotFoundException(request.ProductCategoryId);
                }

                if (productCategoryFromRepo.Products.Count > 0)
                {
                    throw new ProductCategoryContainsProductsException(request.ProductCategoryId);
                }

                // we call delete productCategory to rase delete productCategory event to sync with algolia
                productCategoryFromRepo.Delete();

                // update productCategory with the new unit deleted
                _productCategoryRepository.Delete(productCategoryFromRepo);

                // save changes in the database and rase ProductCategoryUpdated event
                await _productCategoryRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

                return(MediatR.Unit.Value);
            }
コード例 #2
0
        public async Task Handle(ProductCategoryUpdated notification, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Brimo API EventHandelr: {Name} {@UserId} {@UserName} {@Request}", nameof(ProductCategoryUpdated), _currentUserService.UserId, _currentUserService.Name, notification);

            var productCategory = await _productCategoryRepository.FindByIdAsync(notification.ProductCategory.Id.ToString());

            var productCategoryToAddToAlgoia = _mapper.Map <AlgoliaProductCategoryVM>(productCategory);

            await _searchEngine.UpdateEntity(productCategoryToAddToAlgoia, "productCategories");
        }
コード例 #3
0
            public async Task <string> Handle(UpdateProductCategoryCommand request, CancellationToken cancellationToken)
            {
                var productCategoryFromRepo = await _productCategoryRepository.FindByIdAsync(request.ProductCategoryId);

                if (productCategoryFromRepo == null)
                {
                    throw new ProductCategoryNotFoundException(request.ProductCategoryId);
                }

                productCategoryFromRepo.Update(request.Name, request.PhotoUrl);

                _productCategoryRepository.Update(productCategoryFromRepo);

                await _productCategoryRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

                return(productCategoryFromRepo.Id.ToString());
            }