sharee.bike-App/TINKLib/ViewModel/Bikes/Bike/TariffDescriptionViewModel.cs
Anja Müller-Meißner 0468955d49 Version 3.0.338
2022-09-08 09:55:14 +02:00

67 lines
3.3 KiB
C#

using System.Collections.ObjectModel;
using System.Linq;
using TINK.Model.Bikes.BikeInfoNS;
namespace TINK.ViewModel.Bikes.Bike
{
/// <summary>
/// View model for displaying tariff info.
/// </summary>
public class TariffDescriptionViewModel
{
private const string AGBKEY = "AGB";
public TariffDescriptionViewModel(RentalDescription tariff)
{
Name = tariff?.Name ?? string.Empty;
TariffEntries = tariff != null && tariff?.TariffEntries != null
? new ObservableCollection<RentalDescription.TariffElement>(tariff.TariffEntries.OrderBy(x => x.Key).Select(x => x.Value))
: new ObservableCollection<RentalDescription.TariffElement>();
InfoEntries = tariff != null && tariff?.InfoEntries != null
? new ObservableCollection<string>(tariff.InfoEntries.OrderBy(x => x.Key).Where(x => x.Value.Key != AGBKEY).Select(x => x.Value.Value))
: new ObservableCollection<string>();
OperatorAgb = tariff?.InfoEntries != null
&& tariff.InfoEntries.Select(x => x.Value.Key).Contains(AGBKEY)
? tariff?.InfoEntries.FirstOrDefault(x => x.Value.Key == AGBKEY).Value.Value
: string.Empty;
}
/// <summary>
/// Holds the name of the tariff.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Holds the tariff entries to display.
/// </summary>
public ObservableCollection<RentalDescription.TariffElement> TariffEntries { get; private set; }
/// <summary>
/// Holds the info entries to display.
/// </summary>
public ObservableCollection<string> InfoEntries { get; private set; }
/// <summary> Info about operator agb as HTML (i.g. text and hyperlink). </summary>
public string OperatorAgb { get; set; }
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();
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;
}
}