Skip to content

Commit fa58f56

Browse files
authored
Merge pull request #13 from lreb/releases/net5
Releases/net5
2 parents 5c72a7a + 0ffb31e commit fa58f56

31 files changed

+764
-5
lines changed

.vscode/launch.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": ".NET Core Launch (web)",
9+
"type": "coreclr",
10+
"request": "launch",
11+
"preLaunchTask": "build",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/FacwareBase.API/bin/Debug/netcoreapp3.1/FacwareBase.API.dll",
14+
"args": [],
15+
"cwd": "${workspaceFolder}/FacwareBase.API",
16+
"stopAtEntry": false,
17+
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
18+
"serverReadyAction": {
19+
"action": "openExternally",
20+
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
21+
},
22+
"env": {
23+
"ASPNETCORE_ENVIRONMENT": "Development"
24+
},
25+
"sourceFileMap": {
26+
"/Views": "${workspaceFolder}/Views"
27+
}
28+
},
29+
{
30+
"name": ".NET Core Attach",
31+
"type": "coreclr",
32+
"request": "attach",
33+
"processId": "${command:pickProcess}"
34+
}
35+
]
36+
}

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

.vscode/tasks.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
8+
"args": [
9+
"build",
10+
"${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj",
11+
"/property:GenerateFullPaths=true",
12+
"/consoleloggerparameters:NoSummary"
13+
],
14+
"problemMatcher": "$msCompile"
15+
},
16+
{
17+
"label": "publish",
18+
"command": "dotnet",
19+
"type": "process",
20+
"args": [
21+
"publish",
22+
"${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj",
23+
"/property:GenerateFullPaths=true",
24+
"/consoleloggerparameters:NoSummary"
25+
],
26+
"problemMatcher": "$msCompile"
27+
},
28+
{
29+
"label": "watch",
30+
"command": "dotnet",
31+
"type": "process",
32+
"args": [
33+
"watch",
34+
"run",
35+
"${workspaceFolder}/FacwareBase.API/FacwareBase.API.csproj",
36+
"/property:GenerateFullPaths=true",
37+
"/consoleloggerparameters:NoSummary"
38+
],
39+
"problemMatcher": "$msCompile"
40+
}
41+
]
42+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Facware.Data.Access;
6+
using Facware.Data.Access.Repository.Interface;
7+
using Microsoft.AspNetCore.Mvc;
8+
using Microsoft.EntityFrameworkCore;
9+
10+
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
11+
12+
namespace Facware.Api.Controllers
13+
{
14+
[Route("api/[controller]")]
15+
public class ItemsController : Controller
16+
{
17+
private readonly FacwareDbContext _context;
18+
19+
private IItemRepository _itemRepository;
20+
21+
public ItemsController(FacwareDbContext context,
22+
IItemRepository itemRepository)
23+
{
24+
_context = context;
25+
_itemRepository = itemRepository;
26+
}
27+
28+
// GET: api/values
29+
[HttpGet]
30+
public async Task<IActionResult> Get()
31+
{
32+
var data = await _context.Items.ToListAsync();
33+
return Ok(data);
34+
}
35+
36+
// GET api/values/5
37+
[HttpGet("{id}")]
38+
public IActionResult Get(int id)
39+
{
40+
return Ok(_itemRepository.GetById(id));
41+
}
42+
43+
// POST api/values
44+
[HttpPost]
45+
public void Post([FromBody] string value)
46+
{
47+
}
48+
49+
// PUT api/values/5
50+
[HttpPut("{id}")]
51+
public void Put(int id, [FromBody] string value)
52+
{
53+
}
54+
55+
// DELETE api/values/5
56+
[HttpDelete("{id}")]
57+
public void Delete(int id)
58+
{
59+
}
60+
}
61+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.Extensions.Logging;
7+
8+
namespace Facware.Api.Controllers
9+
{
10+
[ApiController]
11+
[Route("[controller]")]
12+
public class WeatherForecastController : ControllerBase
13+
{
14+
private static readonly string[] Summaries = new[]
15+
{
16+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
17+
};
18+
19+
private readonly ILogger<WeatherForecastController> _logger;
20+
21+
public WeatherForecastController(ILogger<WeatherForecastController> logger)
22+
{
23+
_logger = logger;
24+
}
25+
26+
[HttpGet]
27+
public IEnumerable<WeatherForecast> Get()
28+
{
29+
var rng = new Random();
30+
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
31+
{
32+
Date = DateTime.Now.AddDays(index),
33+
TemperatureC = rng.Next(-20, 55),
34+
Summary = Summaries[rng.Next(Summaries.Length)]
35+
})
36+
.ToArray();
37+
}
38+
}
39+
}

Facware.Api/Facware.Api.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.1" NoWarn="NU1605" />
9+
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="5.0.1" NoWarn="NU1605" />
10+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.1">
12+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13+
<PrivateAssets>all</PrivateAssets>
14+
</PackageReference>
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<ProjectReference Include="..\Facware.Data.Access\Facware.Data.Access.csproj">
19+
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
20+
</ProjectReference>
21+
</ItemGroup>
22+
</Project>

Facware.Api/Program.cs

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

Facware.Api/Startup.cs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Facware.Data.Access;
6+
using Facware.Data.Access.Base.Base;
7+
using Facware.Data.Access.Repository.Implementation;
8+
using Facware.Data.Access.Repository.Interface;
9+
using Microsoft.AspNetCore.Builder;
10+
using Microsoft.AspNetCore.Hosting;
11+
using Microsoft.AspNetCore.HttpsPolicy;
12+
using Microsoft.AspNetCore.Mvc;
13+
using Microsoft.EntityFrameworkCore;
14+
using Microsoft.Extensions.Configuration;
15+
using Microsoft.Extensions.DependencyInjection;
16+
using Microsoft.Extensions.Hosting;
17+
using Microsoft.Extensions.Logging;
18+
using Microsoft.OpenApi.Models;
19+
20+
namespace Facware.Api
21+
{
22+
public class Startup
23+
{
24+
public Startup(IConfiguration configuration)
25+
{
26+
_configuration = configuration;
27+
}
28+
29+
public IConfiguration _configuration { get; }
30+
31+
// This method gets called by the runtime. Use this method to add services to the container.
32+
public void ConfigureServices(IServiceCollection services)
33+
{
34+
35+
services.AddControllers();
36+
services.AddSwaggerGen(c =>
37+
{
38+
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Facware.Api", Version = "v1" });
39+
});
40+
41+
var connectionString = _configuration["DbContextSettings:ConnectionString"];
42+
services.AddDbContext<FacwareDbContext>(options =>
43+
options.UseNpgsql(
44+
connectionString,
45+
x => x.MigrationsAssembly("Facware.Data.Access")));
46+
47+
services.AddTransient(typeof(IGenericRepository<>), typeof(GenericRepository<>));
48+
services.AddTransient<IItemRepository, ItemRepository>();
49+
50+
}
51+
52+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
53+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
54+
{
55+
if (env.IsDevelopment())
56+
{
57+
app.UseDeveloperExceptionPage();
58+
app.UseSwagger();
59+
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Facware.Api v1"));
60+
}
61+
62+
app.UseHttpsRedirection();
63+
64+
app.UseRouting();
65+
66+
app.UseAuthorization();
67+
68+
app.UseEndpoints(endpoints =>
69+
{
70+
endpoints.MapControllers();
71+
});
72+
}
73+
}
74+
}

Facware.Api/WeatherForecast.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace Facware.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+
}

0 commit comments

Comments
 (0)