private async Task PublishCommandErrorsNotifications(StartOrderCommand message)
 {
     foreach (var error in message.ValidationResult.Errors)
     {
         await _mediatrHandler.PublishNotification(new DomainNotification(message.MessageType, error.ErrorMessage));
     }
 }
 private async Task PublishInvalidCommandNotifications(CancelOrderProcessingAndSupplyStockCommand message)
 {
     foreach (var error in message.ValidationResult.Errors)
     {
         await _mediatrHandler.PublishNotification(new DomainNotification(message.MessageType, error.ErrorMessage));
     }
 }
Exemple #3
0
        private async Task <bool> DebitStockItem(Guid productId, int quantity)
        {
            var product = await _productRepository.GetById(productId);

            if (product == null)
            {
                return(false);
            }

            if (!product.HasStock(quantity))
            {
                await _mediatorHandler.PublishNotification(new DomainNotification("Stock", $"Product - {product.Name} out of stock."));

                return(false);
            }

            product.DebitStock(quantity);

            // TODO: 10 can parameterizable in config file
            if (product.StockQuantity < 10)
            {
                await _mediatorHandler.PublishEvent(new ProductBelowStockEvent(product.Id, product.StockQuantity));
            }

            _productRepository.Update(product);
            return(true);
        }
Exemple #4
0
        public async Task <bool> DebitStock(Guid productId, int quantity)
        {
            var product = await _productRepository.GetById(productId);

            if (product == null)
            {
                return(false);
            }

            if (!product.HasStock(quantity))
            {
                await _mediatrHandler.PublishNotification(new DomainNotification("Stock", $"The product {product.Name} is out of stock."));

                return(false);
            }
            product.DebitStock(quantity);

            // TODO: To parameterize the low stock quantity
            if (product.StockQuantity < 10)
            {
                await _mediatrHandler.PublishEvent(new LowProductStockEvent(product.Id, product.StockQuantity));
            }

            _productRepository.Update(product);
            return(await _productRepository.UnitOfWork.Commit());
        }
Exemple #5
0
        protected void Notify(FluentValidation.Results.ValidationResult validationResult)
        {
            foreach (var error in validationResult.Errors)
            {
                var notifier = new DomainNotifier(error.ErrorMessage);

                _domainNotification.Handle(notifier);
                _mediatorHandler.PublishNotification(notifier);
            }
        }
        public async Task <Transaction> MakeOrderPayment(PaymentOrder paymentOrder)
        {
            var order = new Order
            {
                Id    = paymentOrder.OrderId,
                Value = paymentOrder.Total
            };

            var payment = new Payment
            {
                Value          = paymentOrder.Total,
                CardName       = paymentOrder.CardName,
                CardNumber     = paymentOrder.CardNumber,
                ExpirationCard = paymentOrder.ExpirationCard,
                CvvCard        = paymentOrder.CvvCard,
                OrderId        = paymentOrder.OrderId
            };

            var transaction = _paymentCreditCardFacade.MakePayment(order, payment);

            if (transaction.StatusTransaction == StatusTransaction.Paid)
            {
                payment.AddEvent(new PaymentMadeEvent(order.Id, paymentOrder.ClientId, transaction.PaymentId, transaction.Id, order.Value));

                _paymentRepository.Add(payment);
                _paymentRepository.AddTransaction(transaction);

                await _paymentRepository.UnitOfWork.Commit();

                return(transaction);
            }

            await _mediatorHandler.PublishNotification(new DomainNotification("payment", "Card operator refused the payment"));

            await _mediatorHandler.PublishEvent(new PaymentOrderRefusedEvent(order.Id, paymentOrder.ClientId, transaction.PaymentId, transaction.Id, order.Value));

            return(transaction);
        }
 protected void NotifyError(string code, string message)
 {
     _mediator.PublishNotification(new DomainNotification(code, message));
 }
 private async Task PublishTransactionDeclinedNotification()
 {
     await _mediatrHandler.PublishNotification(new DomainNotification("payment", "The credit card company declined the payment."));
 }
Exemple #9
0
 protected void PublishError(string code, string message)
 {
     _mediatrHandler.PublishNotification(new DomainNotification(code, message));
 }
        public async Task <bool> Handle(UpdateOrderItemCommand message, CancellationToken cancellationToken)
        {
            if (!ValidateCommand(message))
            {
                return(false);
            }

            var order = await _orderRepository.GetDraftOrderByClientId(message.ClientId);

            if (order == null)
            {
                await _mediatorHandler.PublishNotification(new DomainNotification("order", "Order not found !"));

                return(false);
            }

            var orderItem = await _orderRepository.GetItemByOrder(order.Id, message.ProductId);

            if (!order.OrderItemExist(orderItem))
            {
                await _mediatorHandler.PublishNotification(new DomainNotification("order", "Order item not found !"));

                return(false);
            }

            order.UpdateUnits(orderItem, message.Quantity);

            order.AddEvent(new OrderUpdatedEvent(order.ClientId, order.Id, order.TotalPrice));
            order.AddEvent(new OrderProductUpdatedEvent(message.ClientId, order.Id, message.ProductId, message.Quantity));

            _orderRepository.UpdateOrderItem(orderItem);
            _orderRepository.UpdateOrder(order);

            return(await _orderRepository.UnitOfWork.Commit());
        }