Example #1
0
 public Product(ProductData productData, DateTimeProduct dateTimeProduct, ProductInformation productInformation,
                string category, string userId)
 {
     ProductData        = productData;
     DateTimeProduct    = dateTimeProduct;
     ProductInformation = productInformation;
     Category           = category;
     Status             = ProductStatus.IDEAL.Name;
     UserId             = userId;
 }
        public async Task <ICommandResult> Handle(UpdateProductCommand request, CancellationToken cancellationToken)
        {
            request.Validate();

            if (!request.IsValid)
            {
                return(new CommandResult(false, "Problemas ao atualizar o produto..", request.Notifications));
            }

            var requestedProduct = await _productRepository.GetProductAsync(request.Id);

            if (requestedProduct is null)
            {
                return(new CommandResult(false, "O Produto não foi encontrado", null));
            }

            var productData = new ProductData(request.Name, request.Description);

            var productImage = _productFileService.ProcessProductImage(request.ImageBase64);

            productData.ChangeImage(productImage);

            var datetimeProduct    = new DateTimeProduct(request.PurchaseDate, requestedProduct.DateTimeProduct.ExpirationDate);
            var productInformation = new ProductInformation(request.Quantity, request.MeasurementUnit);

            requestedProduct.ChangeProductData(productData);
            requestedProduct.ChangeDateTimeProduct(datetimeProduct);
            requestedProduct.ChangeProductInformation(productInformation);
            requestedProduct.ChangeStatus(request.ProductStatus);
            requestedProduct.ChangeCategory(request.Category);

            var updatedProduct = await _productRepository.UpdateProductAsync(requestedProduct);

            if (updatedProduct is null)
            {
                return(new CommandResult(false, "Problemas ao atualizar o produto..", null));
            }

            if (!updatedProduct.VerifyQuantity())
            {
                var buyingProduct      = true;
                var productDomainEvent = new ProductOperationDomainEvent(EventAction.UPDATE, updatedProduct, buyingProduct);

                await _domainEntityEventHandler.Raise(productDomainEvent);
            }

            return(new CommandResult(true, "Produto atualizado com sucesso!", request));
        }
Example #3
0
        public async Task <ICommandResult> Handle(CreateProductCommand request, CancellationToken cancellationToken)
        {
            request.Validate();

            if (!request.IsValid)
            {
                return(new CommandResult(false, "Problemas ao cadastrar o produto..", request.Notifications));
            }

            var productExists = await _productRepository.VerifyProductoAsync(request.Name, request.User);

            if (productExists)
            {
                return(new CommandResult(false, "O produto já esta cadastrado.", null));
            }

            var productData         = new ProductData(request.Name, request.Description);
            var datetimeProduct     = new DateTimeProduct(request.PurchaseDate, request.ExpirationDate);
            var produtctInformation = new ProductInformation(request.Quantity, request.MeasurementUnit);

            var productImage = _productFileService.ProcessProductImage(request.ImageBase64);

            productData.ChangeImage(productImage);

            var newProduct = new Product(productData, datetimeProduct, produtctInformation, request.Category, request.User);

            var createdProduct = await _productRepository.CreateProductAsync(newProduct);

            if (createdProduct is null)
            {
                return(new CommandResult(false, "O produto não foi cadastrado.", null));
            }

            var buyingProduct      = false;
            var productDomainEvent = new ProductOperationDomainEvent(EventAction.INSERT, createdProduct, buyingProduct);

            await _domainEntityEventHandler.Raise(productDomainEvent);

            return(new CommandResult(true, "Produto cadastrado com sucesso!", request));
        }
Example #4
0
 public void ChangeDateTimeProduct(DateTimeProduct dateTimeProduct) => DateTimeProduct = dateTimeProduct;