Skip to content

Commit f411dd6

Browse files
Add project files.
1 parent c9afc09 commit f411dd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+40434
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
6+
namespace FrontEndBackEndDemo.Api.Controllers
7+
{
8+
[ApiController]
9+
[Route("[controller]")]
10+
public class WeatherForecastController : ControllerBase
11+
{
12+
private static readonly string[] _summaries = new[]
13+
{
14+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
15+
};
16+
17+
[HttpGet]
18+
public IEnumerable<WeatherForecast> Get()
19+
{
20+
var rng = new Random();
21+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
22+
{
23+
Date = DateTime.Now.AddDays(index),
24+
TemperatureC = rng.Next(-20, 55),
25+
Summary = _summaries[rng.Next(_summaries.Length)]
26+
})
27+
.ToArray();
28+
}
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>9</LangVersion>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.3" />
11+
</ItemGroup>
12+
13+
</Project>

FrontEndBackEndDemo.Api/Program.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
3+
4+
namespace FrontEndBackEndDemo.Api
5+
{
6+
public class Program
7+
{
8+
public static void Main(string[] args)
9+
{
10+
CreateHostBuilder(args).Build().Run();
11+
}
12+
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
19+
}
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:64073",
8+
"sslPort": 0
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "swagger",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"FrontEndBackEndDemo.Api": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "swagger",
25+
"applicationUrl": "http://localhost:5000",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

FrontEndBackEndDemo.Api/Startup.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.AspNetCore.Hosting;
3+
using Microsoft.Extensions.Configuration;
4+
using Microsoft.Extensions.DependencyInjection;
5+
using Microsoft.Extensions.Hosting;
6+
using Microsoft.OpenApi.Models;
7+
8+
namespace FrontEndBackEndDemo.Api
9+
{
10+
public class Startup
11+
{
12+
public Startup(IConfiguration configuration)
13+
{
14+
Configuration = configuration;
15+
}
16+
17+
public IConfiguration Configuration { get; }
18+
19+
// This method gets called by the runtime. Use this method to add services to the container.
20+
public void ConfigureServices(IServiceCollection services)
21+
{
22+
23+
services.AddControllers();
24+
services.AddSwaggerGen(c =>
25+
{
26+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "FrontEndBackEndDemo.Api", Version = "v1" });
27+
});
28+
}
29+
30+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
31+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
32+
{
33+
if (env.IsDevelopment())
34+
{
35+
app.UseDeveloperExceptionPage();
36+
app.UseSwagger();
37+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "FrontEndBackEndDemo.Api v1"));
38+
}
39+
40+
app.UseRouting();
41+
42+
app.UseAuthorization();
43+
44+
app.UseEndpoints(endpoints =>
45+
{
46+
endpoints.MapControllers();
47+
});
48+
}
49+
}
50+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
3+
namespace FrontEndBackEndDemo.Api
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
15+
public WeatherForecast()
16+
{
17+
Summary = string.Empty;
18+
}
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using FrontEndBackEndDemo.Web.Models;
2+
using FrontEndBackEndDemo.Web.Options;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Microsoft.Extensions.Options;
5+
using System.Collections.Generic;
6+
using System.Diagnostics;
7+
using System.IO;
8+
using System.Net.Http;
9+
using System.Text.Json;
10+
using System.Threading.Tasks;
11+
12+
namespace FrontEndBackEndDemo.Web.Controllers
13+
{
14+
public class HomeController : Controller
15+
{
16+
private readonly IHttpClientFactory _httpClientFactory;
17+
private readonly IOptionsMonitor<BackEndOptions> _backEndOptionOptionsAccessor;
18+
19+
public HomeController(
20+
IHttpClientFactory httpClientFactory,
21+
IOptionsMonitor<BackEndOptions> backEndOptionOptionsAccessor)
22+
{
23+
_httpClientFactory = httpClientFactory;
24+
_backEndOptionOptionsAccessor = backEndOptionOptionsAccessor;
25+
}
26+
27+
public async Task<IActionResult> Index()
28+
{
29+
HttpClient httpClient = _httpClientFactory.CreateClient();
30+
HttpResponseMessage backEndApiResponseMessage = await httpClient.GetAsync(
31+
_backEndOptionOptionsAccessor.CurrentValue.BackEndApiEndPoint);
32+
if (backEndApiResponseMessage.IsSuccessStatusCode)
33+
{
34+
using Stream backEndApiResponseStream =
35+
await backEndApiResponseMessage.Content.ReadAsStreamAsync();
36+
IEnumerable<WeatherForecast>? weatherForecast =
37+
await JsonSerializer.DeserializeAsync<IEnumerable<WeatherForecast>>(backEndApiResponseStream);
38+
return View(weatherForecast);
39+
}
40+
return NotFound();
41+
}
42+
43+
public IActionResult Privacy()
44+
{
45+
return View();
46+
}
47+
48+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
49+
public IActionResult Error()
50+
{
51+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
52+
}
53+
}
54+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<LangVersion>9</LangVersion>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)