web api with ef base

main
Peace 11 months ago
parent 91f89c795b
commit cc970b09f2
  1. 8
      AspNetCoreLearnOfficial.sln
  2. 33
      WebAPIWithEF/Controllers/WeatherForecastController.cs
  3. 36
      WebAPIWithEF/Program.cs
  4. 41
      WebAPIWithEF/Properties/launchSettings.json
  5. 13
      WebAPIWithEF/WeatherForecast.cs
  6. 18
      WebAPIWithEF/WebAPIWithEF.csproj
  7. 6
      WebAPIWithEF/WebAPIWithEF.http
  8. 8
      WebAPIWithEF/appsettings.Development.json
  9. 9
      WebAPIWithEF/appsettings.json

@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebApi", "WebApi\WebApi.csp
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzaStore", "MinimumWebAPI\PizzaStore.csproj", "{01E3A866-5135-403E-9059-42EAC85586BC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimumWebAPIWithEF", "MinimumWebAPIWithEF\MinimumWebAPIWithEF.csproj", "{C0C7BBD5-614F-4FE6-B007-412A09B675F8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimumWebAPIWithEF", "MinimumWebAPIWithEF\MinimumWebAPIWithEF.csproj", "{C0C7BBD5-614F-4FE6-B007-412A09B675F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebAPIWithEF", "WebAPIWithEF\WebAPIWithEF.csproj", "{42B252E7-C1BC-43B1-A326-AF8361E62C4C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -27,6 +29,10 @@ Global
{C0C7BBD5-614F-4FE6-B007-412A09B675F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0C7BBD5-614F-4FE6-B007-412A09B675F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0C7BBD5-614F-4FE6-B007-412A09B675F8}.Release|Any CPU.Build.0 = Release|Any CPU
{42B252E7-C1BC-43B1-A326-AF8361E62C4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{42B252E7-C1BC-43B1-A326-AF8361E62C4C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{42B252E7-C1BC-43B1-A326-AF8361E62C4C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{42B252E7-C1BC-43B1-A326-AF8361E62C4C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace WebAPIWithEF.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 = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
})
.ToArray();
}
}
}

@ -0,0 +1,36 @@
namespace WebAPIWithEF
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}

@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:45125",
"sslPort": 44333
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5057",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7158;http://localhost:5057",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

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

@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
</Project>

@ -0,0 +1,6 @@
@WebAPIWithEF_HostAddress = http://localhost:5057
GET {{WebAPIWithEF_HostAddress}}/weatherforecast/
Accept: application/json
###

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Loading…
Cancel
Save