make things a little prettier
This commit is contained in:
parent
3690b4d639
commit
4fc2524e14
@ -18,6 +18,5 @@ namespace WeatherDashboard.Web.Controllers
|
||||
|
||||
return View(weather);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -3,10 +3,12 @@
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div>
|
||||
@Model.Location.Region, @Model.Location.Name
|
||||
<div class="location">
|
||||
<div>@Model.Location.Region, @Model.Location.Name</div>
|
||||
<small>Last updated on @Model.Current.LastUpdated</small>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
@Model.Current.LastUpdated @Model.Current.Temperature
|
||||
<div class="current-conditions">
|
||||
<div class="current-temperature">@Model.Current.Temperature<span class="degrees">°F</span></div>
|
||||
<div class="current-condition-name">@Model.Current.ConditionName</div>
|
||||
</div>
|
||||
|
@ -1,12 +1,12 @@
|
||||
html {
|
||||
font-size: 14px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
/*@media (min-width: 768px) {
|
||||
html {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
|
||||
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
|
||||
@ -19,5 +19,23 @@ html {
|
||||
|
||||
body {
|
||||
font-family: 'Montserrat', sans-serif;
|
||||
color: #777;
|
||||
color: #444;
|
||||
margin:40px;
|
||||
background-color: floralwhite;
|
||||
}
|
||||
|
||||
.location small {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.degrees {
|
||||
font-size: 50px;
|
||||
position: absolute;
|
||||
margin: 20px 0 0 10px;
|
||||
opacity: .6;
|
||||
}
|
||||
|
||||
.current-temperature {
|
||||
font-size: 100px;
|
||||
font-weight: 500;
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace WeatherDashboard
|
||||
{
|
||||
[JsonConverter(typeof(JsonPathConverter))]
|
||||
public class CurrentForecast
|
||||
{
|
||||
[JsonProperty("last_updated")]
|
||||
@ -9,5 +10,8 @@ namespace WeatherDashboard
|
||||
|
||||
[JsonProperty("temp_f")]
|
||||
public decimal Temperature { get; set; }
|
||||
|
||||
[JsonProperty("condition.text")]
|
||||
public string ConditionName { get; set; }
|
||||
}
|
||||
}
|
40
WeatherDashboard/JsonPathConverter.cs
Normal file
40
WeatherDashboard/JsonPathConverter.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace WeatherDashboard
|
||||
{
|
||||
public class JsonPathConverter : JsonConverter
|
||||
{
|
||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var jsonObject = JObject.Load(reader);
|
||||
var target = Activator.CreateInstance(objectType);
|
||||
|
||||
foreach (PropertyInfo prop in objectType.GetProperties().Where(p => p.CanRead && p.CanWrite))
|
||||
{
|
||||
var attribute = prop
|
||||
.GetCustomAttributes(true)
|
||||
.OfType<JsonPropertyAttribute>()
|
||||
.FirstOrDefault();
|
||||
|
||||
var jsonPath = (attribute != null ? attribute.PropertyName : prop.Name);
|
||||
var token = jsonObject.SelectToken(jsonPath);
|
||||
|
||||
if (token != null && token.Type != JTokenType.Null)
|
||||
{
|
||||
object value = token.ToObject(prop.PropertyType, serializer);
|
||||
prop.SetValue(target, value, null);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
// CanConvert is not called when [JsonConverter] attribute is used
|
||||
public override bool CanConvert(Type objectType) => false;
|
||||
|
||||
public override bool CanWrite => false;
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) => throw new NotImplementedException();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user