main
syneffort 2 years ago
parent 3c97c27c94
commit af599328e6
  1. 50
      BlazorApp/WebAPI/Controllers/RankingController.cs
  2. 33
      BlazorApp/WebAPI/Controllers/WeatherForecastController.cs
  3. 13
      BlazorApp/WebAPI/WeatherForecast.cs
  4. 6
      BlazorApp/WebAPI/WebAPI.csproj

@ -0,0 +1,50 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SharedData.Models;
using WebAPI.Data;
namespace WebAPI.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class RankingController : ControllerBase
{
private ApplicationDbContext _context;
public RankingController(ApplicationDbContext context)
{
_context = context;
}
// Create
// POST
// Read
// GET
[HttpGet]
public List<GameResult> GetGameResults()
{
List<GameResult> results = _context.GameResults
.OrderByDescending(x => x.Score)
.ToList();
return results;
}
[HttpGet("{id}")]
public GameResult GetGameResults(int id)
{
GameResult result = _context.GameResults
.Where(x => x.Id == id)
.FirstOrDefault();
return result;
}
// Update
// PUT
// Delete
// DELETE
}
}

@ -1,33 +0,0 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPI.Controllers
{
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()
{
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -1,13 +0,0 @@
namespace WebAPI
{
public class WeatherForecast
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string? Summary { get; set; }
}
}

@ -12,7 +12,13 @@
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.21" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup> </ItemGroup>

Loading…
Cancel
Save