laatzen/LaaProductionWeb/LaaProduction.Services/Models/OrderScanModel.cs
2024-07-17 13:13:41 +02:00

53 lines
1.7 KiB
C#

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<Int32> Positions { get; set; }
= Array.Empty<Int32>();
public IDictionary<Int32, Boolean> Pallets { get; set; }
= new Dictionary<Int32, Boolean> { { 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<KeyValuePair<Int32, Boolean>> 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);
}
}
}
}
}