Weather.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. namespace MyWeather.Models
  5. {
  6. public class Coord
  7. {
  8. [JsonProperty("lon")]
  9. public double Longitude { get; set; } = 0;
  10. [JsonProperty("lat")]
  11. public double Latitude { get; set; } = 0;
  12. }
  13. public class Sys
  14. {
  15. [JsonProperty("country")]
  16. public string Country { get; set; } = string.Empty;
  17. }
  18. public class Weather
  19. {
  20. [JsonProperty("id")]
  21. public int Id { get; set; } = 0;
  22. [JsonProperty("main")]
  23. public string Main { get; set; } = string.Empty;
  24. [JsonProperty("description")]
  25. public string Description { get; set; } = string.Empty;
  26. [JsonProperty("icon")]
  27. public string Icon { get; set; } = string.Empty;
  28. }
  29. public class Main
  30. {
  31. [JsonProperty("temp")]
  32. public double Temperature { get; set; } = 0;
  33. [JsonProperty("pressure")]
  34. public double Pressure { get; set; } = 0;
  35. [JsonProperty("humidity")]
  36. public double Humidity { get; set; } = 0;
  37. [JsonProperty("temp_min")]
  38. public double MinTemperature { get; set; } = 0;
  39. [JsonProperty("temp_max")]
  40. public double MaxTemperature { get; set; } = 0;
  41. }
  42. public class Wind
  43. {
  44. [JsonProperty("speed")]
  45. public double Speed { get; set; } = 0;
  46. [JsonProperty("deg")]
  47. public double WindDirectionDegrees { get; set; } = 0;
  48. }
  49. public class Clouds
  50. {
  51. [JsonProperty("all")]
  52. public int CloudinessPercent { get; set; } = 0;
  53. }
  54. public class WeatherRoot
  55. {
  56. [JsonProperty("coord")]
  57. public Coord Coordinates { get; set; } = new Coord();
  58. [JsonProperty("sys")]
  59. public Sys System { get; set; } = new Sys();
  60. [JsonProperty("weather")]
  61. public List<Weather> Weather { get; set; } = new List<Weather>();
  62. [JsonProperty("main")]
  63. public Main MainWeather { get; set; } = new Main();
  64. [JsonProperty("wind")]
  65. public Wind Wind { get; set; } = new Wind();
  66. [JsonProperty("clouds")]
  67. public Clouds Clouds { get; set; } = new Clouds();
  68. [JsonProperty("id")]
  69. public int CityId { get; set; } = 0;
  70. [JsonProperty("name")]
  71. public string Name { get; set; } = string.Empty;
  72. [JsonProperty("dt_txt")]
  73. public string Date { get; set; } = string.Empty;
  74. [JsonIgnore]
  75. public string DisplayDate => DateTime.Parse(Date).ToLocalTime().ToString("g");
  76. [JsonIgnore]
  77. public string DisplayTemp => $"Temp: {MainWeather?.Temperature ?? 0}° {Weather?[0]?.Main ?? string.Empty}";
  78. [JsonIgnore]
  79. public string DisplayIcon => $"http://openweathermap.org/img/w/{Weather?[0]?.Icon}.png";
  80. }
  81. public class WeatherForecastRoot
  82. {
  83. [JsonProperty("city")]
  84. public City City { get; set; }
  85. [JsonProperty("cod")]
  86. public string Vod { get; set; }
  87. [JsonProperty("message")]
  88. public double Message { get; set; }
  89. [JsonProperty("cnt")]
  90. public int Cnt { get; set; }
  91. [JsonProperty("list")]
  92. public List<WeatherRoot> Items { get; set; }
  93. }
  94. public class City
  95. {
  96. [JsonProperty("id")]
  97. public int Id { get; set; }
  98. [JsonProperty("name")]
  99. public string Name { get; set; }
  100. [JsonProperty("coord")]
  101. public Coord Coord { get; set; }
  102. [JsonProperty("country")]
  103. public string Country { get; set; }
  104. [JsonProperty("population")]
  105. public int Population { get; set; }
  106. [JsonProperty("sys")]
  107. public Sys Sys { get; set; }
  108. }
  109. }