diff options
Diffstat (limited to 'ExamTemplate')
| -rw-r--r-- | ExamTemplate/Data/Class1.cs | 8 | ||||
| -rw-r--r-- | ExamTemplate/Data/Data.csproj | 7 | ||||
| -rw-r--r-- | ExamTemplate/Data/Models/Role.cs | 13 | ||||
| -rw-r--r-- | ExamTemplate/Data/Models/User.cs | 15 | ||||
| -rw-r--r-- | ExamTemplate/Data/TemplateContext.cs | 20 | ||||
| -rw-r--r-- | ExamTemplate/Web/Startup.cs | 6 | ||||
| -rw-r--r-- | ExamTemplate/Web/appsettings.Development.json | 9 | ||||
| -rw-r--r-- | ExamTemplate/Web/appsettings.json | 3 |
8 files changed, 63 insertions, 18 deletions
diff --git a/ExamTemplate/Data/Class1.cs b/ExamTemplate/Data/Class1.cs deleted file mode 100644 index 78d17f8..0000000 --- a/ExamTemplate/Data/Class1.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System;
-
-namespace Data
-{
- public class Class1
- {
- }
-}
diff --git a/ExamTemplate/Data/Data.csproj b/ExamTemplate/Data/Data.csproj index 7be2d32..909eb58 100644 --- a/ExamTemplate/Data/Data.csproj +++ b/ExamTemplate/Data/Data.csproj @@ -4,8 +4,13 @@ <ProjectReference Include="..\Common\Common.csproj" /> </ItemGroup>
+ <ItemGroup> + <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.5" /> + <PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.5" /> + </ItemGroup>
+
<PropertyGroup>
- <TargetFramework>netstandard2.0</TargetFramework>
+ <TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
diff --git a/ExamTemplate/Data/Models/Role.cs b/ExamTemplate/Data/Models/Role.cs new file mode 100644 index 0000000..94e5c48 --- /dev/null +++ b/ExamTemplate/Data/Models/Role.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Identity; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ExamTemplate.Data.Models +{ + [Table("Roles")] + public class Role : IdentityRole<Guid> + { + public List<User> Users { get; set; } = new List<User>(); + } +} diff --git a/ExamTemplate/Data/Models/User.cs b/ExamTemplate/Data/Models/User.cs new file mode 100644 index 0000000..0c3f4c7 --- /dev/null +++ b/ExamTemplate/Data/Models/User.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Identity; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ExamTemplate.Data.Models +{ + [Table("Users")] + public class User : IdentityUser<Guid> + { + public string FirstName { get; set; } + public string LastName { get; set; } + public List<Role> Roles { get; set; } + } +} diff --git a/ExamTemplate/Data/TemplateContext.cs b/ExamTemplate/Data/TemplateContext.cs new file mode 100644 index 0000000..3a682b0 --- /dev/null +++ b/ExamTemplate/Data/TemplateContext.cs @@ -0,0 +1,20 @@ +using System;
+using ExamTemplate.Data.Models;
+using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore;
+
+namespace ExamTemplate.Data
+{
+ public class TemplateContext : IdentityDbContext<User, Role, Guid>
+ {
+ public TemplateContext(DbContextOptions<TemplateContext> options)
+ : base(options) { }
+
+ protected override void OnModelCreating(ModelBuilder builder)
+ {
+ /* Custom logic here! */
+
+ base.OnModelCreating(builder);
+ }
+ }
+}
diff --git a/ExamTemplate/Web/Startup.cs b/ExamTemplate/Web/Startup.cs index 007f311..d6635b8 100644 --- a/ExamTemplate/Web/Startup.cs +++ b/ExamTemplate/Web/Startup.cs @@ -1,5 +1,7 @@ +using ExamTemplate.Data;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
+using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -19,6 +21,10 @@ namespace Web public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
+
+ // Database configuration
+ services.AddDbContext<TemplateContext>(options =>
+ options.UseNpgsql(this.Configuration.GetConnectionString("LocalDBConnection")));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
diff --git a/ExamTemplate/Web/appsettings.Development.json b/ExamTemplate/Web/appsettings.Development.json deleted file mode 100644 index dba68eb..0000000 --- a/ExamTemplate/Web/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information",
- "Microsoft": "Warning",
- "Microsoft.Hosting.Lifetime": "Information"
- } - } -} diff --git a/ExamTemplate/Web/appsettings.json b/ExamTemplate/Web/appsettings.json index 81ff877..f49d9ab 100644 --- a/ExamTemplate/Web/appsettings.json +++ b/ExamTemplate/Web/appsettings.json @@ -1,4 +1,7 @@ {
+ "ConnectionStrings": {
+ "LocalDBConnection": "Server=localhost;Port=5432;Database=TemplateContext;User Id=;Password=;"
+ },
"Logging": {
"LogLevel": {
"Default": "Information",
|
