38 lines
983 B
C#
38 lines
983 B
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
|
|
namespace Expose.MyIT.Shared.ViewModels;
|
|
|
|
public record WeatherForecast
|
|
{
|
|
|
|
public DateOnly Date { init; get; }
|
|
|
|
public int TemperatureC { init; get; }
|
|
|
|
public string? Summary { init; get; }
|
|
|
|
public int TemperatureF { init; get; }
|
|
|
|
[JsonConstructor]
|
|
public WeatherForecast(DateOnly date, int temperatureC, string? summary, int temperatureF)
|
|
{
|
|
Date = date;
|
|
TemperatureC = temperatureC;
|
|
Summary = summary;
|
|
TemperatureF = temperatureF;
|
|
}
|
|
|
|
public WeatherForecast(Models.WeatherForecast weatherForecast) :
|
|
this(weatherForecast.Date,
|
|
weatherForecast.TemperatureC,
|
|
weatherForecast.Summary,
|
|
weatherForecast.TemperatureF)
|
|
{ }
|
|
|
|
public override string ToString()
|
|
{
|
|
string result = JsonSerializer.Serialize(this, new JsonSerializerOptions() { WriteIndented = true });
|
|
return result;
|
|
}
|
|
} |