public virtual IActionResult GetOrderItems(int orderId) { if (!_permissionService.Authorize(XrmsPermissionProvider.ManageWaiterOrders)) { return(AccessDeniedKendoGridJson()); } var orderItems = _currentOrderService.GetOrderItems(orderId); // prepare list view model var listViewModel = new DataSourceResult { Data = orderItems.Select(item => { var product = _productService.GetProductById(item.ProductId); // fill in model values from the entity var rowViewModel = 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 }; return(rowViewModel); }), Total = orderItems.Count }; return(Json(listViewModel)); }
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); }
public async Task Handle(ChangedOrderItemStateEvent message, CancellationToken token) { var order = _currentOrderService.GetOrderByGuid(message.Id); order.Version = message.Version; order.UpdatedOnUtc = message.TimeStamp.UtcDateTime; _currentOrderService.UpdateOrder(order); var item = _currentOrderService.GetOrderItemByGuid(message.OrderItemGuid); item.StateId = message.State; item.UpdatedOnUtc = message.TimeStamp.UtcDateTime; _currentOrderService.UpdateOrderItem(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); //return Task.CompletedTask; }
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); }