Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Added UseRequireLoginMiddleware extension method #98

Open
wants to merge 56 commits into
base: 3.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
db33493
Initial migration to 3.0
DamianEdwards May 12, 2019
306885b
Update sln file to Dev16
DamianEdwards May 15, 2019
1df8034
Application clean up
davidfowl May 16, 2019
4c1899f
Use username for attendees
davidfowl May 16, 2019
7715b4f
Change filter to middleware
davidfowl May 16, 2019
c6b568b
Simplify admin user creation (first is admin)
DamianEdwards May 17, 2019
0729467
Cache conference data on home page.
DamianEdwards May 18, 2019
7994588
ExcludeAssets="runtime" for scaffolding package to prevent Roslyn, et…
DamianEdwards May 24, 2019
0d3d67f
Move session abstract line formatting to the razor file
DamianEdwards May 24, 2019
e2ac852
Use System.Text.Json on the backend
davidfowl Jun 1, 2019
ec71919
Moved to preview6
DamianEdwards Jun 11, 2019
e40f69a
Removed feeds
davidfowl Jun 14, 2019
fd50c14
3.0 updates to session 1 and session 2
davidfowl Jun 15, 2019
0435987
Finished up to 3
davidfowl Jun 15, 2019
c32d109
Updated images and project creation
davidfowl Jun 15, 2019
44ec856
More updates
davidfowl Jun 15, 2019
0878679
More changes to descriptions
davidfowl Jun 16, 2019
6618815
Streamline project creation from the command line
davidfowl Jun 16, 2019
8417709
Fixe dotnet ef global tool instructions
davidfowl Jun 16, 2019
26d1195
Add conosle coloring
davidfowl Jun 16, 2019
d31a763
Half updated section 4
davidfowl Jun 16, 2019
23c106c
Updated auth features
davidfowl Jun 16, 2019
5c2c238
Make the MyAgenda page work again
DamianEdwards Jun 16, 2019
af6b9c0
Updated session5
davidfowl Jun 16, 2019
ad8f1a8
Use the endpoint routes
davidfowl Jun 16, 2019
8c8c910
Small tweaks
davidfowl Jun 16, 2019
368c3f2
Fixed image
davidfowl Jun 16, 2019
ee63094
Got app working
DamianEdwards Jun 16, 2019
cf1de7f
Make EditSession use AlertPartial
DamianEdwards Jun 16, 2019
1665f20
Fix the Session page so unauthenticated users can view it
DamianEdwards Jun 16, 2019
dad1df3
Fix scaffolding package reference
DamianEdwards Jun 16, 2019
bcc4f25
Updated docs
davidfowl Jun 16, 2019
0545b67
Add NDC Oslo data
davidfowl Jun 17, 2019
452075d
Made some tweaks to session2
davidfowl Jun 17, 2019
a8f16f2
Use the extension methods to get search results
davidfowl Jun 17, 2019
a21c224
Small nits
davidfowl Jun 17, 2019
e28fdce
Add EF error and work around
davidfowl Jun 17, 2019
36cd17e
Small nits in global tool
davidfowl Jun 17, 2019
c807479
Use preview6 image
davidfowl Jun 17, 2019
339b020
Added the first snapshot
davidfowl Jun 17, 2019
60c19a7
Added more save points
davidfowl Jun 17, 2019
51c8e7e
Added more save points
davidfowl Jun 17, 2019
e04d885
More save points
davidfowl Jun 17, 2019
d5d4c7f
Updated save points
davidfowl Jun 17, 2019
e5af7ce
Remove install package image
davidfowl Jun 17, 2019
77f086f
Clean up the first session instructions
davidfowl Jun 17, 2019
6a41dee
Changes to snapshot and session2
davidfowl Jun 17, 2019
76bcc6a
Remove redundant EntityExtensions
davidfowl Jun 17, 2019
85c75cb
Session 4 clean up
davidfowl Jun 17, 2019
5bc9526
Minor tweaks to 6
davidfowl Jun 17, 2019
a570f67
Put swagger first
davidfowl Jun 18, 2019
18bf2e3
Before routing is more appropriate
davidfowl Jun 18, 2019
7622c41
Fixed the tag name
davidfowl Jun 18, 2019
4a3ff6c
Tweaks to the workshop docs
davidfowl Jun 18, 2019
d46a50d
Fixed db -> _context
davidfowl Jun 18, 2019
73559ac
Added UseRequireLoginMiddleware extension method
mmayr-at Jun 18, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions ConferencePlanner.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26606.0
# Visual Studio Version 16
VisualStudioVersion = 16.0.28902.138
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FrontEnd", "src\FrontEnd\FrontEnd.csproj", "{520772E8-2FA9-4A3E-8F62-ACA084EA2AFF}"
EndProject
Expand Down
75 changes: 43 additions & 32 deletions docs/1. Create BackEnd API project.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@

## Creating a basic EF model
## Creating a new project using Visual Studio
1. Create and add a new project named `BackEnd` and name the solution `ConferencePlanner` using File / New / ASP.NET Core Web Application. Select the Web API template, No Auth, no Docker support.
![](images/vs2019-new-project.png "Creating a new solution in Visual Studio")
![](images/vs2019-name-backend-project.png "Adding a project to the solution")
![](images/vs2019-new-web-api.png "Web API Project settings")

## Creating a new project using the Command Line

1. Create a new solution called `ConferencePlanner`, and add a new project named `BackEnd` using File / New / ASP.NET Core Web Application. Select the Web API template, No Auth, no Docker support.
![](images/new-solution.png "Creating a new solution in Visual Studio")
![](images/add-project.png "Adding a project to the solution")
![](images/name-backend-project.png "Naming the new Web API project")
![](images/new-web-api-settings.png "Web API Project settings")
1. Create folder `ConferencePlanner` and call `dotnet new sln` at the cmd line to create a solution
1. Create a project using `dotnet new webapi -n BackEnd` at the cmd line inside the folder BackEnd
1. Add the project to the solution using `dotnet sln add BackEnd`

## Creating a basic EF model

> ***Note:* If not using Visual Studio, create the project using `dotnet new webapi` at the cmd line, details as follows:**
> 1. Create folder ConferencePlanner and call `dotnet new sln` at the cmd line to create a solution
> 2. Create sub-folder BackEnd and create a project using `dotnet new webapi` at the cmd line inside the folder BackEnd
> 3. Add the project to the solution using `dotnet sln add BackEnd\BackEnd.csproj`
1. Add a new `Models` folder to the root of the application.
1. Add a new `Speaker` class using the following code:
```csharp
Expand All @@ -19,14 +21,12 @@
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore.Design;

namespace BackEnd.Models
{
public class Speaker
{
public int ID { get; set; }
public int Id { get; set; }

[Required]
[StringLength(200)]
Expand All @@ -40,6 +40,10 @@
}
}
```
1. Add a reference to the NuGet package `Microsoft.EntityFrameworkCore.SqlServer` version `3.0.0-preview6.19304.10`.
> This can be done from the command line using `dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 3.0.0-preview6.19304.10`
1. Add a reference to the NuGet package `Microsoft.EntityFrameworkCore.Sqlite` version `3.0.0-preview6.19304.10`.
> This can be done from the command line using `dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 3.0.0-preview6.19304.10`
1. Next we'll create a new Entity Framework DbContext. Create a new `ApplicationDbContext` class in the `Models` folder using the following code:
```csharp
using Microsoft.EntityFrameworkCore;
Expand Down Expand Up @@ -68,7 +72,9 @@
},
"Logging": {
"LogLevel": {
"Default": "Warning"
"Default": "Warning",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
Expand All @@ -91,14 +97,14 @@
});
```
> This code registers the `ApplicationDbContext` service so it can be injected into controllers. Additionally, it configures operating system specific database technologies and connection strings
1. Add a reference to the NuGet package `Microsoft.EntityFrameworkCore.Sqlite`. Note that you'll need to resolve several references by adding missing `using` statements (`Ctrl + .` is your friend).
![](images/add-sqlite-nuget-reference.png "Adding the SQLite NuGet reference")

> **If you're not using Visual Studio** install the package from the command line with `dotnet add package Microsoft.EntityFrameworkCore.Sqlite --version 2.2.1`

## Configuring EF Migrations

1. Add a reference to the NuGet package `Microsoft.EntityFrameworkCore.Tools` version `3.0.0-preview6.19304.10`.
> **If you're not using Visual Studio** install the package from the command line with `dotnet add package Microsoft.EntityFrameworkCore.Tools --version 3.0.0-preview6.19304.10`

### Visual Studio: Package Manager Console

1. In Visual Studio, select the Tools -> NuGet Package Manager -> Package Manager Console

1. Run the following commands in the Package Manager Console
Expand All @@ -109,6 +115,11 @@

### Command line

1. Install the EntityFramework global tool `dotnet-ef` using the following command:
```console
dotnet tool install -g dotnet-ef --version 3.0.0-preview6.19304.10
```

1. Open a command prompt and navigate to the project directory. (The directory containing the `Startup.cs` file).

1. Run the following commands in the command prompt:
Expand Down Expand Up @@ -139,19 +150,18 @@ First, open the `Controllers` folder and take a quick look at the `ValuesControl

### Using the cmd line
1. Install the "Microsoft.VisualStudio.Web.CodeGeneration.Design" package
```
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 2.2.0
```
```console
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design --version 3.0.0-preview5-19264-04
```

1. Install the `aspnet-codegenerator` global tool by running the following command:

```
dotnet tool install --global dotnet-aspnet-codegenerator
```
```console
dotnet tool install -g dotnet-aspnet-codegenerator --version 3.0.0-preview5-19264-04
```

> Note: You will need to close and reopen the console window to be able to use this tool.
2. Run the following in the project folder at the cmd line:
```
```console
dotnet aspnet-codegenerator controller -api -name SpeakersController -m Speaker -dc BackEnd.Models.ApplicationDbContext -outDir Controllers
```

Expand All @@ -165,25 +175,26 @@ In this section, we'll be adding documentation to our API using the Swashbuckle

Additional information on using Swashbuckle in ASP.NET Core is available in this tutorial: [ASP.NET Web API Help Pages using Swagger](https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger)

1. Add the `Swashbuckle.AspNetCore` NuGet package.
> This can be done from the command line using `dotnet add package Swashbuckle.AspNetCore`
1. Add a reference to the NuGet package `Swashbuckle.AspNetCore` version `5.0.0-rc2`.
> This can be done from the command line using `dotnet add package Swashbuckle.AspNetCore --version 5.0.0-rc2`

1. Add the Swashbuckle services in your `ConfigureServices` method:
```csharp
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddControllers();

services.AddSwaggerGen(options =>
options.SwaggerDoc("v1", new Info { Title = "Conference Planner API", Version = "v1" })
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Conference Planner API", Version = "v1" })
);
```
1. Configure Swashbuckle by adding the following lines to top of the `Configure` method in `Startup.cs`:
1. Configure Swashbuckle by adding the following lines just before `UseRouting` in the `Configure` method in `Startup.cs`:
```csharp
app.UseSwagger();

app.UseSwaggerUI(options =>
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Conference Planner API v1")
);
```
> ***Note:* Due to how the middleware and pipeline are structured, you'll want to place this before the `app.UseMvc()` statement.**
> ***Note:* Due to how the middleware and pipeline are structured, you'll want to place this before the `app.UseEndpoints()` statement.**
1. Add a redirect to the end of the pipeline that redirects to the swagger end point.
```csharp
app.Run(context =>
Expand Down
Loading