namespace LaaProduction.Services.Models { using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; public class OrderScanModel : OrderModel { public String Host { get; set; } public String Place { get; set; } public Int32 PalletsCount { get; set; } [Display(Name = "Paletten-Nr.")] public Int32? PalletNr { get; set; } public IEnumerable Positions { get; set; } = Array.Empty(); public IDictionary Pallets { get; set; } = new Dictionary { { 1, false } }; public String PrintUrl => $"~/Shipments/Print?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={this.PalletNr}"; public String PalletUrl(Int32? palletNr) => $"~/Shipments/Pallet?ordernr={this.OrderNr}&positionnr={this.PositionNr}&palletnr={palletNr}"; internal void UpdatePallets(IEnumerable> pallets) { this.Pallets = pallets.ToDictionary(x => x.Key, x => x.Value); if (this.PalletNr is null || this.PalletNr == 0) { if (pallets.Any(x => x.Value)) { this.PalletNr = Math.Max(pallets .Where(x => x.Value) .OrderByDescending(x => x.Key) .FirstOrDefault().Key, 1); } else { this.PalletNr = Math.Max(pallets .OrderByDescending(x => x.Key) .FirstOrDefault().Key, 1); } } } } }