Example #1
0
        public async Task <CreateOptionResponse> Handle(
            CreateOptionProductRequest request, CancellationToken cancellationToken)
        {
            var product = await _productRepository.GetByIdAsync(request.IdProduct);

            if (product == null)
            {
                _notificationContext.AddNotification("product null", "O produto não foi encontrado");
                return(null);
            }

            var option = new Option(request.Name);

            if (option.Invalid)
            {
                _notificationContext.AddNotifications(option.ValidationResult);
                return(null);
            }

            product.HasOne(option);

            await _optionRepository.CreateAsync(option);

            return((CreateOptionResponse)option);
        }
        public async Task <CreateOptionItemResponse> Handle(
            CreateOptionItemRequest request, CancellationToken cancellationToken)
        {
            var item = await _itemRepository.GetByIdAsync(request.IdItem);

            if (item == null)
            {
                _notificationContext.AddNotification("Item null", "Item não encontrado");
                return(null);
            }

            var option = new Option(request.Name);

            if (option.Invalid)
            {
                _notificationContext.AddNotifications(option.ValidationResult);
                return(null);
            }

            item.HasOne(option);

            await _optionRepository.CreateAsync(option);

            return(new CreateOptionItemResponse(item, option));
        }
        public async Task <CreateOptionResponse> Handle(
            CreateOptionRequest request, CancellationToken cancellationToken)
        {
            var option = new Option(request.Name);

            if (option.Invalid)
            {
                _notificationContext.AddNotifications(option.ValidationResult);
                return(null);
            }

            await _optionRepository.CreateAsync(option);

            return((CreateOptionResponse)option);
        }