Skip to content

Commit d6e96d9

Browse files
authored
Add Postgres example (#4)
1 parent ddba962 commit d6e96d9

File tree

134 files changed

+27458
-1
lines changed

Some content is hidden

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

134 files changed

+27458
-1
lines changed

Postgres/Postgres.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27130.2024
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Postgres", "Postgres\Postgres.csproj", "{9C99EB70-BB57-4D41-876D-B35234DC4E39}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{9C99EB70-BB57-4D41-876D-B35234DC4E39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{9C99EB70-BB57-4D41-876D-B35234DC4E39}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{9C99EB70-BB57-4D41-876D-B35234DC4E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{9C99EB70-BB57-4D41-876D-B35234DC4E39}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {5BC14972-1FF4-49F1-A51F-3885C2F43261}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Identity;
6+
using Microsoft.AspNetCore.Mvc;
7+
using Microsoft.Extensions.Logging;
8+
using Postgres.Data;
9+
10+
namespace Postgres.Controllers
11+
{
12+
[Route("[controller]/[action]")]
13+
public class AccountController : Controller
14+
{
15+
private readonly SignInManager<ApplicationUser> _signInManager;
16+
private readonly ILogger _logger;
17+
18+
public AccountController(SignInManager<ApplicationUser> signInManager, ILogger<AccountController> logger)
19+
{
20+
_signInManager = signInManager;
21+
_logger = logger;
22+
}
23+
24+
[HttpPost]
25+
[ValidateAntiForgeryToken]
26+
public async Task<IActionResult> Logout()
27+
{
28+
await _signInManager.SignOutAsync();
29+
_logger.LogInformation("User logged out.");
30+
return RedirectToPage("/Index");
31+
}
32+
}
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
6+
using Microsoft.EntityFrameworkCore;
7+
8+
namespace Postgres.Data
9+
{
10+
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
11+
{
12+
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
13+
: base(options)
14+
{
15+
}
16+
17+
protected override void OnModelCreating(ModelBuilder builder)
18+
{
19+
base.OnModelCreating(builder);
20+
// Customize the ASP.NET Identity model and override the defaults if needed.
21+
// For example, you can rename the ASP.NET Identity table names and more.
22+
// Add your customizations after calling base.OnModelCreating(builder);
23+
}
24+
}
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Identity;
6+
7+
namespace Postgres.Data
8+
{
9+
// Add profile data for application users by adding properties to the ApplicationUser class
10+
public class ApplicationUser : IdentityUser
11+
{
12+
}
13+
}

Postgres/Postgres/Data/Contact.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Postgres.Data
2+
{
3+
public class Contact
4+
{
5+
public int Id { get; set; }
6+
public string Name { get; set; }
7+
public string Address { get; set; }
8+
public string City { get; set; }
9+
public string Subregion { get; set; }
10+
public string PostalCode { get; set; }
11+
public string Phone { get; set; }
12+
public string Email { get; set; }
13+
}
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using Microsoft.EntityFrameworkCore;
2+
3+
namespace Postgres.Data
4+
{
5+
public class ContactsDbContext : DbContext
6+
{
7+
public DbSet<Contact> Contacts { get; set; }
8+
9+
public ContactsDbContext(DbContextOptions<ContactsDbContext> options)
10+
: base(options)
11+
{
12+
13+
}
14+
}
15+
}

Postgres/Postgres/Data/Migrations/00000000000000_CreateIdentitySchema.Designer.cs

Lines changed: 216 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)