Skip to content

Commit 8f655e9

Browse files
seralaciMarkPieszak
authored andcommitted
refactor(code): misc code cleanup
- Removed redundant codes - Expression-bodied property - Fixed naming convention issue
1 parent 61dbd59 commit 8f655e9

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

content/Controllers/WeatherController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public IActionResult Forecasts([FromQuery(Name = "from")] int from = 0, [FromQue
2525
{
2626
return BadRequest("You cannot have the 'to' parameter higher than 'from' parameter.");
2727
}
28-
else if (from < 0)
28+
29+
if (from < 0)
2930
{
3031
return BadRequest("You cannot go in the negative with the 'from' parameter");
3132
}

content/Models/WeatherForecast.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@ namespace Vue2Spa.Models
22
{
33
public class WeatherForecast
44
{
5-
public string DateFormatted { get; set; }
6-
public int TemperatureC { get; set; }
5+
public string DateFormatted { get; set; }
6+
77
public string Summary { get; set; }
88

9-
public int TemperatureF
10-
{
11-
get
12-
{
13-
return 32 + (int)(TemperatureC / 0.5556);
14-
}
15-
}
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
1612
}
1713
}

content/Providers/WeatherProviderFake.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace Vue2Spa.Providers
77
{
88
public class WeatherProviderFake : IWeatherProvider
99
{
10-
private string[] Summaries = new[]
11-
{
10+
private readonly string[] summaries = {
1211
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
1312
};
1413

@@ -26,7 +25,7 @@ private void Initialize(int quantity)
2625
{
2726
DateFormatted = DateTime.Now.AddDays(index).ToString("d"),
2827
TemperatureC = rng.Next(-20, 55),
29-
Summary = Summaries[rng.Next(Summaries.Length)]
28+
Summary = summaries[rng.Next(summaries.Length)]
3029
}).ToList();
3130
}
3231

0 commit comments

Comments
 (0)