├── .gitignore
├── CleanArchitecture.sln
├── README.md
├── src
├── Core.Application
│ ├── Core.Application.csproj
│ ├── DTOs
│ │ ├── ApplicationUserDto.cs
│ │ ├── AuthenticationResponse.cs
│ │ ├── EmailConfirmationRequest.cs
│ │ ├── EmailConfirmationResponse.cs
│ │ ├── ResetPasswordRequest.cs
│ │ ├── SignInRequest.cs
│ │ └── SignUpRequest.cs
│ ├── Extensions
│ │ └── ServiceCollectionExtensions.cs
│ ├── Interfaces
│ │ ├── Application
│ │ │ ├── ICurrentUserService.cs
│ │ │ └── IDateTimeService.cs
│ │ ├── Identity
│ │ │ ├── IAuthService.cs
│ │ │ └── IUserService.cs
│ │ └── Persistence
│ │ │ ├── IIdentifiable.cs
│ │ │ ├── IRepositoryBase.cs
│ │ │ ├── IServiceBase.cs
│ │ │ └── IUnitOfWork.cs
│ └── Mapper
│ │ └── ApplicationProfile.cs
├── Core.Domain
│ ├── Core.Domain.csproj
│ └── Entities
│ │ ├── AuditableEntityBase.cs
│ │ └── EntityBase.cs
├── Infrastructure.Identity
│ ├── Data
│ │ └── AppIdentityDbContext.cs
│ ├── Extensions
│ │ ├── IdentityResultExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── Infrastructure.Identity.csproj
│ ├── Mapper
│ │ └── InfrastructureProfile.cs
│ ├── Migrations
│ │ ├── 20230408115648_InitialModel.Designer.cs
│ │ ├── 20230408115648_InitialModel.cs
│ │ └── AppIdentityDbContextModelSnapshot.cs
│ ├── Models
│ │ └── ApplicationUser.cs
│ └── Services
│ │ ├── AuthService.cs
│ │ └── UserService.cs
├── Infrastructure.Persistence
│ ├── Data
│ │ └── AppDbContext.cs
│ ├── Extensions
│ │ └── ServiceCollectionExtensions.cs
│ ├── Infrastructure.Persistence.csproj
│ ├── Interceptors
│ │ └── AuditableEntitySaveChangesInterceptor.cs
│ ├── Migrations
│ │ ├── 20230408115629_InitialModel.Designer.cs
│ │ ├── 20230408115629_InitialModel.cs
│ │ └── AppDbContextModelSnapshot.cs
│ ├── Repositories
│ │ ├── RepositoryBase.cs
│ │ └── UnitOfWork.cs
│ └── Services
│ │ └── ServiceBase.cs
├── Infrastructure.Shared
│ ├── Extensions
│ │ └── ServiceCollectionExtensions.cs
│ ├── Infrastructure.Shared.csproj
│ ├── Services
│ │ └── DateTimeService.cs
│ └── appsettings.json
├── Web.Api
│ ├── Controllers
│ │ └── AuthController.cs
│ ├── Program.cs
│ ├── Properties
│ │ └── launchSettings.json
│ └── Web.Api.csproj
└── Web.Razor
│ ├── Areas
│ └── Identity
│ │ └── Pages
│ │ ├── Account
│ │ ├── AccessDenied.cshtml
│ │ ├── AccessDenied.cshtml.cs
│ │ ├── ConfirmEmail.cshtml
│ │ ├── ConfirmEmail.cshtml.cs
│ │ ├── ConfirmEmailChange.cshtml
│ │ ├── ConfirmEmailChange.cshtml.cs
│ │ ├── ForgotPassword.cshtml
│ │ ├── ForgotPassword.cshtml.cs
│ │ ├── ForgotPasswordConfirmation.cshtml
│ │ ├── ForgotPasswordConfirmation.cshtml.cs
│ │ ├── Login.cshtml
│ │ ├── Login.cshtml.cs
│ │ ├── Logout.cshtml
│ │ ├── Logout.cshtml.cs
│ │ ├── Manage
│ │ │ ├── ChangePassword.cshtml
│ │ │ ├── ChangePassword.cshtml.cs
│ │ │ ├── Email.cshtml
│ │ │ ├── Email.cshtml.cs
│ │ │ ├── Index.cshtml
│ │ │ ├── Index.cshtml.cs
│ │ │ ├── ManageNavPages.cs
│ │ │ ├── _Layout.cshtml
│ │ │ ├── _ManageNav.cshtml
│ │ │ ├── _StatusMessage.cshtml
│ │ │ └── _ViewImports.cshtml
│ │ ├── Register.cshtml
│ │ ├── Register.cshtml.cs
│ │ ├── RegisterConfirmation.cshtml
│ │ ├── RegisterConfirmation.cshtml.cs
│ │ ├── ResendEmailConfirmation.cshtml
│ │ ├── ResendEmailConfirmation.cshtml.cs
│ │ ├── ResetPassword.cshtml
│ │ ├── ResetPassword.cshtml.cs
│ │ ├── ResetPasswordConfirmation.cshtml
│ │ ├── ResetPasswordConfirmation.cshtml.cs
│ │ ├── _StatusMessage.cshtml
│ │ └── _ViewImports.cshtml
│ │ ├── Error.cshtml
│ │ ├── Error.cshtml.cs
│ │ ├── _ValidationScriptsPartial.cshtml
│ │ ├── _ViewImports.cshtml
│ │ └── _ViewStart.cshtml
│ ├── Extensions
│ └── ServiceCollectionExtensions.cs
│ ├── Pages
│ ├── Error.cshtml
│ ├── Error.cshtml.cs
│ ├── Index.cshtml
│ ├── Index.cshtml.cs
│ ├── Privacy.cshtml
│ ├── Privacy.cshtml.cs
│ ├── Shared
│ │ ├── _Layout.cshtml
│ │ ├── _Layout.cshtml.css
│ │ ├── _LoginPartial.cshtml
│ │ └── _ValidationScriptsPartial.cshtml
│ ├── _ViewImports.cshtml
│ └── _ViewStart.cshtml
│ ├── Program.cs
│ ├── Properties
│ └── launchSettings.json
│ ├── Services
│ └── CurrentUserService.cs
│ ├── Web.Razor.csproj
│ └── wwwroot
│ ├── css
│ └── site.css
│ ├── favicon.ico
│ ├── js
│ └── site.js
│ └── lib
│ ├── bootstrap
│ ├── LICENSE
│ └── dist
│ │ ├── css
│ │ ├── bootstrap-grid.css
│ │ ├── bootstrap-grid.css.map
│ │ ├── bootstrap-grid.min.css
│ │ ├── bootstrap-grid.min.css.map
│ │ ├── bootstrap-grid.rtl.css
│ │ ├── bootstrap-grid.rtl.css.map
│ │ ├── bootstrap-grid.rtl.min.css
│ │ ├── bootstrap-grid.rtl.min.css.map
│ │ ├── bootstrap-reboot.css
│ │ ├── bootstrap-reboot.css.map
│ │ ├── bootstrap-reboot.min.css
│ │ ├── bootstrap-reboot.min.css.map
│ │ ├── bootstrap-reboot.rtl.css
│ │ ├── bootstrap-reboot.rtl.css.map
│ │ ├── bootstrap-reboot.rtl.min.css
│ │ ├── bootstrap-reboot.rtl.min.css.map
│ │ ├── bootstrap-utilities.css
│ │ ├── bootstrap-utilities.css.map
│ │ ├── bootstrap-utilities.min.css
│ │ ├── bootstrap-utilities.min.css.map
│ │ ├── bootstrap-utilities.rtl.css
│ │ ├── bootstrap-utilities.rtl.css.map
│ │ ├── bootstrap-utilities.rtl.min.css
│ │ ├── bootstrap-utilities.rtl.min.css.map
│ │ ├── bootstrap.css
│ │ ├── bootstrap.css.map
│ │ ├── bootstrap.min.css
│ │ ├── bootstrap.min.css.map
│ │ ├── bootstrap.rtl.css
│ │ ├── bootstrap.rtl.css.map
│ │ ├── bootstrap.rtl.min.css
│ │ └── bootstrap.rtl.min.css.map
│ │ └── js
│ │ ├── bootstrap.bundle.js
│ │ ├── bootstrap.bundle.js.map
│ │ ├── bootstrap.bundle.min.js
│ │ ├── bootstrap.bundle.min.js.map
│ │ ├── bootstrap.esm.js
│ │ ├── bootstrap.esm.js.map
│ │ ├── bootstrap.esm.min.js
│ │ ├── bootstrap.esm.min.js.map
│ │ ├── bootstrap.js
│ │ ├── bootstrap.js.map
│ │ ├── bootstrap.min.js
│ │ └── bootstrap.min.js.map
│ ├── jquery-validation-unobtrusive
│ ├── LICENSE.txt
│ ├── jquery.validate.unobtrusive.js
│ └── jquery.validate.unobtrusive.min.js
│ ├── jquery-validation
│ ├── LICENSE.md
│ └── dist
│ │ ├── additional-methods.js
│ │ ├── additional-methods.min.js
│ │ ├── jquery.validate.js
│ │ └── jquery.validate.min.js
│ └── jquery
│ ├── LICENSE.txt
│ └── dist
│ ├── jquery.js
│ ├── jquery.min.js
│ └── jquery.min.map
└── tests
├── Core.Application.UnitTests
├── Core.Application.UnitTests.csproj
└── Usings.cs
└── Infrastructure.Persistence.IntegrationTests
├── Infrastructure.Persistence.IntegrationTests.csproj
└── Usings.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Aa][Rr][Mm]/
27 | [Aa][Rr][Mm]64/
28 | bld/
29 | [Bb]in/
30 | [Oo]bj/
31 | [Ll]og/
32 | [Ll]ogs/
33 |
34 | # Visual Studio 2015/2017 cache/options directory
35 | .vs/
36 | # Uncomment if you have tasks that create the project's static files in wwwroot
37 | #wwwroot/
38 |
39 | # Visual Studio 2017 auto generated files
40 | Generated\ Files/
41 |
42 | # MSTest test Results
43 | [Tt]est[Rr]esult*/
44 | [Bb]uild[Ll]og.*
45 |
46 | # NUnit
47 | *.VisualState.xml
48 | TestResult.xml
49 | nunit-*.xml
50 |
51 | # Build Results of an ATL Project
52 | [Dd]ebugPS/
53 | [Rr]eleasePS/
54 | dlldata.c
55 |
56 | # Benchmark Results
57 | BenchmarkDotNet.Artifacts/
58 |
59 | # .NET Core
60 | project.lock.json
61 | project.fragment.lock.json
62 | artifacts/
63 |
64 | # StyleCop
65 | StyleCopReport.xml
66 |
67 | # Files built by Visual Studio
68 | *_i.c
69 | *_p.c
70 | *_h.h
71 | *.ilk
72 | *.meta
73 | *.obj
74 | *.iobj
75 | *.pch
76 | *.pdb
77 | *.ipdb
78 | *.pgc
79 | *.pgd
80 | *.rsp
81 | *.sbr
82 | *.tlb
83 | *.tli
84 | *.tlh
85 | *.tmp
86 | *.tmp_proj
87 | *_wpftmp.csproj
88 | *.log
89 | *.vspscc
90 | *.vssscc
91 | .builds
92 | *.pidb
93 | *.svclog
94 | *.scc
95 |
96 | # Chutzpah Test files
97 | _Chutzpah*
98 |
99 | # Visual C++ cache files
100 | ipch/
101 | *.aps
102 | *.ncb
103 | *.opendb
104 | *.opensdf
105 | *.sdf
106 | *.cachefile
107 | *.VC.db
108 | *.VC.VC.opendb
109 |
110 | # Visual Studio profiler
111 | *.psess
112 | *.vsp
113 | *.vspx
114 | *.sap
115 |
116 | # Visual Studio Trace Files
117 | *.e2e
118 |
119 | # TFS 2012 Local Workspace
120 | $tf/
121 |
122 | # Guidance Automation Toolkit
123 | *.gpState
124 |
125 | # ReSharper is a .NET coding add-in
126 | _ReSharper*/
127 | *.[Rr]e[Ss]harper
128 | *.DotSettings.user
129 |
130 | # TeamCity is a build add-in
131 | _TeamCity*
132 |
133 | # DotCover is a Code Coverage Tool
134 | *.dotCover
135 |
136 | # AxoCover is a Code Coverage Tool
137 | .axoCover/*
138 | !.axoCover/settings.json
139 |
140 | # Visual Studio code coverage results
141 | *.coverage
142 | *.coveragexml
143 |
144 | # NCrunch
145 | _NCrunch_*
146 | .*crunch*.local.xml
147 | nCrunchTemp_*
148 |
149 | # MightyMoose
150 | *.mm.*
151 | AutoTest.Net/
152 |
153 | # Web workbench (sass)
154 | .sass-cache/
155 |
156 | # Installshield output folder
157 | [Ee]xpress/
158 |
159 | # DocProject is a documentation generator add-in
160 | DocProject/buildhelp/
161 | DocProject/Help/*.HxT
162 | DocProject/Help/*.HxC
163 | DocProject/Help/*.hhc
164 | DocProject/Help/*.hhk
165 | DocProject/Help/*.hhp
166 | DocProject/Help/Html2
167 | DocProject/Help/html
168 |
169 | # Click-Once directory
170 | publish/
171 |
172 | # Publish Web Output
173 | *.[Pp]ublish.xml
174 | *.azurePubxml
175 | # Note: Comment the next line if you want to checkin your web deploy settings,
176 | # but database connection strings (with potential passwords) will be unencrypted
177 | *.pubxml
178 | *.publishproj
179 |
180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
181 | # checkin your Azure Web App publish settings, but sensitive information contained
182 | # in these scripts will be unencrypted
183 | PublishScripts/
184 |
185 | # NuGet Packages
186 | *.nupkg
187 | # NuGet Symbol Packages
188 | *.snupkg
189 | # The packages folder can be ignored because of Package Restore
190 | **/[Pp]ackages/*
191 | # except build/, which is used as an MSBuild target.
192 | !**/[Pp]ackages/build/
193 | # Uncomment if necessary however generally it will be regenerated when needed
194 | #!**/[Pp]ackages/repositories.config
195 | # NuGet v3's project.json files produces more ignorable files
196 | *.nuget.props
197 | *.nuget.targets
198 |
199 | # Microsoft Azure Build Output
200 | csx/
201 | *.build.csdef
202 |
203 | # Microsoft Azure Emulator
204 | ecf/
205 | rcf/
206 |
207 | # Windows Store app package directories and files
208 | AppPackages/
209 | BundleArtifacts/
210 | Package.StoreAssociation.xml
211 | _pkginfo.txt
212 | *.appx
213 | *.appxbundle
214 | *.appxupload
215 |
216 | # Visual Studio cache files
217 | # files ending in .cache can be ignored
218 | *.[Cc]ache
219 | # but keep track of directories ending in .cache
220 | !?*.[Cc]ache/
221 |
222 | # Others
223 | ClientBin/
224 | ~$*
225 | *~
226 | *.dbmdl
227 | *.dbproj.schemaview
228 | *.jfm
229 | *.pfx
230 | *.publishsettings
231 | orleans.codegen.cs
232 |
233 | # Including strong name files can present a security risk
234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
235 | #*.snk
236 |
237 | # Since there are multiple workflows, uncomment next line to ignore bower_components
238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
239 | #bower_components/
240 |
241 | # RIA/Silverlight projects
242 | Generated_Code/
243 |
244 | # Backup & report files from converting an old project file
245 | # to a newer Visual Studio version. Backup files are not needed,
246 | # because we have git ;-)
247 | _UpgradeReport_Files/
248 | Backup*/
249 | UpgradeLog*.XML
250 | UpgradeLog*.htm
251 | ServiceFabricBackup/
252 | *.rptproj.bak
253 |
254 | # SQL Server files
255 | *.mdf
256 | *.ldf
257 | *.ndf
258 |
259 | # Business Intelligence projects
260 | *.rdl.data
261 | *.bim.layout
262 | *.bim_*.settings
263 | *.rptproj.rsuser
264 | *- [Bb]ackup.rdl
265 | *- [Bb]ackup ([0-9]).rdl
266 | *- [Bb]ackup ([0-9][0-9]).rdl
267 |
268 | # Microsoft Fakes
269 | FakesAssemblies/
270 |
271 | # GhostDoc plugin setting file
272 | *.GhostDoc.xml
273 |
274 | # Node.js Tools for Visual Studio
275 | .ntvs_analysis.dat
276 | node_modules/
277 |
278 | # Visual Studio 6 build log
279 | *.plg
280 |
281 | # Visual Studio 6 workspace options file
282 | *.opt
283 |
284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
285 | *.vbw
286 |
287 | # Visual Studio LightSwitch build output
288 | **/*.HTMLClient/GeneratedArtifacts
289 | **/*.DesktopClient/GeneratedArtifacts
290 | **/*.DesktopClient/ModelManifest.xml
291 | **/*.Server/GeneratedArtifacts
292 | **/*.Server/ModelManifest.xml
293 | _Pvt_Extensions
294 |
295 | # Paket dependency manager
296 | .paket/paket.exe
297 | paket-files/
298 |
299 | # FAKE - F# Make
300 | .fake/
301 |
302 | # CodeRush personal settings
303 | .cr/personal
304 |
305 | # Python Tools for Visual Studio (PTVS)
306 | __pycache__/
307 | *.pyc
308 |
309 | # Cake - Uncomment if you are using it
310 | # tools/**
311 | # !tools/packages.config
312 |
313 | # Tabs Studio
314 | *.tss
315 |
316 | # Telerik's JustMock configuration file
317 | *.jmconfig
318 |
319 | # BizTalk build output
320 | *.btp.cs
321 | *.btm.cs
322 | *.odx.cs
323 | *.xsd.cs
324 |
325 | # OpenCover UI analysis results
326 | OpenCover/
327 |
328 | # Azure Stream Analytics local run output
329 | ASALocalRun/
330 |
331 | # MSBuild Binary and Structured Log
332 | *.binlog
333 |
334 | # NVidia Nsight GPU debugger configuration file
335 | *.nvuser
336 |
337 | # MFractors (Xamarin productivity tool) working folder
338 | .mfractor/
339 |
340 | # Local History for Visual Studio
341 | .localhistory/
342 |
343 | # BeatPulse healthcheck temp database
344 | healthchecksdb
345 |
346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
347 | MigrationBackup/
348 |
349 | # Ionide (cross platform F# VS Code tools) working folder
350 | .ionide/
351 |
352 | # AppSettings files
353 | appsettings.*.json
354 |
--------------------------------------------------------------------------------
/CleanArchitecture.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.5.33414.496
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Domain", "src\Core.Domain\Core.Domain.csproj", "{5C317095-EA0B-4874-B9BE-7B97330272B6}"
7 | EndProject
8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Persistence", "src\Infrastructure.Persistence\Infrastructure.Persistence.csproj", "{147F6165-9465-4FB3-9CC8-FB1029122DF2}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Application", "src\Core.Application\Core.Application.csproj", "{F255EB58-F184-4D66-87CF-ADB84FE1ED70}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web.Razor", "src\Web.Razor\Web.Razor.csproj", "{E147552A-BACB-4FBA-A5AF-C0CB80DFA518}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Identity", "src\Infrastructure.Identity\Infrastructure.Identity.csproj", "{9EF5D86C-2ACB-4547-B3B3-C81C32F676B4}"
15 | EndProject
16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}"
17 | EndProject
18 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{856C0AA6-D18A-4507-807D-244B067E10A9}"
19 | EndProject
20 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core.Application.UnitTests", "tests\Core.Application.UnitTests\Core.Application.UnitTests.csproj", "{44CE3529-1865-45CF-B520-3588F34AAAC2}"
21 | EndProject
22 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Persistence.IntegrationTests", "tests\Infrastructure.Persistence.IntegrationTests\Infrastructure.Persistence.IntegrationTests.csproj", "{4BE95815-8DEC-4C7C-A334-F7AF77B01460}"
23 | EndProject
24 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Infrastructure.Shared", "src\Infrastructure.Shared\Infrastructure.Shared.csproj", "{767B03F8-130E-4774-8C3A-07A2D1272665}"
25 | EndProject
26 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EDFF7F32-36EF-452F-9B12-1BA598DFF239}"
27 | ProjectSection(SolutionItems) = preProject
28 | .gitignore = .gitignore
29 | README.md = README.md
30 | EndProjectSection
31 | EndProject
32 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web.Api", "src\Web.Api\Web.Api.csproj", "{E6B7F998-F565-4D05-B13E-99E4727C45DE}"
33 | EndProject
34 | Global
35 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
36 | Debug|Any CPU = Debug|Any CPU
37 | Release|Any CPU = Release|Any CPU
38 | EndGlobalSection
39 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
40 | {5C317095-EA0B-4874-B9BE-7B97330272B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41 | {5C317095-EA0B-4874-B9BE-7B97330272B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
42 | {5C317095-EA0B-4874-B9BE-7B97330272B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
43 | {5C317095-EA0B-4874-B9BE-7B97330272B6}.Release|Any CPU.Build.0 = Release|Any CPU
44 | {147F6165-9465-4FB3-9CC8-FB1029122DF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
45 | {147F6165-9465-4FB3-9CC8-FB1029122DF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
46 | {147F6165-9465-4FB3-9CC8-FB1029122DF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
47 | {147F6165-9465-4FB3-9CC8-FB1029122DF2}.Release|Any CPU.Build.0 = Release|Any CPU
48 | {F255EB58-F184-4D66-87CF-ADB84FE1ED70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
49 | {F255EB58-F184-4D66-87CF-ADB84FE1ED70}.Debug|Any CPU.Build.0 = Debug|Any CPU
50 | {F255EB58-F184-4D66-87CF-ADB84FE1ED70}.Release|Any CPU.ActiveCfg = Release|Any CPU
51 | {F255EB58-F184-4D66-87CF-ADB84FE1ED70}.Release|Any CPU.Build.0 = Release|Any CPU
52 | {E147552A-BACB-4FBA-A5AF-C0CB80DFA518}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
53 | {E147552A-BACB-4FBA-A5AF-C0CB80DFA518}.Debug|Any CPU.Build.0 = Debug|Any CPU
54 | {E147552A-BACB-4FBA-A5AF-C0CB80DFA518}.Release|Any CPU.ActiveCfg = Release|Any CPU
55 | {E147552A-BACB-4FBA-A5AF-C0CB80DFA518}.Release|Any CPU.Build.0 = Release|Any CPU
56 | {9EF5D86C-2ACB-4547-B3B3-C81C32F676B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
57 | {9EF5D86C-2ACB-4547-B3B3-C81C32F676B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
58 | {9EF5D86C-2ACB-4547-B3B3-C81C32F676B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
59 | {9EF5D86C-2ACB-4547-B3B3-C81C32F676B4}.Release|Any CPU.Build.0 = Release|Any CPU
60 | {44CE3529-1865-45CF-B520-3588F34AAAC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
61 | {44CE3529-1865-45CF-B520-3588F34AAAC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
62 | {44CE3529-1865-45CF-B520-3588F34AAAC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
63 | {44CE3529-1865-45CF-B520-3588F34AAAC2}.Release|Any CPU.Build.0 = Release|Any CPU
64 | {4BE95815-8DEC-4C7C-A334-F7AF77B01460}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
65 | {4BE95815-8DEC-4C7C-A334-F7AF77B01460}.Debug|Any CPU.Build.0 = Debug|Any CPU
66 | {4BE95815-8DEC-4C7C-A334-F7AF77B01460}.Release|Any CPU.ActiveCfg = Release|Any CPU
67 | {4BE95815-8DEC-4C7C-A334-F7AF77B01460}.Release|Any CPU.Build.0 = Release|Any CPU
68 | {767B03F8-130E-4774-8C3A-07A2D1272665}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
69 | {767B03F8-130E-4774-8C3A-07A2D1272665}.Debug|Any CPU.Build.0 = Debug|Any CPU
70 | {767B03F8-130E-4774-8C3A-07A2D1272665}.Release|Any CPU.ActiveCfg = Release|Any CPU
71 | {767B03F8-130E-4774-8C3A-07A2D1272665}.Release|Any CPU.Build.0 = Release|Any CPU
72 | {E6B7F998-F565-4D05-B13E-99E4727C45DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
73 | {E6B7F998-F565-4D05-B13E-99E4727C45DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
74 | {E6B7F998-F565-4D05-B13E-99E4727C45DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
75 | {E6B7F998-F565-4D05-B13E-99E4727C45DE}.Release|Any CPU.Build.0 = Release|Any CPU
76 | EndGlobalSection
77 | GlobalSection(SolutionProperties) = preSolution
78 | HideSolutionNode = FALSE
79 | EndGlobalSection
80 | GlobalSection(NestedProjects) = preSolution
81 | {5C317095-EA0B-4874-B9BE-7B97330272B6} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
82 | {147F6165-9465-4FB3-9CC8-FB1029122DF2} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
83 | {F255EB58-F184-4D66-87CF-ADB84FE1ED70} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
84 | {E147552A-BACB-4FBA-A5AF-C0CB80DFA518} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
85 | {9EF5D86C-2ACB-4547-B3B3-C81C32F676B4} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
86 | {44CE3529-1865-45CF-B520-3588F34AAAC2} = {856C0AA6-D18A-4507-807D-244B067E10A9}
87 | {4BE95815-8DEC-4C7C-A334-F7AF77B01460} = {856C0AA6-D18A-4507-807D-244B067E10A9}
88 | {767B03F8-130E-4774-8C3A-07A2D1272665} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
89 | {E6B7F998-F565-4D05-B13E-99E4727C45DE} = {E74BD3FC-9DF4-4A3F-AF85-EBF1E2A56D22}
90 | EndGlobalSection
91 | GlobalSection(ExtensibilityGlobals) = postSolution
92 | SolutionGuid = {72C21E00-7F24-463D-A43B-4F72E4A72BFC}
93 | EndGlobalSection
94 | EndGlobal
95 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ASP.NET Core Identity in a Clean Architecture
2 |
3 | ## Goal
4 | This solution provides a starting point to build any type of client (Razor pages, Web API, Angular, etc.) to work with ASP.NET Core Identity using .NET 7 and PostgreSQL, based on Clean Architecture and repository design pattern.
5 |
6 | Clean Architecture is promoted by Microsoft on their .NET application architecture guide page. The e-book written by Steve "ardalis" Smith ([@ardalis](https://github.com/ardalis)) is very well written and explains in detail the benefits of using Clean Architecture. For more details, please see [Architect Modern Web Applications with ASP.NET Core and Azure](https://docs.microsoft.com/en-us/dotnet/architecture/modern-web-apps-azure/).
7 |
8 | For a live application forked from this repository see [Budgetbase repository](https://github.com/iamdlm/budgetbase) or visit the [website](https://budgetbase.app/).
9 | ## Configuring the sample to use PostgreSQL
10 | 1. Ensure your connection string in appsettings.json point to a local PostgreSQL instance.
11 | 2. Ensure the tool EF was already installed. You can find some help [here](https://docs.microsoft.com/ef/core/miscellaneous/cli/dotnet).
12 | ```
13 | dotnet tool update --global dotnet-ef
14 | ```
15 | 3. Open a command prompt in the `src` folder and execute the following commands:
16 | ```
17 | dotnet ef database update --context AppDbContext --project Infrastructure.Persistence --startup-project Web.Razor --connection "YOUR_CONNECTION_STRING_HERE"
18 | dotnet ef database update --context AppIdentityDbContext --project Infrastructure.Identity --startup-project Web.Razor --connection "YOUR_CONNECTION_STRING_HERE"
19 | ```
20 | 4. Run the application.
21 | Note: If you need to create migrations, you can execute these commands from the `src` folder:
22 | ```
23 | dotnet restore
24 | dotnet tool restore
25 | dotnet ef migrations add InitialModel --context AppDbContext --project Infrastructure.Persistence --startup-project Web.Razor --output-dir Persistence\Migrations
26 | dotnet ef migrations add InitialModel --context AppIdentityDbContext --project Infrastructure.Identity --startup-project Web.Razor --output-dir Identity\Migrations
27 | ```
28 |
29 | ## Getting Started - Razor pages
30 | _Under development_
31 |
32 | ## Getting Started - Web API
33 | _Under development_
34 |
35 | ## Getting Started - Angular
36 | _Under development_
37 |
38 | ## Technologies used
39 | - ASP.NET Core 7
40 | - Entity Framework Core 7
41 | - Serilog
42 | - AutoMapper
43 | - xUnit
44 | - Razor Components
45 | - ASP.NET Core Web API
46 | - Angular
47 |
48 | ## Features supported
49 | _Under development_
50 |
51 |
52 |
--------------------------------------------------------------------------------
/src/Core.Application/Core.Application.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/ApplicationUserDto.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Application.DTOs
2 | {
3 | public class ApplicationUserDto
4 | {
5 | public string Id { get; set; }
6 | public string UserName { get; set; }
7 | public string Email { get; set; }
8 | public bool EmailConfirmed { get; set; }
9 | public string PhoneNumber { get; set; }
10 | public bool PhoneNumberConfirmed { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/AuthenticationResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class AuthenticationResponse
6 | {
7 | [JsonPropertyName("succeeded")]
8 | public bool Succeeded { get; set; }
9 |
10 | [JsonPropertyName("errors")]
11 | public Dictionary Errors { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/EmailConfirmationRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class EmailConfirmationRequest
6 | {
7 | [JsonPropertyName("userId")]
8 | public string UserId { get; set; }
9 |
10 | [JsonPropertyName("token")]
11 | public string Token { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/EmailConfirmationResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class TokenResponse : AuthenticationResponse
6 | {
7 | [JsonPropertyName("userId")]
8 | public string UserId { get; set; }
9 |
10 | [JsonPropertyName("token")]
11 | public string Token { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/ResetPasswordRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class ResetPasswordRequest
6 | {
7 | [JsonPropertyName("userEmail")]
8 | public string UserEmail { get; set; }
9 |
10 | [JsonPropertyName("token")]
11 | public string Token { get; set; }
12 |
13 | [JsonPropertyName("newPassword")]
14 | public string NewPassword { get; set; }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/SignInRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class SignInRequest
6 | {
7 | [JsonPropertyName("email")]
8 | public string Email { get; set; }
9 |
10 | [JsonPropertyName("password")]
11 | public string Password { get; set; }
12 |
13 | [JsonPropertyName("rememberMe")]
14 | public bool RememberMe { get; set; }
15 | }
16 | }
--------------------------------------------------------------------------------
/src/Core.Application/DTOs/SignUpRequest.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Core.Application.DTOs
4 | {
5 | public class SignUpRequest
6 | {
7 | [JsonPropertyName("email")]
8 | public string Email { get; set; }
9 |
10 | [JsonPropertyName("password")]
11 | public string Password { get; set; }
12 | }
13 | }
--------------------------------------------------------------------------------
/src/Core.Application/Extensions/ServiceCollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.Mapper;
2 | using AutoMapper;
3 | using Microsoft.Extensions.DependencyInjection;
4 |
5 | namespace Core.Application.Extensions
6 | {
7 | public static class ServiceCollectionExtensions
8 | {
9 | public static void AddApplicationMappingProfile(this IServiceCollection services)
10 | {
11 | MapperConfiguration mappingConfig = new(mc =>
12 | {
13 | mc.AddProfile(new ApplicationProfile());
14 | });
15 |
16 | services.AddSingleton(mappingConfig.CreateMapper());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Application/ICurrentUserService.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Application.Interfaces.Application
2 | {
3 | public interface ICurrentUserService
4 | {
5 | string? UserId { get; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Application/IDateTimeService.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace Core.Application.Interfaces.Application
8 | {
9 | public interface IDateTimeService
10 | {
11 | DateTime Now { get; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Identity/IAuthService.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.DTOs;
2 | using System.Security.Claims;
3 |
4 | namespace Core.Application.Interfaces.Identity
5 | {
6 | public interface IAuthService
7 | {
8 | Task SignInAsync(SignInRequest signInRequest);
9 | Task SignOutAsync();
10 | Task SignUpAsync(SignUpRequest signUpRequest);
11 | Task ChangePasswordAsync(ClaimsPrincipal user, string currentPassword, string newPassword);
12 | Task ResetPasswordAsync(ResetPasswordRequest resetPasswordRequest);
13 | Task GeneratePasswordResetTokenAsync(string email);
14 | Task GetCurrentUserAsync(ClaimsPrincipal user);
15 | Task GenerateEmailConfirmationAsync(ClaimsPrincipal user);
16 | Task GenerateEmailChangeAsync(ClaimsPrincipal user, string newEmail);
17 | Task ConfirmEmailAsync(EmailConfirmationRequest emailConfirmationRequest);
18 | Task RefreshSignInAsync(ClaimsPrincipal user);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Identity/IUserService.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.DTOs;
2 | using System.Security.Claims;
3 |
4 | namespace Core.Application.Interfaces.Identity
5 | {
6 | public interface IUserService
7 | {
8 | Task FindByIdAsync(string userId);
9 | Task FindByEmailAsync(string email);
10 | Task GetUserIdAsync(ClaimsPrincipal principal);
11 | Task GetEmailAsync(ClaimsPrincipal principal);
12 | Task GetUserNameAsync(ClaimsPrincipal principal);
13 | Task GetPhoneNumberAsync(ClaimsPrincipal principal);
14 | Task ChangeEmailAsync(ClaimsPrincipal principal, string email, string code);
15 | Task ChangePasswordAsync(ClaimsPrincipal principal, string oldPassword, string newPassword);
16 | Task IsEmailConfirmedAsync(string email);
17 | Task HasPasswordAsync(ClaimsPrincipal principal);
18 | Task SetPhoneNumberAsync(ClaimsPrincipal principal, string phoneNumber);
19 | Task AddPasswordAsync(ClaimsPrincipal principal, string newPassword);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Persistence/IIdentifiable.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Application.Interfaces.Persistence
2 | {
3 | public interface IIdentifiable
4 | {
5 | Guid Id { get; set; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Persistence/IRepositoryBase.cs:
--------------------------------------------------------------------------------
1 | using System.Linq.Expressions;
2 |
3 | namespace Core.Application.Interfaces.Persistence
4 | {
5 | public interface IRepositoryBase
6 | {
7 | Task FirstOrDefaultAsync(Expression> filter, Func, IOrderedQueryable> orderBy, params Expression>[] includes);
8 |
9 | Task> GetAllAsync();
10 |
11 | Task> GetAllAsync(Expression> filter, Func, IOrderedQueryable> orderBy, params Expression>[] includes);
12 |
13 | Task> GetWhereAsync(Expression> filter);
14 |
15 | Task GetByIdAsync(Guid id);
16 |
17 | void Add(T entity);
18 |
19 | void Update(T entity);
20 |
21 | void Delete(T entity);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Persistence/IServiceBase.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Application.Interfaces.Persistence
2 | {
3 | public interface IServiceBase where TDto : class, IIdentifiable
4 | {
5 | Task GetByIdAsync(Guid id);
6 | Task> GetAllAsync();
7 | Task CreateAsync(TDto dto);
8 | Task UpdateAsync(TDto dto);
9 | Task DeleteAsync(Guid id);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Core.Application/Interfaces/Persistence/IUnitOfWork.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Application.Interfaces.Persistence
2 | {
3 | public interface IUnitOfWork : IDisposable
4 | {
5 | IRepositoryBase GetRepository() where T : class;
6 | Task CompleteAsync();
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Core.Application/Mapper/ApplicationProfile.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 |
3 | namespace Core.Application.Mapper
4 | {
5 | public class ApplicationProfile : Profile
6 | {
7 | public ApplicationProfile()
8 | {
9 |
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Core.Domain/Core.Domain.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/Core.Domain/Entities/AuditableEntityBase.cs:
--------------------------------------------------------------------------------
1 | namespace Core.Domain.Entities
2 | {
3 | public abstract class AuditableEntityBase : EntityBase
4 | {
5 | public DateTime CreatedOn { get; set; }
6 |
7 | public string CreatedBy { get; set; }
8 |
9 | public DateTime ModifiedOn { get; set; }
10 |
11 | public string ModifiedBy { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Core.Domain/Entities/EntityBase.cs:
--------------------------------------------------------------------------------
1 | using System.ComponentModel.DataAnnotations;
2 |
3 | namespace Core.Domain.Entities
4 | {
5 | public abstract class EntityBase
6 | {
7 | [Key]
8 | public Guid Id { get; set; }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Data/AppIdentityDbContext.cs:
--------------------------------------------------------------------------------
1 | using Infrastructure.Identity.Models;
2 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
3 | using Microsoft.EntityFrameworkCore;
4 |
5 | namespace Infrastructure.Identity.Data
6 | {
7 | public class AppIdentityDbContext : IdentityDbContext
8 | {
9 | public AppIdentityDbContext(DbContextOptions options) : base(options)
10 | {
11 | }
12 |
13 | protected override void OnModelCreating(ModelBuilder builder)
14 | {
15 | base.OnModelCreating(builder);
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Extensions/IdentityResultExtensions.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.DTOs;
2 | using Microsoft.AspNetCore.Identity;
3 |
4 | namespace Infrastructure.Identity.Helpers
5 | {
6 | public static class IdentityResultExtensions
7 | {
8 | public static AuthenticationResponse ToAuthenticationResult(this IdentityResult result)
9 | {
10 | return new AuthenticationResponse()
11 | {
12 | Succeeded = result.Succeeded,
13 | Errors = result.Errors.ToDictionary(e => e.Code, e => e.Description)
14 | };
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Extensions/ServiceCollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Infrastructure.Identity.Models;
2 | using Microsoft.AspNetCore.Identity;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.Extensions.Configuration;
5 | using Microsoft.Extensions.DependencyInjection;
6 | using Core.Application.Interfaces.Identity;
7 | using Infrastructure.Identity.Services;
8 | using AutoMapper;
9 | using Infrastructure.Identity.Mapper;
10 | using Infrastructure.Identity.Data;
11 |
12 | namespace Infrastructure.Identity.Extensions
13 | {
14 | public static class ServiceCollectionExtensions
15 | {
16 | public static void AddIdentityDbContext(this IServiceCollection services, IConfiguration configuration)
17 | {
18 | services.AddDbContext(options =>
19 | options.UseNpgsql(
20 | configuration.GetConnectionString("DefaultConnection"),
21 | b => b.MigrationsAssembly(typeof(AppIdentityDbContext).Assembly.FullName)));
22 | }
23 |
24 | public static void AddIdentityAuth(this IServiceCollection services)
25 | {
26 | services.AddIdentity()
27 | .AddEntityFrameworkStores()
28 | .AddDefaultTokenProviders();
29 | }
30 |
31 | public static void AddInfrastructureIdentityServices(this IServiceCollection services)
32 | {
33 | services.AddScoped();
34 | services.AddScoped();
35 | }
36 |
37 | public static void AddInfrastructureIdentityMappingProfile(this IServiceCollection services)
38 | {
39 | MapperConfiguration mappingConfig = new(mc =>
40 | {
41 | mc.AddProfile(new InfrastructureIdentityProfile());
42 | });
43 |
44 | services.AddSingleton(mappingConfig.CreateMapper());
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Infrastructure.Identity.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Mapper/InfrastructureProfile.cs:
--------------------------------------------------------------------------------
1 | using AutoMapper;
2 | using Core.Application.DTOs;
3 | using Infrastructure.Identity.Models;
4 |
5 | namespace Infrastructure.Identity.Mapper
6 | {
7 | public class InfrastructureIdentityProfile : Profile
8 | {
9 | public InfrastructureIdentityProfile()
10 | {
11 | CreateMap()
12 | .ReverseMap();
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Migrations/20230408115648_InitialModel.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using System;
3 | using Infrastructure.Identity.Data;
4 | using Microsoft.EntityFrameworkCore;
5 | using Microsoft.EntityFrameworkCore.Infrastructure;
6 | using Microsoft.EntityFrameworkCore.Migrations;
7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
8 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
9 |
10 | #nullable disable
11 |
12 | namespace Infrastructure.Identity.Migrations
13 | {
14 | [DbContext(typeof(AppIdentityDbContext))]
15 | [Migration("20230408115648_InitialModel")]
16 | partial class InitialModel
17 | {
18 | ///
19 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
20 | {
21 | #pragma warning disable 612, 618
22 | modelBuilder
23 | .HasAnnotation("ProductVersion", "7.0.4")
24 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
25 |
26 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
27 |
28 | modelBuilder.Entity("Infrastructure.Identity.ApplicationUser", b =>
29 | {
30 | b.Property("Id")
31 | .HasColumnType("text");
32 |
33 | b.Property("AccessFailedCount")
34 | .HasColumnType("integer");
35 |
36 | b.Property("Birthdate")
37 | .HasColumnType("timestamp with time zone");
38 |
39 | b.Property("ConcurrencyStamp")
40 | .IsConcurrencyToken()
41 | .HasColumnType("text");
42 |
43 | b.Property("Email")
44 | .HasMaxLength(256)
45 | .HasColumnType("character varying(256)");
46 |
47 | b.Property("EmailConfirmed")
48 | .HasColumnType("boolean");
49 |
50 | b.Property("FirstName")
51 | .HasColumnType("text");
52 |
53 | b.Property("LastName")
54 | .HasColumnType("text");
55 |
56 | b.Property("LockoutEnabled")
57 | .HasColumnType("boolean");
58 |
59 | b.Property("LockoutEnd")
60 | .HasColumnType("timestamp with time zone");
61 |
62 | b.Property("NormalizedEmail")
63 | .HasMaxLength(256)
64 | .HasColumnType("character varying(256)");
65 |
66 | b.Property("NormalizedUserName")
67 | .HasMaxLength(256)
68 | .HasColumnType("character varying(256)");
69 |
70 | b.Property("PasswordHash")
71 | .HasColumnType("text");
72 |
73 | b.Property("PhoneNumber")
74 | .HasColumnType("text");
75 |
76 | b.Property("PhoneNumberConfirmed")
77 | .HasColumnType("boolean");
78 |
79 | b.Property("SecurityStamp")
80 | .HasColumnType("text");
81 |
82 | b.Property("TwoFactorEnabled")
83 | .HasColumnType("boolean");
84 |
85 | b.Property("UserName")
86 | .HasMaxLength(256)
87 | .HasColumnType("character varying(256)");
88 |
89 | b.HasKey("Id");
90 |
91 | b.HasIndex("NormalizedEmail")
92 | .HasDatabaseName("EmailIndex");
93 |
94 | b.HasIndex("NormalizedUserName")
95 | .IsUnique()
96 | .HasDatabaseName("UserNameIndex");
97 |
98 | b.ToTable("AspNetUsers", (string)null);
99 | });
100 |
101 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
102 | {
103 | b.Property("Id")
104 | .HasColumnType("text");
105 |
106 | b.Property("ConcurrencyStamp")
107 | .IsConcurrencyToken()
108 | .HasColumnType("text");
109 |
110 | b.Property("Name")
111 | .HasMaxLength(256)
112 | .HasColumnType("character varying(256)");
113 |
114 | b.Property("NormalizedName")
115 | .HasMaxLength(256)
116 | .HasColumnType("character varying(256)");
117 |
118 | b.HasKey("Id");
119 |
120 | b.HasIndex("NormalizedName")
121 | .IsUnique()
122 | .HasDatabaseName("RoleNameIndex");
123 |
124 | b.ToTable("AspNetRoles", (string)null);
125 | });
126 |
127 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
128 | {
129 | b.Property("Id")
130 | .ValueGeneratedOnAdd()
131 | .HasColumnType("integer");
132 |
133 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
134 |
135 | b.Property("ClaimType")
136 | .HasColumnType("text");
137 |
138 | b.Property("ClaimValue")
139 | .HasColumnType("text");
140 |
141 | b.Property("RoleId")
142 | .IsRequired()
143 | .HasColumnType("text");
144 |
145 | b.HasKey("Id");
146 |
147 | b.HasIndex("RoleId");
148 |
149 | b.ToTable("AspNetRoleClaims", (string)null);
150 | });
151 |
152 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
153 | {
154 | b.Property("Id")
155 | .ValueGeneratedOnAdd()
156 | .HasColumnType("integer");
157 |
158 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
159 |
160 | b.Property("ClaimType")
161 | .HasColumnType("text");
162 |
163 | b.Property("ClaimValue")
164 | .HasColumnType("text");
165 |
166 | b.Property("UserId")
167 | .IsRequired()
168 | .HasColumnType("text");
169 |
170 | b.HasKey("Id");
171 |
172 | b.HasIndex("UserId");
173 |
174 | b.ToTable("AspNetUserClaims", (string)null);
175 | });
176 |
177 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
178 | {
179 | b.Property("LoginProvider")
180 | .HasColumnType("text");
181 |
182 | b.Property("ProviderKey")
183 | .HasColumnType("text");
184 |
185 | b.Property("ProviderDisplayName")
186 | .HasColumnType("text");
187 |
188 | b.Property("UserId")
189 | .IsRequired()
190 | .HasColumnType("text");
191 |
192 | b.HasKey("LoginProvider", "ProviderKey");
193 |
194 | b.HasIndex("UserId");
195 |
196 | b.ToTable("AspNetUserLogins", (string)null);
197 | });
198 |
199 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
200 | {
201 | b.Property("UserId")
202 | .HasColumnType("text");
203 |
204 | b.Property("RoleId")
205 | .HasColumnType("text");
206 |
207 | b.HasKey("UserId", "RoleId");
208 |
209 | b.HasIndex("RoleId");
210 |
211 | b.ToTable("AspNetUserRoles", (string)null);
212 | });
213 |
214 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
215 | {
216 | b.Property("UserId")
217 | .HasColumnType("text");
218 |
219 | b.Property("LoginProvider")
220 | .HasColumnType("text");
221 |
222 | b.Property("Name")
223 | .HasColumnType("text");
224 |
225 | b.Property("Value")
226 | .HasColumnType("text");
227 |
228 | b.HasKey("UserId", "LoginProvider", "Name");
229 |
230 | b.ToTable("AspNetUserTokens", (string)null);
231 | });
232 |
233 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
234 | {
235 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
236 | .WithMany()
237 | .HasForeignKey("RoleId")
238 | .OnDelete(DeleteBehavior.Cascade)
239 | .IsRequired();
240 | });
241 |
242 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
243 | {
244 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
245 | .WithMany()
246 | .HasForeignKey("UserId")
247 | .OnDelete(DeleteBehavior.Cascade)
248 | .IsRequired();
249 | });
250 |
251 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
252 | {
253 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
254 | .WithMany()
255 | .HasForeignKey("UserId")
256 | .OnDelete(DeleteBehavior.Cascade)
257 | .IsRequired();
258 | });
259 |
260 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
261 | {
262 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
263 | .WithMany()
264 | .HasForeignKey("RoleId")
265 | .OnDelete(DeleteBehavior.Cascade)
266 | .IsRequired();
267 |
268 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
269 | .WithMany()
270 | .HasForeignKey("UserId")
271 | .OnDelete(DeleteBehavior.Cascade)
272 | .IsRequired();
273 | });
274 |
275 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
276 | {
277 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
278 | .WithMany()
279 | .HasForeignKey("UserId")
280 | .OnDelete(DeleteBehavior.Cascade)
281 | .IsRequired();
282 | });
283 | #pragma warning restore 612, 618
284 | }
285 | }
286 | }
287 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Migrations/20230408115648_InitialModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
3 |
4 | #nullable disable
5 |
6 | namespace Infrastructure.Identity.Migrations
7 | {
8 | ///
9 | public partial class InitialModel : Migration
10 | {
11 | ///
12 | protected override void Up(MigrationBuilder migrationBuilder)
13 | {
14 | migrationBuilder.CreateTable(
15 | name: "AspNetRoles",
16 | columns: table => new
17 | {
18 | Id = table.Column(type: "text", nullable: false),
19 | Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
20 | NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
21 | ConcurrencyStamp = table.Column(type: "text", nullable: true)
22 | },
23 | constraints: table =>
24 | {
25 | table.PrimaryKey("PK_AspNetRoles", x => x.Id);
26 | });
27 |
28 | migrationBuilder.CreateTable(
29 | name: "AspNetUsers",
30 | columns: table => new
31 | {
32 | Id = table.Column(type: "text", nullable: false),
33 | FirstName = table.Column(type: "text", nullable: true),
34 | LastName = table.Column(type: "text", nullable: true),
35 | Birthdate = table.Column(type: "timestamp with time zone", nullable: true),
36 | UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
37 | NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
38 | Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
39 | NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true),
40 | EmailConfirmed = table.Column(type: "boolean", nullable: false),
41 | PasswordHash = table.Column(type: "text", nullable: true),
42 | SecurityStamp = table.Column(type: "text", nullable: true),
43 | ConcurrencyStamp = table.Column(type: "text", nullable: true),
44 | PhoneNumber = table.Column(type: "text", nullable: true),
45 | PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false),
46 | TwoFactorEnabled = table.Column(type: "boolean", nullable: false),
47 | LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true),
48 | LockoutEnabled = table.Column(type: "boolean", nullable: false),
49 | AccessFailedCount = table.Column(type: "integer", nullable: false)
50 | },
51 | constraints: table =>
52 | {
53 | table.PrimaryKey("PK_AspNetUsers", x => x.Id);
54 | });
55 |
56 | migrationBuilder.CreateTable(
57 | name: "AspNetRoleClaims",
58 | columns: table => new
59 | {
60 | Id = table.Column(type: "integer", nullable: false)
61 | .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
62 | RoleId = table.Column(type: "text", nullable: false),
63 | ClaimType = table.Column(type: "text", nullable: true),
64 | ClaimValue = table.Column(type: "text", nullable: true)
65 | },
66 | constraints: table =>
67 | {
68 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id);
69 | table.ForeignKey(
70 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId",
71 | column: x => x.RoleId,
72 | principalTable: "AspNetRoles",
73 | principalColumn: "Id",
74 | onDelete: ReferentialAction.Cascade);
75 | });
76 |
77 | migrationBuilder.CreateTable(
78 | name: "AspNetUserClaims",
79 | columns: table => new
80 | {
81 | Id = table.Column(type: "integer", nullable: false)
82 | .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
83 | UserId = table.Column(type: "text", nullable: false),
84 | ClaimType = table.Column(type: "text", nullable: true),
85 | ClaimValue = table.Column(type: "text", nullable: true)
86 | },
87 | constraints: table =>
88 | {
89 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id);
90 | table.ForeignKey(
91 | name: "FK_AspNetUserClaims_AspNetUsers_UserId",
92 | column: x => x.UserId,
93 | principalTable: "AspNetUsers",
94 | principalColumn: "Id",
95 | onDelete: ReferentialAction.Cascade);
96 | });
97 |
98 | migrationBuilder.CreateTable(
99 | name: "AspNetUserLogins",
100 | columns: table => new
101 | {
102 | LoginProvider = table.Column(type: "text", nullable: false),
103 | ProviderKey = table.Column(type: "text", nullable: false),
104 | ProviderDisplayName = table.Column(type: "text", nullable: true),
105 | UserId = table.Column(type: "text", nullable: false)
106 | },
107 | constraints: table =>
108 | {
109 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey });
110 | table.ForeignKey(
111 | name: "FK_AspNetUserLogins_AspNetUsers_UserId",
112 | column: x => x.UserId,
113 | principalTable: "AspNetUsers",
114 | principalColumn: "Id",
115 | onDelete: ReferentialAction.Cascade);
116 | });
117 |
118 | migrationBuilder.CreateTable(
119 | name: "AspNetUserRoles",
120 | columns: table => new
121 | {
122 | UserId = table.Column(type: "text", nullable: false),
123 | RoleId = table.Column(type: "text", nullable: false)
124 | },
125 | constraints: table =>
126 | {
127 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId });
128 | table.ForeignKey(
129 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId",
130 | column: x => x.RoleId,
131 | principalTable: "AspNetRoles",
132 | principalColumn: "Id",
133 | onDelete: ReferentialAction.Cascade);
134 | table.ForeignKey(
135 | name: "FK_AspNetUserRoles_AspNetUsers_UserId",
136 | column: x => x.UserId,
137 | principalTable: "AspNetUsers",
138 | principalColumn: "Id",
139 | onDelete: ReferentialAction.Cascade);
140 | });
141 |
142 | migrationBuilder.CreateTable(
143 | name: "AspNetUserTokens",
144 | columns: table => new
145 | {
146 | UserId = table.Column(type: "text", nullable: false),
147 | LoginProvider = table.Column(type: "text", nullable: false),
148 | Name = table.Column(type: "text", nullable: false),
149 | Value = table.Column(type: "text", nullable: true)
150 | },
151 | constraints: table =>
152 | {
153 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name });
154 | table.ForeignKey(
155 | name: "FK_AspNetUserTokens_AspNetUsers_UserId",
156 | column: x => x.UserId,
157 | principalTable: "AspNetUsers",
158 | principalColumn: "Id",
159 | onDelete: ReferentialAction.Cascade);
160 | });
161 |
162 | migrationBuilder.CreateIndex(
163 | name: "IX_AspNetRoleClaims_RoleId",
164 | table: "AspNetRoleClaims",
165 | column: "RoleId");
166 |
167 | migrationBuilder.CreateIndex(
168 | name: "RoleNameIndex",
169 | table: "AspNetRoles",
170 | column: "NormalizedName",
171 | unique: true);
172 |
173 | migrationBuilder.CreateIndex(
174 | name: "IX_AspNetUserClaims_UserId",
175 | table: "AspNetUserClaims",
176 | column: "UserId");
177 |
178 | migrationBuilder.CreateIndex(
179 | name: "IX_AspNetUserLogins_UserId",
180 | table: "AspNetUserLogins",
181 | column: "UserId");
182 |
183 | migrationBuilder.CreateIndex(
184 | name: "IX_AspNetUserRoles_RoleId",
185 | table: "AspNetUserRoles",
186 | column: "RoleId");
187 |
188 | migrationBuilder.CreateIndex(
189 | name: "EmailIndex",
190 | table: "AspNetUsers",
191 | column: "NormalizedEmail");
192 |
193 | migrationBuilder.CreateIndex(
194 | name: "UserNameIndex",
195 | table: "AspNetUsers",
196 | column: "NormalizedUserName",
197 | unique: true);
198 | }
199 |
200 | ///
201 | protected override void Down(MigrationBuilder migrationBuilder)
202 | {
203 | migrationBuilder.DropTable(
204 | name: "AspNetRoleClaims");
205 |
206 | migrationBuilder.DropTable(
207 | name: "AspNetUserClaims");
208 |
209 | migrationBuilder.DropTable(
210 | name: "AspNetUserLogins");
211 |
212 | migrationBuilder.DropTable(
213 | name: "AspNetUserRoles");
214 |
215 | migrationBuilder.DropTable(
216 | name: "AspNetUserTokens");
217 |
218 | migrationBuilder.DropTable(
219 | name: "AspNetRoles");
220 |
221 | migrationBuilder.DropTable(
222 | name: "AspNetUsers");
223 | }
224 | }
225 | }
226 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Migrations/AppIdentityDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using Infrastructure.Identity.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 |
6 | #nullable disable
7 |
8 | namespace Infrastructure.Identity.Migrations
9 | {
10 | [DbContext(typeof(AppIdentityDbContext))]
11 | partial class AppIdentityDbContextModelSnapshot : ModelSnapshot
12 | {
13 | protected override void BuildModel(ModelBuilder modelBuilder)
14 | {
15 | #pragma warning disable 612, 618
16 | modelBuilder
17 | .HasAnnotation("ProductVersion", "7.0.4")
18 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
19 |
20 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
21 |
22 | modelBuilder.Entity("Infrastructure.Identity.ApplicationUser", b =>
23 | {
24 | b.Property("Id")
25 | .HasColumnType("text");
26 |
27 | b.Property("AccessFailedCount")
28 | .HasColumnType("integer");
29 |
30 | b.Property("Birthdate")
31 | .HasColumnType("timestamp with time zone");
32 |
33 | b.Property("ConcurrencyStamp")
34 | .IsConcurrencyToken()
35 | .HasColumnType("text");
36 |
37 | b.Property("Email")
38 | .HasMaxLength(256)
39 | .HasColumnType("character varying(256)");
40 |
41 | b.Property("EmailConfirmed")
42 | .HasColumnType("boolean");
43 |
44 | b.Property("FirstName")
45 | .HasColumnType("text");
46 |
47 | b.Property("LastName")
48 | .HasColumnType("text");
49 |
50 | b.Property("LockoutEnabled")
51 | .HasColumnType("boolean");
52 |
53 | b.Property("LockoutEnd")
54 | .HasColumnType("timestamp with time zone");
55 |
56 | b.Property("NormalizedEmail")
57 | .HasMaxLength(256)
58 | .HasColumnType("character varying(256)");
59 |
60 | b.Property("NormalizedUserName")
61 | .HasMaxLength(256)
62 | .HasColumnType("character varying(256)");
63 |
64 | b.Property("PasswordHash")
65 | .HasColumnType("text");
66 |
67 | b.Property("PhoneNumber")
68 | .HasColumnType("text");
69 |
70 | b.Property("PhoneNumberConfirmed")
71 | .HasColumnType("boolean");
72 |
73 | b.Property("SecurityStamp")
74 | .HasColumnType("text");
75 |
76 | b.Property("TwoFactorEnabled")
77 | .HasColumnType("boolean");
78 |
79 | b.Property("UserName")
80 | .HasMaxLength(256)
81 | .HasColumnType("character varying(256)");
82 |
83 | b.HasKey("Id");
84 |
85 | b.HasIndex("NormalizedEmail")
86 | .HasDatabaseName("EmailIndex");
87 |
88 | b.HasIndex("NormalizedUserName")
89 | .IsUnique()
90 | .HasDatabaseName("UserNameIndex");
91 |
92 | b.ToTable("AspNetUsers", (string)null);
93 | });
94 |
95 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
96 | {
97 | b.Property("Id")
98 | .HasColumnType("text");
99 |
100 | b.Property("ConcurrencyStamp")
101 | .IsConcurrencyToken()
102 | .HasColumnType("text");
103 |
104 | b.Property("Name")
105 | .HasMaxLength(256)
106 | .HasColumnType("character varying(256)");
107 |
108 | b.Property("NormalizedName")
109 | .HasMaxLength(256)
110 | .HasColumnType("character varying(256)");
111 |
112 | b.HasKey("Id");
113 |
114 | b.HasIndex("NormalizedName")
115 | .IsUnique()
116 | .HasDatabaseName("RoleNameIndex");
117 |
118 | b.ToTable("AspNetRoles", (string)null);
119 | });
120 |
121 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
122 | {
123 | b.Property("Id")
124 | .ValueGeneratedOnAdd()
125 | .HasColumnType("integer");
126 |
127 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
128 |
129 | b.Property("ClaimType")
130 | .HasColumnType("text");
131 |
132 | b.Property("ClaimValue")
133 | .HasColumnType("text");
134 |
135 | b.Property("RoleId")
136 | .IsRequired()
137 | .HasColumnType("text");
138 |
139 | b.HasKey("Id");
140 |
141 | b.HasIndex("RoleId");
142 |
143 | b.ToTable("AspNetRoleClaims", (string)null);
144 | });
145 |
146 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
147 | {
148 | b.Property("Id")
149 | .ValueGeneratedOnAdd()
150 | .HasColumnType("integer");
151 |
152 | NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id"));
153 |
154 | b.Property("ClaimType")
155 | .HasColumnType("text");
156 |
157 | b.Property("ClaimValue")
158 | .HasColumnType("text");
159 |
160 | b.Property("UserId")
161 | .IsRequired()
162 | .HasColumnType("text");
163 |
164 | b.HasKey("Id");
165 |
166 | b.HasIndex("UserId");
167 |
168 | b.ToTable("AspNetUserClaims", (string)null);
169 | });
170 |
171 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
172 | {
173 | b.Property("LoginProvider")
174 | .HasColumnType("text");
175 |
176 | b.Property("ProviderKey")
177 | .HasColumnType("text");
178 |
179 | b.Property("ProviderDisplayName")
180 | .HasColumnType("text");
181 |
182 | b.Property("UserId")
183 | .IsRequired()
184 | .HasColumnType("text");
185 |
186 | b.HasKey("LoginProvider", "ProviderKey");
187 |
188 | b.HasIndex("UserId");
189 |
190 | b.ToTable("AspNetUserLogins", (string)null);
191 | });
192 |
193 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
194 | {
195 | b.Property("UserId")
196 | .HasColumnType("text");
197 |
198 | b.Property("RoleId")
199 | .HasColumnType("text");
200 |
201 | b.HasKey("UserId", "RoleId");
202 |
203 | b.HasIndex("RoleId");
204 |
205 | b.ToTable("AspNetUserRoles", (string)null);
206 | });
207 |
208 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
209 | {
210 | b.Property("UserId")
211 | .HasColumnType("text");
212 |
213 | b.Property("LoginProvider")
214 | .HasColumnType("text");
215 |
216 | b.Property("Name")
217 | .HasColumnType("text");
218 |
219 | b.Property("Value")
220 | .HasColumnType("text");
221 |
222 | b.HasKey("UserId", "LoginProvider", "Name");
223 |
224 | b.ToTable("AspNetUserTokens", (string)null);
225 | });
226 |
227 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b =>
228 | {
229 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
230 | .WithMany()
231 | .HasForeignKey("RoleId")
232 | .OnDelete(DeleteBehavior.Cascade)
233 | .IsRequired();
234 | });
235 |
236 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b =>
237 | {
238 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
239 | .WithMany()
240 | .HasForeignKey("UserId")
241 | .OnDelete(DeleteBehavior.Cascade)
242 | .IsRequired();
243 | });
244 |
245 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b =>
246 | {
247 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
248 | .WithMany()
249 | .HasForeignKey("UserId")
250 | .OnDelete(DeleteBehavior.Cascade)
251 | .IsRequired();
252 | });
253 |
254 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b =>
255 | {
256 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
257 | .WithMany()
258 | .HasForeignKey("RoleId")
259 | .OnDelete(DeleteBehavior.Cascade)
260 | .IsRequired();
261 |
262 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
263 | .WithMany()
264 | .HasForeignKey("UserId")
265 | .OnDelete(DeleteBehavior.Cascade)
266 | .IsRequired();
267 | });
268 |
269 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b =>
270 | {
271 | b.HasOne("Infrastructure.Identity.ApplicationUser", null)
272 | .WithMany()
273 | .HasForeignKey("UserId")
274 | .OnDelete(DeleteBehavior.Cascade)
275 | .IsRequired();
276 | });
277 | #pragma warning restore 612, 618
278 | }
279 | }
280 | }
281 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Models/ApplicationUser.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.AspNetCore.Identity;
2 |
3 | namespace Infrastructure.Identity.Models
4 | {
5 | public class ApplicationUser : IdentityUser
6 | {
7 | public string? FirstName { get; set; }
8 | public string? LastName { get; set; }
9 | public DateTime? Birthdate { get; set; }
10 | }
11 | }
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Services/AuthService.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.DTOs;
2 | using Microsoft.AspNetCore.Identity;
3 | using System.Security.Claims;
4 | using AutoMapper;
5 | using Core.Application.Interfaces.Identity;
6 | using Infrastructure.Identity.Models;
7 | using Infrastructure.Identity.Helpers;
8 | using Microsoft.AspNetCore.WebUtilities;
9 | using System.Text;
10 |
11 | namespace Infrastructure.Identity.Services
12 | {
13 | public class AuthService : IAuthService
14 | {
15 | private readonly IMapper _mapper;
16 | private readonly UserManager _userManager;
17 | private readonly SignInManager _signInManager;
18 |
19 | public AuthService(IMapper mapper, UserManager UserManager, SignInManager signInManager)
20 | {
21 | _mapper = mapper;
22 | _userManager = UserManager;
23 | _signInManager = signInManager;
24 | }
25 |
26 | public async Task SignInAsync(SignInRequest request)
27 | {
28 | SignInResult signInResult = await _signInManager.PasswordSignInAsync(request.Email, request.Password, request.RememberMe, false);
29 |
30 | return signInResult.Succeeded;
31 | }
32 |
33 | public async Task SignOutAsync()
34 | {
35 | await _signInManager.SignOutAsync();
36 | }
37 |
38 | public async Task GetCurrentUserAsync(ClaimsPrincipal principal)
39 | {
40 | if (principal == null)
41 | {
42 | return null;
43 | }
44 |
45 | string userId = _userManager.GetUserId(principal);
46 | if (string.IsNullOrEmpty(userId))
47 | {
48 | return null;
49 | }
50 |
51 | ApplicationUser user = await _userManager.FindByIdAsync(userId);
52 |
53 | if (user == null)
54 | {
55 | return null;
56 | }
57 |
58 | return _mapper.Map(user);
59 | }
60 |
61 | public async Task SignUpAsync(SignUpRequest request)
62 | {
63 | ApplicationUser user = new ApplicationUser
64 | {
65 | Email = request.Email,
66 | UserName = request.Email
67 | };
68 |
69 | IdentityResult result = await _userManager.CreateAsync(user, request.Password);
70 |
71 | if (result.Succeeded)
72 | {
73 | await _signInManager.SignInAsync(user, isPersistent: false);
74 | }
75 |
76 | return result.ToAuthenticationResult();
77 | }
78 |
79 | public async Task ChangePasswordAsync(ClaimsPrincipal principal, string currentPassword, string newPassword)
80 | {
81 | ApplicationUser user = await _userManager.GetUserAsync(principal);
82 |
83 | if (user == null)
84 | {
85 | return new AuthenticationResponse()
86 | {
87 | Succeeded = false,
88 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
89 | };
90 | }
91 |
92 | IdentityResult result = await _userManager.ChangePasswordAsync(user, currentPassword, newPassword);
93 |
94 | return result.ToAuthenticationResult();
95 | }
96 |
97 | public async Task ResetPasswordAsync(ResetPasswordRequest request)
98 | {
99 | ApplicationUser user = await _userManager.FindByEmailAsync(request.UserEmail);
100 |
101 | if (user == null)
102 | {
103 | return new AuthenticationResponse()
104 | {
105 | Succeeded = false,
106 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
107 | };
108 | }
109 |
110 | IdentityResult result = await _userManager.ResetPasswordAsync(user, Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(request.Token)), request.NewPassword);
111 |
112 | return result.ToAuthenticationResult();
113 | }
114 |
115 | public async Task GeneratePasswordResetTokenAsync(string email)
116 | {
117 | ApplicationUser user = await _userManager.FindByEmailAsync(email);
118 |
119 | if (user == null)
120 | {
121 | return new TokenResponse()
122 | {
123 | Succeeded = false,
124 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
125 | };
126 | }
127 |
128 | string token = await _userManager.GeneratePasswordResetTokenAsync(user);
129 |
130 | return new TokenResponse()
131 | {
132 | Succeeded = true,
133 | Token = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token))
134 | };
135 | }
136 |
137 | public async Task GenerateEmailConfirmationAsync(ClaimsPrincipal principal)
138 | {
139 | ApplicationUser user = await _userManager.GetUserAsync(principal);
140 |
141 | if (user == null)
142 | {
143 | return new TokenResponse()
144 | {
145 | Succeeded = false,
146 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
147 | };
148 | }
149 |
150 | string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
151 |
152 | return new TokenResponse()
153 | {
154 | Succeeded = true,
155 | UserId = user.Id,
156 | Token = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code))
157 | };
158 | }
159 |
160 | public async Task ConfirmEmailAsync(EmailConfirmationRequest request)
161 | {
162 | ApplicationUser user = await _userManager.FindByIdAsync(request.UserId);
163 |
164 | if (user == null)
165 | {
166 | return new AuthenticationResponse()
167 | {
168 | Succeeded = false,
169 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
170 | };
171 | }
172 |
173 | string token = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(request.Token));
174 |
175 | IdentityResult result = await _userManager.ConfirmEmailAsync(user, token);
176 |
177 | return result.ToAuthenticationResult();
178 | }
179 |
180 | public async Task RefreshSignInAsync(ClaimsPrincipal principal)
181 | {
182 | ApplicationUser user = await _userManager.GetUserAsync(principal);
183 |
184 | if (user != null)
185 | {
186 | await _signInManager.RefreshSignInAsync(user);
187 | }
188 | }
189 |
190 | public async Task GenerateEmailChangeAsync(ClaimsPrincipal principal, string newEmail)
191 | {
192 | ApplicationUser user = await _userManager.GetUserAsync(principal);
193 |
194 | if (user == null)
195 | {
196 | return new TokenResponse()
197 | {
198 | Succeeded = false,
199 | Errors = new Dictionary() { { string.Empty, "Invalid request." } }
200 | };
201 | }
202 |
203 | string token = await _userManager.GenerateChangeEmailTokenAsync(user, newEmail);
204 |
205 | return new TokenResponse()
206 | {
207 | Succeeded = true,
208 | Token = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(token)),
209 | UserId = user.Id
210 | };
211 | }
212 | }
213 | }
214 |
--------------------------------------------------------------------------------
/src/Infrastructure.Identity/Services/UserService.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.DTOs;
2 | using Core.Application.Interfaces.Identity;
3 | using AutoMapper;
4 | using Infrastructure.Identity.Models;
5 | using Microsoft.AspNetCore.Identity;
6 | using Infrastructure.Identity.Helpers;
7 | using System.Security.Claims;
8 |
9 | namespace Infrastructure.Identity.Services
10 | {
11 | public class UserService : IUserService
12 | {
13 | public UserManager _userManager { get; }
14 | public IMapper _mapper { get; }
15 |
16 | public UserService(UserManager userManager, IMapper mapper)
17 | {
18 | _userManager = userManager;
19 | _mapper = mapper;
20 | }
21 |
22 | public async Task FindByIdAsync(string userId)
23 | {
24 | ApplicationUser user = await _userManager.FindByIdAsync(userId);
25 |
26 | if (user == null)
27 | {
28 | return null;
29 | }
30 |
31 | return _mapper.Map(user);
32 | }
33 |
34 | public async Task FindByEmailAsync(string email)
35 | {
36 | ApplicationUser user = await _userManager.FindByEmailAsync(email);
37 |
38 | if (user == null)
39 | {
40 | return null;
41 | }
42 |
43 | return _mapper.Map(user);
44 | }
45 |
46 | public async Task GetUserIdAsync(ClaimsPrincipal principal)
47 | {
48 | ApplicationUser user = await _userManager.GetUserAsync(principal);
49 | return await _userManager.GetUserIdAsync(user);
50 | }
51 |
52 | public async Task ChangeEmailAsync(ClaimsPrincipal principal, string email, string code)
53 | {
54 | ApplicationUser user = await _userManager.GetUserAsync(principal);
55 | IdentityResult result = await _userManager.ChangeEmailAsync(user, email, code);
56 | return result.ToAuthenticationResult();
57 | }
58 |
59 | public async Task IsEmailConfirmedAsync(string email)
60 | {
61 | ApplicationUser user = await _userManager.FindByEmailAsync(email);
62 |
63 | if (user == null)
64 | {
65 | return false;
66 | }
67 |
68 | return await _userManager.IsEmailConfirmedAsync(user);
69 | }
70 |
71 | public async Task ChangePasswordAsync(ClaimsPrincipal principal, string oldPassword, string newPassword)
72 | {
73 | ApplicationUser user = await _userManager.GetUserAsync(principal);
74 | IdentityResult result = await _userManager.ChangePasswordAsync(user, oldPassword, newPassword);
75 | return result.ToAuthenticationResult();
76 | }
77 |
78 | public async Task HasPasswordAsync(ClaimsPrincipal principal)
79 | {
80 | ApplicationUser user = await _userManager.GetUserAsync(principal);
81 | return await _userManager.HasPasswordAsync(user);
82 | }
83 |
84 | public async Task GetEmailAsync(ClaimsPrincipal principal)
85 | {
86 | ApplicationUser user = await _userManager.GetUserAsync(principal);
87 | return await _userManager.GetEmailAsync(user);
88 | }
89 |
90 | public async Task GetUserNameAsync(ClaimsPrincipal principal)
91 | {
92 | ApplicationUser user = await _userManager.GetUserAsync(principal);
93 | return await _userManager.GetUserNameAsync(user);
94 | }
95 |
96 | public async Task GetPhoneNumberAsync(ClaimsPrincipal principal)
97 | {
98 | ApplicationUser user = await _userManager.GetUserAsync(principal);
99 | return await _userManager.GetPhoneNumberAsync(user);
100 | }
101 |
102 | public async Task SetPhoneNumberAsync(ClaimsPrincipal principal, string phoneNumber)
103 | {
104 | ApplicationUser user = await _userManager.GetUserAsync(principal);
105 | IdentityResult result = await _userManager.SetPhoneNumberAsync(user, phoneNumber);
106 | return result.ToAuthenticationResult();
107 | }
108 |
109 | public async Task AddPasswordAsync(ClaimsPrincipal principal, string newPassword)
110 | {
111 | ApplicationUser user = await _userManager.GetUserAsync(principal);
112 | IdentityResult result = await _userManager.AddPasswordAsync(user, newPassword);
113 | return result.ToAuthenticationResult();
114 | }
115 | }
116 | }
117 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Data/AppDbContext.cs:
--------------------------------------------------------------------------------
1 | using Infrastructure.Persistence.Interceptors;
2 | using Microsoft.EntityFrameworkCore;
3 |
4 | namespace Infrastructure.Persistence.Data
5 | {
6 | public class AppDbContext : DbContext
7 | {
8 | private readonly AuditableEntitySaveChangesInterceptor _auditableEntitySaveChangesInterceptor;
9 |
10 | public AppDbContext(
11 | DbContextOptions options,
12 | AuditableEntitySaveChangesInterceptor auditableEntitySaveChangesInterceptor)
13 | : base(options)
14 | {
15 | _auditableEntitySaveChangesInterceptor = auditableEntitySaveChangesInterceptor;
16 | }
17 |
18 | protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
19 | {
20 | optionsBuilder.AddInterceptors(_auditableEntitySaveChangesInterceptor);
21 | }
22 |
23 | protected override void OnModelCreating(ModelBuilder modelBuilder)
24 | {
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Extensions/ServiceCollectionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Infrastructure.Persistence.Repositories;
2 | using Microsoft.EntityFrameworkCore;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Core.Application.Interfaces.Persistence;
6 | using Infrastructure.Persistence.Data;
7 | using Infrastructure.Persistence.Interceptors;
8 |
9 | namespace Infrastructure.Persistence.Extensions
10 | {
11 | public static class ServiceCollectionExtensions
12 | {
13 | public static void AddAppDbContext(this IServiceCollection services, IConfiguration configuration)
14 | {
15 | services.AddDbContext(options =>
16 | options.UseNpgsql(
17 | configuration.GetConnectionString("DefaultConnection"),
18 | b => b.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName)));
19 | }
20 |
21 | public static void AddInfrastructurePersistenceServices(this IServiceCollection services)
22 | {
23 | services.AddScoped();
24 | services.AddScoped(typeof(IRepositoryBase<>), typeof(RepositoryBase<>));
25 | services.AddScoped();
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Infrastructure.Persistence.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net7.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Interceptors/AuditableEntitySaveChangesInterceptor.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Diagnostics;
2 | using Microsoft.EntityFrameworkCore;
3 | using Core.Domain.Entities;
4 | using Core.Application.Interfaces.Application;
5 |
6 | namespace Infrastructure.Persistence.Interceptors
7 | {
8 | public class AuditableEntitySaveChangesInterceptor : SaveChangesInterceptor
9 | {
10 | private readonly ICurrentUserService _currentUserService;
11 | private readonly IDateTimeService _dateTime;
12 |
13 | public AuditableEntitySaveChangesInterceptor(
14 | ICurrentUserService currentUserService,
15 | IDateTimeService dateTime)
16 | {
17 | _currentUserService = currentUserService;
18 | _dateTime = dateTime;
19 | }
20 |
21 | public override InterceptionResult SavingChanges(DbContextEventData eventData, InterceptionResult result)
22 | {
23 | UpdateEntities(eventData.Context);
24 |
25 | return base.SavingChanges(eventData, result);
26 | }
27 |
28 | public override ValueTask> SavingChangesAsync(DbContextEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default)
29 | {
30 | UpdateEntities(eventData.Context);
31 |
32 | return base.SavingChangesAsync(eventData, result, cancellationToken);
33 | }
34 |
35 | public void UpdateEntities(DbContext? context)
36 | {
37 | if (context == null) return;
38 |
39 | DateTime now = _dateTime.Now;
40 |
41 | foreach (var entry in context.ChangeTracker.Entries())
42 | {
43 | if (entry.State == EntityState.Added)
44 | {
45 | entry.Entity.CreatedBy = _currentUserService.UserId;
46 | entry.Entity.CreatedOn = now;
47 | }
48 |
49 | if (entry.State == EntityState.Added || entry.State == EntityState.Modified)
50 | {
51 | entry.Entity.ModifiedBy = _currentUserService.UserId;
52 | entry.Entity.ModifiedOn = now;
53 | }
54 | }
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Migrations/20230408115629_InitialModel.Designer.cs:
--------------------------------------------------------------------------------
1 | //
2 | using Infrastructure.Persistence.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Migrations;
6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
7 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
8 |
9 | #nullable disable
10 |
11 | namespace Infrastructure.Persistence.Migrations
12 | {
13 | [DbContext(typeof(AppDbContext))]
14 | [Migration("20230408115629_InitialModel")]
15 | partial class InitialModel
16 | {
17 | ///
18 | protected override void BuildTargetModel(ModelBuilder modelBuilder)
19 | {
20 | #pragma warning disable 612, 618
21 | modelBuilder
22 | .HasAnnotation("ProductVersion", "7.0.4")
23 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
24 |
25 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
26 | #pragma warning restore 612, 618
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Migrations/20230408115629_InitialModel.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.EntityFrameworkCore.Migrations;
2 |
3 | #nullable disable
4 |
5 | namespace Infrastructure.Persistence.Migrations
6 | {
7 | ///
8 | public partial class InitialModel : Migration
9 | {
10 | ///
11 | protected override void Up(MigrationBuilder migrationBuilder)
12 | {
13 |
14 | }
15 |
16 | ///
17 | protected override void Down(MigrationBuilder migrationBuilder)
18 | {
19 |
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Migrations/AppDbContextModelSnapshot.cs:
--------------------------------------------------------------------------------
1 | //
2 | using Infrastructure.Persistence.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using Microsoft.EntityFrameworkCore.Infrastructure;
5 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
6 | using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
7 |
8 | #nullable disable
9 |
10 | namespace Infrastructure.Persistence.Migrations
11 | {
12 | [DbContext(typeof(AppDbContext))]
13 | partial class AppDbContextModelSnapshot : ModelSnapshot
14 | {
15 | protected override void BuildModel(ModelBuilder modelBuilder)
16 | {
17 | #pragma warning disable 612, 618
18 | modelBuilder
19 | .HasAnnotation("ProductVersion", "7.0.4")
20 | .HasAnnotation("Relational:MaxIdentifierLength", 63);
21 |
22 | NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
23 | #pragma warning restore 612, 618
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Infrastructure.Persistence/Repositories/RepositoryBase.cs:
--------------------------------------------------------------------------------
1 | using Core.Application.Interfaces.Persistence;
2 | using Infrastructure.Persistence.Data;
3 | using Microsoft.EntityFrameworkCore;
4 | using System.Linq.Expressions;
5 |
6 | namespace Infrastructure.Persistence.Repositories
7 | {
8 | public class RepositoryBase : IRepositoryBase where T : class
9 | {
10 | protected readonly AppDbContext _appContext;
11 |
12 | public RepositoryBase(AppDbContext appContext)
13 | {
14 | _appContext = appContext;
15 | }
16 |
17 | public async Task FirstOrDefaultAsync(Expression> filter = null, Func, IOrderedQueryable> orderBy = null, params Expression>[] includes)
18 | {
19 | IQueryable query = _appContext.Set();
20 |
21 | foreach (Expression> include in includes)
22 | {
23 | query = query.Include(include);
24 | }
25 |
26 | if (filter != null)
27 | {
28 | query = query.Where(filter);
29 | }
30 |
31 | if (orderBy != null)
32 | {
33 | query = orderBy(query);
34 | }
35 |
36 | return await query.FirstOrDefaultAsync().ConfigureAwait(false);
37 | }
38 |
39 | public async Task> GetAllAsync() => await _appContext.Set().ToListAsync();
40 |
41 | public async Task> GetAllAsync(Expression> filter = null, Func