示例#1
0
        private void Apply(AddedOrderItemEvent e)
        {
            var logger = EngineContext.Current.Resolve <ILogger>();

            logger.InsertLog(LogLevel.Information, "Apply AddedOrderItemEvent",
                             String.Format("OrderItemGuid = {0}, ProductId = {1}, Quantity = {2}", e.OrderItemGuid, e.ProductId, e.Quantity));
            _orderItems.Add(new OrderItem()
            {
                OrderItemGuid = e.OrderItemGuid,
                ProductId     = e.ProductId,
                Quantity      = e.Quantity,
                State         = 0
            });
        }
        public async Task Handle(AddedOrderItemEvent message, CancellationToken token)
        {
            // get current order
            var order = _currentOrderService.GetOrderByGuid(message.Id);

            // get customer from current order
            var currentStore = _storeContext.CurrentStore;
            var customer     = _customerService.GetCustomerById(order.CustomerId);
            // add shopping cart first, then add current order item
            var shoppingCartItem = _shoppingCartService.AddShoppingCartItem(_customerService, customer, message.ProductId, ShoppingCartType.ShoppingCart, currentStore.Id, message.Quantity);

            /*if (shoppingCartItem != null)
             * {
             *  order.CurrentOrderItems.Add(new CurrentOrderItemEntity()
             *  {
             *      ShoppingCartItemId = shoppingCartItem.Id,
             *      AggregateId = message.OrderItemGuid,
             *      CurrentOrderId = order.Id,
             *      ProductId = message.ProductId,
             *      Quantity = message.Quantity,
             *      CreatedOnUtc = message.TimeStamp.UtcDateTime,
             *      UpdatedOnUtc = message.TimeStamp.UtcDateTime
             *  });
             * }*/
            // update current order information
            order.Version      = message.Version;
            order.UpdatedOnUtc = message.TimeStamp.UtcDateTime;
            _currentOrderService.UpdateOrder(order);
            var item = new CurrentOrderItemEntity()
            {
                ShoppingCartItemId = (shoppingCartItem != null) ? shoppingCartItem.Id : 0,
                AggregateId        = message.OrderItemGuid,
                CurrentOrderId     = order.Id,
                ProductId          = message.ProductId,
                Quantity           = message.Quantity,
                CreatedOnUtc       = message.TimeStamp.UtcDateTime,
                UpdatedOnUtc       = message.TimeStamp.UtcDateTime
            };

            _currentOrderService.InsertOrderItem(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,
                Version     = item.Version,
                AggregateId = item.AggregateId,
                ProductId   = item.ProductId,
                Quantity    = item.Quantity,
                OldQuantity = item.Quantity,

                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.NotifyAddedOrderItemEvent(notifyModel);
        }