diff --git a/AspNetCoreLearnOfficial.sln b/AspNetCoreLearnOfficial.sln index c5b74ac..dcc1477 100644 --- a/AspNetCoreLearnOfficial.sln +++ b/AspNetCoreLearnOfficial.sln @@ -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 diff --git a/WebAPIWithEF/Controllers/WeatherForecastController.cs b/WebAPIWithEF/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..4b0e080 --- /dev/null +++ b/WebAPIWithEF/Controllers/WeatherForecastController.cs @@ -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 _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable 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(); + } + } +} diff --git a/WebAPIWithEF/Program.cs b/WebAPIWithEF/Program.cs new file mode 100644 index 0000000..ec3e32d --- /dev/null +++ b/WebAPIWithEF/Program.cs @@ -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(); + } + } +} diff --git a/WebAPIWithEF/Properties/launchSettings.json b/WebAPIWithEF/Properties/launchSettings.json new file mode 100644 index 0000000..16a74ad --- /dev/null +++ b/WebAPIWithEF/Properties/launchSettings.json @@ -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" + } + } + } +} diff --git a/WebAPIWithEF/WeatherForecast.cs b/WebAPIWithEF/WeatherForecast.cs new file mode 100644 index 0000000..b15b918 --- /dev/null +++ b/WebAPIWithEF/WeatherForecast.cs @@ -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; } + } +} diff --git a/WebAPIWithEF/WebAPIWithEF.csproj b/WebAPIWithEF/WebAPIWithEF.csproj new file mode 100644 index 0000000..c6ec4d4 --- /dev/null +++ b/WebAPIWithEF/WebAPIWithEF.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + enable + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + diff --git a/WebAPIWithEF/WebAPIWithEF.http b/WebAPIWithEF/WebAPIWithEF.http new file mode 100644 index 0000000..d1becfc --- /dev/null +++ b/WebAPIWithEF/WebAPIWithEF.http @@ -0,0 +1,6 @@ +@WebAPIWithEF_HostAddress = http://localhost:5057 + +GET {{WebAPIWithEF_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/WebAPIWithEF/appsettings.Development.json b/WebAPIWithEF/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/WebAPIWithEF/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/WebAPIWithEF/appsettings.json b/WebAPIWithEF/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/WebAPIWithEF/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}