mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 02:26:29 +01:00
74 lines
3 KiB
C#
74 lines
3 KiB
C#
using System.Globalization;
|
|
using TINK.MultilingualResources;
|
|
using TINK.Repository.Response;
|
|
|
|
namespace TINK.Model.Connector.Updater
|
|
{
|
|
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,
|
|
#if USCSHARP9
|
|
Number = int.TryParse(tariffDesciption?.number, out int number) ? number : null,
|
|
#else
|
|
Id = int.TryParse(tariffDesciption?.number, out int number) ? number : (int?)null,
|
|
#endif
|
|
};
|
|
|
|
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)
|
|
});
|
|
}
|
|
|
|
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)
|
|
});
|
|
}
|
|
|
|
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)
|
|
});
|
|
}
|
|
|
|
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)
|
|
});
|
|
}
|
|
|
|
return bike;
|
|
}
|
|
|
|
}
|
|
}
|