2022-08-30 15:42:25 +02:00
|
|
|
|
using System.Globalization;
|
|
|
|
|
using TINK.MultilingualResources;
|
|
|
|
|
using TINK.Repository.Response;
|
|
|
|
|
|
|
|
|
|
namespace TINK.Model.Connector.Updater
|
|
|
|
|
{
|
2022-09-06 16:08:19 +02:00
|
|
|
|
public static class TariffDescriptionFactory
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates rental description object from JSON- tarif description object.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="tariffDesciption">Source JSON object.</param>
|
|
|
|
|
/// <returns>Tariff description object.</returns>
|
|
|
|
|
public static Bikes.BikeInfoNS.RentalDescription Create(this TariffDescription tariffDesciption)
|
|
|
|
|
{
|
|
|
|
|
var bike = new Bikes.BikeInfoNS.RentalDescription
|
|
|
|
|
{
|
|
|
|
|
Name = tariffDesciption?.name,
|
2022-08-30 15:42:25 +02:00
|
|
|
|
#if USCSHARP9
|
|
|
|
|
Number = int.TryParse(tariffDesciption?.number, out int number) ? number : null,
|
|
|
|
|
#else
|
2022-09-06 16:08:19 +02:00
|
|
|
|
Id = int.TryParse(tariffDesciption?.number, out int number) ? number : (int?)null,
|
2022-08-30 15:42:25 +02:00
|
|
|
|
#endif
|
2022-09-06 16:08:19 +02:00
|
|
|
|
};
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(tariffDesciption?.free_hours)
|
|
|
|
|
&& double.TryParse(tariffDesciption?.free_hours, NumberStyles.Any, CultureInfo.InvariantCulture, out double freeHours))
|
|
|
|
|
{
|
|
|
|
|
// Free time. Unit hours,format floating point number.
|
|
|
|
|
bike.TariffEntries.Add("1", new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
|
|
|
|
{
|
|
|
|
|
Description = AppResources.MessageBikesManagementTariffDescriptionFreeTimePerSession,
|
|
|
|
|
Value = string.Format("{0} {1}", freeHours.ToString("0.00"), AppResources.MessageBikesManagementTariffDescriptionHour)
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(tariffDesciption?.eur_per_hour)
|
|
|
|
|
&& double.TryParse(tariffDesciption?.eur_per_hour, NumberStyles.Any, CultureInfo.InvariantCulture, out double euroPerHour))
|
|
|
|
|
{
|
|
|
|
|
// Euro per hour. Format floating point.
|
|
|
|
|
bike.TariffEntries.Add("2", new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
|
|
|
|
{
|
|
|
|
|
Description = AppResources.MessageBikesManagementTariffDescriptionFeeEuroPerHour,
|
|
|
|
|
Value = string.Format("{0} {1}", euroPerHour.ToString("0.00"), AppResources.MessageBikesManagementTariffDescriptionEuroPerHour)
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(tariffDesciption?.max_eur_per_day)
|
|
|
|
|
&& double.TryParse(tariffDesciption.max_eur_per_day, NumberStyles.Any, CultureInfo.InvariantCulture, out double maxEuroPerDay))
|
|
|
|
|
{
|
|
|
|
|
// Max euro per day. Format floating point.
|
|
|
|
|
bike.TariffEntries.Add("3", new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
|
|
|
|
{
|
|
|
|
|
Description = AppResources.MessageBikesManagementTariffDescriptionMaxFeeEuroPerDay,
|
|
|
|
|
Value = string.Format("{0} {1}", maxEuroPerDay.ToString("0.00"), AppResources.MessageBikesManagementMaxFeeEuroPerDay)
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(tariffDesciption?.abo_eur_per_month)
|
|
|
|
|
&& double.TryParse(tariffDesciption.abo_eur_per_month, NumberStyles.Any, CultureInfo.InvariantCulture, out double aboEuroPerMonth))
|
|
|
|
|
{
|
|
|
|
|
// Abo per month
|
|
|
|
|
bike.TariffEntries.Add("4", new Bikes.BikeInfoNS.RentalDescription.TariffElement
|
|
|
|
|
{
|
|
|
|
|
Description = AppResources.MessageBikesManagementTariffDescriptionAboEuroPerMonth,
|
|
|
|
|
Value = string.Format("{0} {1}", aboEuroPerMonth.ToString("0.00"), AppResources.MessageBikesManagementTariffDescriptionEuroPerMonth)
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(tariffDesciption?.operator_agb ?? string.Empty))
|
|
|
|
|
{
|
|
|
|
|
bike.InfoEntries.Add("1", new Bikes.BikeInfoNS.RentalDescription.InfoElement { Key = "AGB", Value = tariffDesciption.operator_agb });
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
return bike;
|
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
|
2022-09-06 16:08:19 +02:00
|
|
|
|
}
|
2022-08-30 15:42:25 +02:00
|
|
|
|
}
|