sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/TariffDescriptionViewModel.cs

80 lines
3.8 KiB
C#
Raw Normal View History

2022-10-03 17:55:10 +02:00
using System.Collections.ObjectModel;
2022-06-17 14:17:58 +02:00
using System.Linq;
2022-08-30 15:42:25 +02:00
using TINK.Model.Bikes.BikeInfoNS;
2021-05-13 20:03:07 +02:00
namespace TINK.ViewModel.Bikes.Bike
{
2022-09-06 16:08:19 +02:00
/// <summary>
/// View model for displaying tariff info.
/// </summary>
public class TariffDescriptionViewModel
{
2023-02-22 14:03:35 +01:00
private const string TRACKINGKEY = "TRACKING";
2023-04-19 12:14:14 +02:00
private const string RIDETYPEKEY = "AAFAHRTEN";
2022-09-06 16:08:19 +02:00
public TariffDescriptionViewModel(RentalDescription tariff)
{
Name = tariff?.Name ?? string.Empty;
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
TariffEntries = tariff != null && tariff?.TariffEntries != null
? new ObservableCollection<RentalDescription.TariffElement>(tariff.TariffEntries.OrderBy(x => x.Key).Select(x => x.Value))
: new ObservableCollection<RentalDescription.TariffElement>();
2021-05-13 20:03:07 +02:00
2023-04-19 12:14:14 +02:00
// Add all entires except the known entries which are kept as properties.
2022-09-06 16:08:19 +02:00
InfoEntries = tariff != null && tariff?.InfoEntries != null
2023-02-22 14:03:35 +01:00
? new ObservableCollection<string>(tariff.InfoEntries
2023-04-19 12:14:14 +02:00
.Where(x => x.Value.Key.ToUpper() != TRACKINGKEY
&& x.Value.Key.ToUpper() != RIDETYPEKEY)
2023-02-22 14:03:35 +01:00
.OrderBy(x => x.Key)
.Select(x => x.Value.Value))
2022-09-06 16:08:19 +02:00
: new ObservableCollection<string>();
2023-02-22 14:03:35 +01:00
2023-04-19 12:14:14 +02:00
RideTypeText = tariff?.InfoEntries != null ? tariff?.InfoEntries?.FirstOrDefault(x => x.Value.Key.ToUpper() == RIDETYPEKEY).Value?.Value ?? string.Empty : string.Empty;
2023-02-22 14:03:35 +01:00
TrackingInfoText = tariff?.InfoEntries != null ? tariff?.InfoEntries?.FirstOrDefault(x => x.Value.Key.ToUpper() == TRACKINGKEY).Value?.Value ?? string.Empty : string.Empty;
2022-09-06 16:08:19 +02:00
}
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the name of the tariff.
/// </summary>
public string Name { get; set; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the tariff entries to display.
/// </summary>
public ObservableCollection<RentalDescription.TariffElement> TariffEntries { get; private set; }
2021-05-13 20:03:07 +02:00
2022-09-06 16:08:19 +02:00
/// <summary>
/// Holds the info entries to display.
/// </summary>
public ObservableCollection<string> InfoEntries { get; private set; }
2021-11-07 21:28:13 +01:00
2023-04-19 12:14:14 +02:00
/// <summary>
/// Holds the tracking info text or empty if not applicable.
/// </summary>
public string RideTypeText { get; private set; }
2023-02-22 14:03:35 +01:00
/// <summary>
/// Holds the tracking info text or empty if not applicable.
/// </summary>
public string TrackingInfoText { get; private set; }
2022-09-06 16:08:19 +02:00
public RentalDescription.TariffElement TarifEntry1 => TariffEntries.Count > 0 ? TariffEntries[0] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry2 => TariffEntries.Count > 1 ? TariffEntries[1] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry3 => TariffEntries.Count > 2 ? TariffEntries[2] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry4 => TariffEntries.Count > 3 ? TariffEntries[3] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry5 => TariffEntries.Count > 4 ? TariffEntries[4] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry6 => TariffEntries.Count > 5 ? TariffEntries[5] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry7 => TariffEntries.Count > 6 ? TariffEntries[6] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry8 => TariffEntries.Count > 7 ? TariffEntries[7] : new RentalDescription.TariffElement();
public RentalDescription.TariffElement TarifEntry9 => TariffEntries.Count > 8 ? TariffEntries[8] : new RentalDescription.TariffElement();
2022-06-17 14:17:58 +02:00
2022-09-06 16:08:19 +02:00
public string InfoEntry1 => InfoEntries.Count > 0 ? InfoEntries[0] : string.Empty;
public string InfoEntry2 => InfoEntries.Count > 1 ? InfoEntries[1] : string.Empty;
public string InfoEntry3 => InfoEntries.Count > 2 ? InfoEntries[2] : string.Empty;
public string InfoEntry4 => InfoEntries.Count > 3 ? InfoEntries[3] : string.Empty;
public string InfoEntry5 => InfoEntries.Count > 4 ? InfoEntries[4] : string.Empty;
}
2021-05-13 20:03:07 +02:00
}