first commit
This commit is contained in:
16
Models/API/MethodParameter.cs
Normal file
16
Models/API/MethodParameter.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MotoVaultPro.Models
|
||||
{
|
||||
public class MethodParameter
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[JsonConverter(typeof(FromDateOptional))]
|
||||
public string StartDate { get; set; }
|
||||
[JsonConverter(typeof(FromDateOptional))]
|
||||
public string EndDate { get; set; }
|
||||
public string Tags { get; set; }
|
||||
public bool UseMPG { get; set; }
|
||||
public bool UseUKMPG { get; set; }
|
||||
}
|
||||
}
|
||||
18
Models/API/ReleaseVersion.cs
Normal file
18
Models/API/ReleaseVersion.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace MotoVaultPro.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// For deserializing GitHub response for latest version
|
||||
/// </summary>
|
||||
public class ReleaseResponse
|
||||
{
|
||||
public string tag_name { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// For returning the version numbers via API.
|
||||
/// </summary>
|
||||
public class ReleaseVersion
|
||||
{
|
||||
public string CurrentVersion { get; set; }
|
||||
public string LatestVersion { get; set; }
|
||||
}
|
||||
}
|
||||
138
Models/API/TypeConverter.cs
Normal file
138
Models/API/TypeConverter.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace MotoVaultPro.Models
|
||||
{
|
||||
public class DummyType
|
||||
{
|
||||
|
||||
}
|
||||
class InvariantConverter : JsonConverter<DummyType>
|
||||
{
|
||||
public override void Write(Utf8JsonWriter writer, DummyType value, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override DummyType? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
class FromDateOptional: JsonConverter<string>
|
||||
{
|
||||
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var tokenType = reader.TokenType;
|
||||
if (tokenType == JsonTokenType.String)
|
||||
{
|
||||
return reader.GetString();
|
||||
}
|
||||
else if (tokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (reader.TryGetInt64(out long intInput))
|
||||
{
|
||||
return DateTimeOffset.FromUnixTimeSeconds(intInput).Date.ToShortDateString();
|
||||
}
|
||||
}
|
||||
return reader.GetString();
|
||||
}
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
if (options.Converters.Any(x => x.Type == typeof(DummyType)))
|
||||
{
|
||||
writer.WriteStringValue(DateTime.Parse(value).ToString("yyyy-MM-dd"));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
class FromDecimalOptional : JsonConverter<string>
|
||||
{
|
||||
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var tokenType = reader.TokenType;
|
||||
if (tokenType == JsonTokenType.String)
|
||||
{
|
||||
return reader.GetString();
|
||||
}
|
||||
else if (tokenType == JsonTokenType.Number) {
|
||||
if (reader.TryGetDecimal(out decimal decimalInput))
|
||||
{
|
||||
return decimalInput.ToString();
|
||||
}
|
||||
}
|
||||
return reader.GetString();
|
||||
}
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
if (options.Converters.Any(x=>x.Type == typeof(DummyType)))
|
||||
{
|
||||
writer.WriteNumberValue(decimal.Parse(value));
|
||||
} else
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
class FromIntOptional : JsonConverter<string>
|
||||
{
|
||||
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var tokenType = reader.TokenType;
|
||||
if (tokenType == JsonTokenType.String)
|
||||
{
|
||||
return reader.GetString();
|
||||
}
|
||||
else if (tokenType == JsonTokenType.Number)
|
||||
{
|
||||
if (reader.TryGetInt32(out int intInput))
|
||||
{
|
||||
return intInput.ToString();
|
||||
}
|
||||
}
|
||||
return reader.GetString();
|
||||
}
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
if (options.Converters.Any(x => x.Type == typeof(DummyType)))
|
||||
{
|
||||
writer.WriteNumberValue(int.Parse(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
class FromBoolOptional : JsonConverter<string>
|
||||
{
|
||||
public override string? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
|
||||
{
|
||||
var tokenType = reader.TokenType;
|
||||
switch (tokenType)
|
||||
{
|
||||
case JsonTokenType.String:
|
||||
return reader.GetString();
|
||||
case JsonTokenType.True:
|
||||
return "True";
|
||||
case JsonTokenType.False:
|
||||
return "False";
|
||||
default:
|
||||
return reader.GetString();
|
||||
}
|
||||
}
|
||||
public override void Write(Utf8JsonWriter writer, string value, JsonSerializerOptions options)
|
||||
{
|
||||
if (options.Converters.Any(x => x.Type == typeof(DummyType)))
|
||||
{
|
||||
writer.WriteBooleanValue(bool.Parse(value));
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WriteStringValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Models/API/VehicleInfo.cs
Normal file
27
Models/API/VehicleInfo.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
namespace MotoVaultPro.Models
|
||||
{
|
||||
public class VehicleInfo
|
||||
{
|
||||
public Vehicle VehicleData { get; set; } = new Vehicle();
|
||||
public int VeryUrgentReminderCount { get; set; }
|
||||
public int UrgentReminderCount { get; set;}
|
||||
public int NotUrgentReminderCount { get; set; }
|
||||
public int PastDueReminderCount { get; set; }
|
||||
public ReminderAPIExportModel NextReminder { get; set; }
|
||||
public int ServiceRecordCount { get; set; }
|
||||
public decimal ServiceRecordCost { get; set; }
|
||||
public int RepairRecordCount { get; set; }
|
||||
public decimal RepairRecordCost { get; set; }
|
||||
public int UpgradeRecordCount { get; set; }
|
||||
public decimal UpgradeRecordCost { get; set; }
|
||||
public int TaxRecordCount { get; set; }
|
||||
public decimal TaxRecordCost { get; set; }
|
||||
public int GasRecordCount { get; set; }
|
||||
public decimal GasRecordCost { get; set; }
|
||||
public int LastReportedOdometer { get; set; }
|
||||
public int PlanRecordBackLogCount { get; set; }
|
||||
public int PlanRecordInProgressCount { get; set; }
|
||||
public int PlanRecordTestingCount { get; set; }
|
||||
public int PlanRecordDoneCount { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user