public IEnumerable <LabelGridItem> GetBagGridItems(int orderId) { var orderDetails = GetOrderDetailsWithoutOffalProducts(orderId); var locations = GetCustomerLocations(orderDetails); var products = GetProducts(orderDetails); var gridItems = new List <LabelGridItem>(); foreach (var product in products) { var gridItem = new LabelGridItem { ProductId = product.Id, ProductName = ProductService.GetFormattedProductName(product), Locations = new ObservableCollection <LabelGridItem.LocationTemplate>() }; for (var locationId = 0; locationId < locations.Length; locationId++) { var location = locations.ElementAtOrDefault(locationId); if (location == null) { continue; } var item = orderDetails.FirstOrDefault(it => it.CustomerLocationId == location.Id && it.ProductId == product.Id); if (item == null) { continue; } int bagQuantity = item.Product.BagPieceQuantity; var customerProducts = product.CustomerProductData.Where(x => x.CustomerId == item.Order.CustomerId); var customerProduct = customerProducts.FirstOrDefault(); if (customerProduct != null) { if (customerProduct.BoxQuantity.HasValue) { bagQuantity = customerProduct.BoxQuantity.Value; } } gridItem.Locations.Add(new LabelGridItem.LocationTemplate { Id = item.CustomerLocationId, OrderDetailId = item.Id, CompletedCount = item.Label.Count(label => label.TypeId == OmsLabelType.Bag), Total = item.PieceQuantity / // in case when db has incorrect data (bagQuantity == 0 ? 1 : bagQuantity), }); } gridItems.Add(gridItem); } return(gridItems); }
private void ChangeLocation(Visual container, LabelGridItem selectedProduct, int?location = null) { if (location.HasValue) { selectedProduct.SelectedLocation = location; } else if (++selectedProduct.SelectedLocation == selectedProduct.Locations.Count) { selectedProduct.SelectedLocation = 0; } ApplyUnitCaptionStyle(container, selectedProduct.SelectedLocation); }