예제 #1
0
        private void Apply(ChangedOrderItemQuantityEvent e)
        {
            var logger = EngineContext.Current.Resolve <ILogger>();

            logger.InsertLog(LogLevel.Information, "Apply ChangedOrderItemQuantity",
                             String.Format("OrderItemGuid = {0}, ProductId = {1}, Quantity = {2}", e.OrderItemGuid, e.ProductId, e.Quantity));
            var item = _orderItems.Find(i => i.OrderItemGuid == e.OrderItemGuid);

            if (item != null)
            {
                item.Quantity = e.Quantity;
            }
            else
            {
                throw new Exception(String.Format("No have order item '{0}' in order.", e.OrderItemGuid));
            }
        }
예제 #2
0
        public async Task Handle(ChangedOrderItemQuantityEvent message, CancellationToken token)
        {
            // get current order
            var order = _currentOrderService.GetOrderByGuid(message.Id);

            order.Version      = message.Version;
            order.UpdatedOnUtc = message.TimeStamp.UtcDateTime;
            _currentOrderService.UpdateOrder(order);
            var item = _currentOrderService.GetOrderItemByGuid(message.OrderItemGuid);

            // get customer form current order
            var customer = _customerService.GetCustomerById(order.CustomerId);

            _shoppingCartService.UpdateShoppingCartItem(_customerService, customer, item.ShoppingCartItemId, quantity: message.Quantity);
            if (message.Quantity > 0)
            {
                item.Quantity     = message.Quantity;
                item.UpdatedOnUtc = message.TimeStamp.UtcDateTime;
                _currentOrderService.UpdateOrderItem(item);
            }
            else
            {
                _currentOrderService.DeleteOrderItem(item);
            }

            // fill in model values from the entity
            var notifyModel    = order.ToNotifyChangedOrderItemModel();
            var product        = _productService.GetProductById(item.ProductId);
            var orderItemModel = new InStoreOrderItemListRowViewModel()
            {
                Id          = item.Id,
                AggregateId = item.AggregateId,
                ProductId   = item.ProductId,
                Quantity    = item.Quantity,
                OldQuantity = item.Quantity,
                Version     = item.Version,

                ProductName  = product.Name,
                ProductPrice = product.Price
            };

            notifyModel.UpdatedOnUtc     = _dateTimeHelper.ConvertToUserTime(order.UpdatedOnUtc, DateTimeKind.Utc).ToString("dd/MM HH:mm:ss");
            notifyModel.ChangedOrderItem = orderItemModel;

            await this._clientNotificationService.NotifyChangedOrderItemQuantityEvent(notifyModel);
        }