├── .gitignore ├── Parte 1 - Usuario por Tenant ├── MultiTenancyDemo.sln └── MultiTenancyDemo │ ├── Areas │ └── Identity │ │ └── Pages │ │ └── _ViewStart.cshtml │ ├── Controllers │ ├── HomeController.cs │ └── UsuariosController.cs │ ├── Data │ ├── ApplicationDbContext.cs │ └── Migrations │ │ ├── 00000000000000_CreateIdentitySchema.Designer.cs │ │ ├── 00000000000000_CreateIdentitySchema.cs │ │ ├── 20220702220206_Multitenancy.Designer.cs │ │ ├── 20220702220206_Multitenancy.cs │ │ └── ApplicationDbContextModelSnapshot.cs │ ├── Entidades │ ├── IEntidadComún.cs │ ├── IEntidadTenant.cs │ ├── País.cs │ └── Producto.cs │ ├── Models │ ├── ErrorViewModel.cs │ ├── HomeIndexViewModel.cs │ ├── LoginViewModel.cs │ └── RegistroViewModel.cs │ ├── MultiTenancyDemo.csproj │ ├── Program.cs │ ├── Properties │ ├── launchSettings.json │ ├── serviceDependencies.json │ └── serviceDependencies.local.json │ ├── Servicios │ ├── Constantes.cs │ ├── ExtensionesTipo.cs │ ├── IServicioTenant.cs │ └── ServicioTenant.cs │ ├── Views │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ ├── _Layout.cshtml.css │ │ ├── _LoginPartial.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── Usuarios │ │ ├── Login.cshtml │ │ └── Registro.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── 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 ├── Parte 2 - Tenant por Empresa ├── MultiTenancyDemo.sln └── MultiTenancyDemo │ ├── Areas │ └── Identity │ │ └── Pages │ │ └── _ViewStart.cshtml │ ├── Controllers │ ├── EmpresasController.cs │ ├── HomeController.cs │ ├── PermisosController.cs │ ├── UsuariosController.cs │ └── VinculacionesController.cs │ ├── Data │ ├── ApplicationDbContext.cs │ └── Migrations │ │ ├── 00000000000000_CreateIdentitySchema.Designer.cs │ │ ├── 00000000000000_CreateIdentitySchema.cs │ │ ├── 20220702220206_Multitenancy.Designer.cs │ │ ├── 20220702220206_Multitenancy.cs │ │ ├── 20220801125621_Empresas.Designer.cs │ │ ├── 20220801125621_Empresas.cs │ │ └── ApplicationDbContextModelSnapshot.cs │ ├── Entidades │ ├── Empresa.cs │ ├── EmpresaUsuarioPermiso.cs │ ├── IEntidadComún.cs │ ├── IEntidadTenant.cs │ ├── País.cs │ ├── Permisos.cs │ ├── Producto.cs │ ├── Vinculacion.cs │ └── VinculacionEstatus.cs │ ├── Models │ ├── AdministrarPermisosDTO.cs │ ├── CrearEmpresa.cs │ ├── ErrorViewModel.cs │ ├── HomeIndexViewModel.cs │ ├── IndexPermisosDTO.cs │ ├── LoginViewModel.cs │ ├── PermisoUsuarioDTO.cs │ ├── RegistroViewModel.cs │ ├── UsuarioDTO.cs │ └── VincularUsuario.cs │ ├── MultiTenancyDemo.csproj │ ├── Program.cs │ ├── Properties │ ├── launchSettings.json │ ├── serviceDependencies.json │ └── serviceDependencies.local.json │ ├── Seguridad │ ├── IAuthorizationServiceExtensions.cs │ ├── TienePermisoAttribute.cs │ ├── TienePermisoHandler.cs │ ├── TienePermisoPolicyProvider.cs │ └── TienePermisoRequirement.cs │ ├── Servicios │ ├── Constantes.cs │ ├── EsconderAttribute.cs │ ├── ExtensionesTipo.cs │ ├── IServicioCambioTenant.cs │ ├── IServicioTenant.cs │ ├── IServicioUsuario.cs │ ├── ServicioCambioTenant.cs │ ├── ServicioTenant.cs │ └── ServicioUsuario.cs │ ├── Views │ ├── Empresas │ │ ├── Cambiar.cshtml │ │ └── Crear.cshtml │ ├── Home │ │ ├── Index.cshtml │ │ └── Privacy.cshtml │ ├── Permisos │ │ ├── Administrar.cshtml │ │ └── Index.cshtml │ ├── Shared │ │ ├── Error.cshtml │ │ ├── _Layout.cshtml │ │ ├── _Layout.cshtml.css │ │ ├── _LoginPartial.cshtml │ │ └── _ValidationScriptsPartial.cshtml │ ├── Usuarios │ │ ├── Login.cshtml │ │ └── Registro.cshtml │ ├── Vinculaciones │ │ ├── Index.cshtml │ │ ├── UsuarioVinculado.cshtml │ │ └── Vincular.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── 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 └── README.md /.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 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # Tye 66 | .tye/ 67 | 68 | # ASP.NET Scaffolding 69 | ScaffoldingReadMe.txt 70 | 71 | # StyleCop 72 | StyleCopReport.xml 73 | 74 | # Files built by Visual Studio 75 | *_i.c 76 | *_p.c 77 | *_h.h 78 | *.ilk 79 | *.meta 80 | *.obj 81 | *.iobj 82 | *.pch 83 | *.pdb 84 | *.ipdb 85 | *.pgc 86 | *.pgd 87 | *.rsp 88 | *.sbr 89 | *.tlb 90 | *.tli 91 | *.tlh 92 | *.tmp 93 | *.tmp_proj 94 | *_wpftmp.csproj 95 | *.log 96 | *.vspscc 97 | *.vssscc 98 | .builds 99 | *.pidb 100 | *.svclog 101 | *.scc 102 | 103 | # Chutzpah Test files 104 | _Chutzpah* 105 | 106 | # Visual C++ cache files 107 | ipch/ 108 | *.aps 109 | *.ncb 110 | *.opendb 111 | *.opensdf 112 | *.sdf 113 | *.cachefile 114 | *.VC.db 115 | *.VC.VC.opendb 116 | 117 | # Visual Studio profiler 118 | *.psess 119 | *.vsp 120 | *.vspx 121 | *.sap 122 | 123 | # Visual Studio Trace Files 124 | *.e2e 125 | 126 | # TFS 2012 Local Workspace 127 | $tf/ 128 | 129 | # Guidance Automation Toolkit 130 | *.gpState 131 | 132 | # ReSharper is a .NET coding add-in 133 | _ReSharper*/ 134 | *.[Rr]e[Ss]harper 135 | *.DotSettings.user 136 | 137 | # TeamCity is a build add-in 138 | _TeamCity* 139 | 140 | # DotCover is a Code Coverage Tool 141 | *.dotCover 142 | 143 | # AxoCover is a Code Coverage Tool 144 | .axoCover/* 145 | !.axoCover/settings.json 146 | 147 | # Coverlet is a free, cross platform Code Coverage Tool 148 | coverage*.json 149 | coverage*.xml 150 | coverage*.info 151 | 152 | # Visual Studio code coverage results 153 | *.coverage 154 | *.coveragexml 155 | 156 | # NCrunch 157 | _NCrunch_* 158 | .*crunch*.local.xml 159 | nCrunchTemp_* 160 | 161 | # MightyMoose 162 | *.mm.* 163 | AutoTest.Net/ 164 | 165 | # Web workbench (sass) 166 | .sass-cache/ 167 | 168 | # Installshield output folder 169 | [Ee]xpress/ 170 | 171 | # DocProject is a documentation generator add-in 172 | DocProject/buildhelp/ 173 | DocProject/Help/*.HxT 174 | DocProject/Help/*.HxC 175 | DocProject/Help/*.hhc 176 | DocProject/Help/*.hhk 177 | DocProject/Help/*.hhp 178 | DocProject/Help/Html2 179 | DocProject/Help/html 180 | 181 | # Click-Once directory 182 | publish/ 183 | 184 | # Publish Web Output 185 | *.[Pp]ublish.xml 186 | *.azurePubxml 187 | # Note: Comment the next line if you want to checkin your web deploy settings, 188 | # but database connection strings (with potential passwords) will be unencrypted 189 | *.pubxml 190 | *.publishproj 191 | 192 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 193 | # checkin your Azure Web App publish settings, but sensitive information contained 194 | # in these scripts will be unencrypted 195 | PublishScripts/ 196 | 197 | # NuGet Packages 198 | *.nupkg 199 | # NuGet Symbol Packages 200 | *.snupkg 201 | # The packages folder can be ignored because of Package Restore 202 | **/[Pp]ackages/* 203 | # except build/, which is used as an MSBuild target. 204 | !**/[Pp]ackages/build/ 205 | # Uncomment if necessary however generally it will be regenerated when needed 206 | #!**/[Pp]ackages/repositories.config 207 | # NuGet v3's project.json files produces more ignorable files 208 | *.nuget.props 209 | *.nuget.targets 210 | 211 | # Microsoft Azure Build Output 212 | csx/ 213 | *.build.csdef 214 | 215 | # Microsoft Azure Emulator 216 | ecf/ 217 | rcf/ 218 | 219 | # Windows Store app package directories and files 220 | AppPackages/ 221 | BundleArtifacts/ 222 | Package.StoreAssociation.xml 223 | _pkginfo.txt 224 | *.appx 225 | *.appxbundle 226 | *.appxupload 227 | 228 | # Visual Studio cache files 229 | # files ending in .cache can be ignored 230 | *.[Cc]ache 231 | # but keep track of directories ending in .cache 232 | !?*.[Cc]ache/ 233 | 234 | # Others 235 | ClientBin/ 236 | ~$* 237 | *~ 238 | *.dbmdl 239 | *.dbproj.schemaview 240 | *.jfm 241 | *.pfx 242 | *.publishsettings 243 | orleans.codegen.cs 244 | 245 | # Including strong name files can present a security risk 246 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 247 | #*.snk 248 | 249 | # Since there are multiple workflows, uncomment next line to ignore bower_components 250 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 251 | #bower_components/ 252 | 253 | # RIA/Silverlight projects 254 | Generated_Code/ 255 | 256 | # Backup & report files from converting an old project file 257 | # to a newer Visual Studio version. Backup files are not needed, 258 | # because we have git ;-) 259 | _UpgradeReport_Files/ 260 | Backup*/ 261 | UpgradeLog*.XML 262 | UpgradeLog*.htm 263 | ServiceFabricBackup/ 264 | *.rptproj.bak 265 | 266 | # SQL Server files 267 | *.mdf 268 | *.ldf 269 | *.ndf 270 | 271 | # Business Intelligence projects 272 | *.rdl.data 273 | *.bim.layout 274 | *.bim_*.settings 275 | *.rptproj.rsuser 276 | *- [Bb]ackup.rdl 277 | *- [Bb]ackup ([0-9]).rdl 278 | *- [Bb]ackup ([0-9][0-9]).rdl 279 | 280 | # Microsoft Fakes 281 | FakesAssemblies/ 282 | 283 | # GhostDoc plugin setting file 284 | *.GhostDoc.xml 285 | 286 | # Node.js Tools for Visual Studio 287 | .ntvs_analysis.dat 288 | node_modules/ 289 | 290 | # Visual Studio 6 build log 291 | *.plg 292 | 293 | # Visual Studio 6 workspace options file 294 | *.opt 295 | 296 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 297 | *.vbw 298 | 299 | # Visual Studio LightSwitch build output 300 | **/*.HTMLClient/GeneratedArtifacts 301 | **/*.DesktopClient/GeneratedArtifacts 302 | **/*.DesktopClient/ModelManifest.xml 303 | **/*.Server/GeneratedArtifacts 304 | **/*.Server/ModelManifest.xml 305 | _Pvt_Extensions 306 | 307 | # Paket dependency manager 308 | .paket/paket.exe 309 | paket-files/ 310 | 311 | # FAKE - F# Make 312 | .fake/ 313 | 314 | # CodeRush personal settings 315 | .cr/personal 316 | 317 | # Python Tools for Visual Studio (PTVS) 318 | __pycache__/ 319 | *.pyc 320 | 321 | # Cake - Uncomment if you are using it 322 | # tools/** 323 | # !tools/packages.config 324 | 325 | # Tabs Studio 326 | *.tss 327 | 328 | # Telerik's JustMock configuration file 329 | *.jmconfig 330 | 331 | # BizTalk build output 332 | *.btp.cs 333 | *.btm.cs 334 | *.odx.cs 335 | *.xsd.cs 336 | 337 | # OpenCover UI analysis results 338 | OpenCover/ 339 | 340 | # Azure Stream Analytics local run output 341 | ASALocalRun/ 342 | 343 | # MSBuild Binary and Structured Log 344 | *.binlog 345 | 346 | # NVidia Nsight GPU debugger configuration file 347 | *.nvuser 348 | 349 | # MFractors (Xamarin productivity tool) working folder 350 | .mfractor/ 351 | 352 | # Local History for Visual Studio 353 | .localhistory/ 354 | 355 | # BeatPulse healthcheck temp database 356 | healthchecksdb 357 | 358 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 359 | MigrationBackup/ 360 | 361 | # Ionide (cross platform F# VS Code tools) working folder 362 | .ionide/ 363 | 364 | # Fody - auto-generated XML schema 365 | FodyWeavers.xsd 366 | 367 | ## 368 | ## Visual studio for Mac 369 | ## 370 | 371 | 372 | # globs 373 | Makefile.in 374 | *.userprefs 375 | *.usertasks 376 | config.make 377 | config.status 378 | aclocal.m4 379 | install-sh 380 | autom4te.cache/ 381 | *.tar.gz 382 | tarballs/ 383 | test-results/ 384 | 385 | # Mac bundle stuff 386 | *.dmg 387 | *.app 388 | 389 | # content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore 390 | # General 391 | .DS_Store 392 | .AppleDouble 393 | .LSOverride 394 | 395 | # Icon must end with two \r 396 | Icon 397 | 398 | 399 | # Thumbnails 400 | ._* 401 | 402 | # Files that might appear in the root of a volume 403 | .DocumentRevisions-V100 404 | .fseventsd 405 | .Spotlight-V100 406 | .TemporaryItems 407 | .Trashes 408 | .VolumeIcon.icns 409 | .com.apple.timemachine.donotpresent 410 | 411 | # Directories potentially created on remote AFP share 412 | .AppleDB 413 | .AppleDesktop 414 | Network Trash Folder 415 | Temporary Items 416 | .apdisk 417 | 418 | # content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore 419 | # Windows thumbnail cache files 420 | Thumbs.db 421 | ehthumbs.db 422 | ehthumbs_vista.db 423 | 424 | # Dump file 425 | *.stackdump 426 | 427 | # Folder config file 428 | [Dd]esktop.ini 429 | 430 | # Recycle Bin used on file shares 431 | $RECYCLE.BIN/ 432 | 433 | # Windows Installer files 434 | *.cab 435 | *.msi 436 | *.msix 437 | *.msm 438 | *.msp 439 | 440 | # Windows shortcuts 441 | *.lnk 442 | 443 | # JetBrains Rider 444 | .idea/ 445 | *.sln.iml 446 | 447 | ## 448 | ## Visual Studio Code 449 | ## 450 | .vscode/* 451 | !.vscode/settings.json 452 | !.vscode/tasks.json 453 | !.vscode/launch.json 454 | !.vscode/extensions.json 455 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32526.322 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiTenancyDemo", "MultiTenancyDemo\MultiTenancyDemo.csproj", "{E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}" 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 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.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 = {019731A0-4136-42A5-BC39-546654CC48D9} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Areas/Identity/Pages/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Data; 4 | using MultiTenancyDemo.Entidades; 5 | using MultiTenancyDemo.Models; 6 | using System.Diagnostics; 7 | 8 | namespace MultiTenancyDemo.Controllers 9 | { 10 | public class HomeController : Controller 11 | { 12 | private readonly ILogger _logger; 13 | private readonly ApplicationDbContext context; 14 | 15 | public HomeController(ILogger logger, 16 | ApplicationDbContext context) 17 | { 18 | _logger = logger; 19 | this.context = context; 20 | } 21 | 22 | public async Task Index() 23 | { 24 | var modelo = await ConstruirModeloHomeIndex(); 25 | return View(modelo); 26 | } 27 | 28 | [HttpPost] 29 | public async Task Index(Producto producto) 30 | { 31 | context.Add(producto); 32 | await context.SaveChangesAsync(); 33 | var modelo = await ConstruirModeloHomeIndex(); 34 | return View(modelo); 35 | } 36 | 37 | 38 | private async Task ConstruirModeloHomeIndex() 39 | { 40 | var productos = await context.Productos.ToListAsync(); 41 | var paises = await context.Paises.ToListAsync(); 42 | 43 | var modelo = new HomeIndexViewModel(); 44 | modelo.Productos = productos; 45 | modelo.Países = paises; 46 | return modelo; 47 | } 48 | 49 | 50 | public IActionResult Privacy() 51 | { 52 | return View(); 53 | } 54 | 55 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 56 | public IActionResult Error() 57 | { 58 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Controllers/UsuariosController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.AspNetCore.Mvc; 3 | using MultiTenancyDemo.Models; 4 | using MultiTenancyDemo.Servicios; 5 | using System.Security.Claims; 6 | 7 | namespace MultiTenancyDemo.Controllers 8 | { 9 | public class UsuariosController : Controller 10 | { 11 | private readonly UserManager userManager; 12 | private readonly SignInManager signInManager; 13 | 14 | public UsuariosController(UserManager userManager, 15 | SignInManager signInManager) 16 | { 17 | this.userManager = userManager; 18 | this.signInManager = signInManager; 19 | } 20 | 21 | public IActionResult Registro() 22 | { 23 | return View(); 24 | } 25 | 26 | [HttpPost] 27 | public async Task Registro(RegistroViewModel modelo) 28 | { 29 | if (!ModelState.IsValid) 30 | { 31 | return View(modelo); 32 | } 33 | 34 | var usuario = new IdentityUser() { Email = modelo.Email, UserName = modelo.Email }; 35 | 36 | var resultado = await userManager.CreateAsync(usuario, password: modelo.Password); 37 | 38 | var claimsPersonalizados = new List() 39 | { 40 | new Claim(Constantes.ClaimTenantId, usuario.Id), 41 | }; 42 | 43 | await userManager.AddClaimsAsync(usuario, claimsPersonalizados); 44 | 45 | if (resultado.Succeeded) 46 | { 47 | await signInManager.SignInAsync(usuario, isPersistent: true); 48 | return RedirectToAction("Index", "Home"); 49 | } 50 | else 51 | { 52 | foreach (var error in resultado.Errors) 53 | { 54 | ModelState.AddModelError(string.Empty, error.Description); 55 | } 56 | 57 | return View(modelo); 58 | } 59 | 60 | } 61 | 62 | [HttpGet] 63 | public IActionResult Login() 64 | { 65 | return View(); 66 | } 67 | 68 | [HttpPost] 69 | public async Task Login(LoginViewModel modelo) 70 | { 71 | if (!ModelState.IsValid) 72 | { 73 | return View(modelo); 74 | } 75 | 76 | var resultado = await signInManager.PasswordSignInAsync(modelo.Email, 77 | modelo.Password, modelo.Recuerdame, lockoutOnFailure: false); 78 | 79 | if (resultado.Succeeded) 80 | { 81 | return RedirectToAction("Index", "Home"); 82 | } 83 | else 84 | { 85 | ModelState.AddModelError(string.Empty, "Nombre de usuario o password incorrecto."); 86 | return View(modelo); 87 | } 88 | } 89 | 90 | 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Entidades; 4 | using MultiTenancyDemo.Servicios; 5 | using System.Linq.Expressions; 6 | using System.Reflection; 7 | 8 | namespace MultiTenancyDemo.Data 9 | { 10 | public class ApplicationDbContext : IdentityDbContext 11 | { 12 | private string tenantId; 13 | 14 | public ApplicationDbContext(DbContextOptions options, 15 | IServicioTenant servicioTenant) 16 | : base(options) 17 | { 18 | tenantId = servicioTenant.ObtenerTenant(); 19 | } 20 | 21 | public override Task SaveChangesAsync(CancellationToken cancellationToken = default) 22 | { 23 | foreach (var item in ChangeTracker.Entries().Where(e => e.State == EntityState.Added 24 | && e.Entity is IEntidadTenant)) 25 | { 26 | if (string.IsNullOrEmpty(tenantId)) 27 | { 28 | throw new Exception("TenantId no encontrado al momento de crear el registro."); 29 | } 30 | 31 | var entidad = item.Entity as IEntidadTenant; 32 | entidad!.TenantId = tenantId; 33 | } 34 | 35 | return base.SaveChangesAsync(cancellationToken); 36 | } 37 | 38 | 39 | protected override void OnModelCreating(ModelBuilder builder) 40 | { 41 | base.OnModelCreating(builder); 42 | 43 | builder.Entity().HasData(new País[] 44 | { 45 | new País{Id = 1, Nombre = "República Dominicana"}, 46 | new País{Id = 2, Nombre = "México"}, 47 | new País{Id = 3, Nombre = "Colombia"} 48 | }); 49 | 50 | 51 | foreach (var entidad in builder.Model.GetEntityTypes()) 52 | { 53 | var tipo = entidad.ClrType; 54 | 55 | if (typeof(IEntidadTenant).IsAssignableFrom(tipo)) 56 | { 57 | var método = typeof(ApplicationDbContext) 58 | .GetMethod(nameof(ArmarFiltroGlobalTenant), 59 | BindingFlags.NonPublic | BindingFlags.Static 60 | )?.MakeGenericMethod(tipo); 61 | 62 | var filtro = método?.Invoke(null, new object[] { this })!; 63 | entidad.SetQueryFilter((LambdaExpression)filtro); 64 | entidad.AddIndex(entidad.FindProperty(nameof(IEntidadTenant.TenantId))!); 65 | } 66 | else if (tipo.DebeSaltarValidaciónTenant()) 67 | { 68 | continue; 69 | } 70 | else 71 | { 72 | throw new Exception($"La entidad {entidad} no ha sido marcada como tenant o común"); 73 | } 74 | } 75 | } 76 | 77 | private static LambdaExpression ArmarFiltroGlobalTenant( 78 | ApplicationDbContext context) 79 | where TEntidad : class, IEntidadTenant 80 | { 81 | Expression> filtro = x => x.TenantId == context.tenantId; 82 | return filtro; 83 | } 84 | 85 | public DbSet Productos => Set(); 86 | public DbSet Paises => Set(); 87 | 88 | } 89 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Data/Migrations/00000000000000_CreateIdentitySchema.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Metadata; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | using System; 4 | 5 | namespace MultiTenancyDemo.Data.Migrations 6 | { 7 | public partial class CreateIdentitySchema : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "AspNetRoles", 13 | columns: table => new 14 | { 15 | Id = table.Column(nullable: false), 16 | Name = table.Column(maxLength: 256, nullable: true), 17 | NormalizedName = table.Column(maxLength: 256, nullable: true), 18 | ConcurrencyStamp = table.Column(nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 23 | }); 24 | 25 | migrationBuilder.CreateTable( 26 | name: "AspNetUsers", 27 | columns: table => new 28 | { 29 | Id = table.Column(nullable: false), 30 | UserName = table.Column(maxLength: 256, nullable: true), 31 | NormalizedUserName = table.Column(maxLength: 256, nullable: true), 32 | Email = table.Column(maxLength: 256, nullable: true), 33 | NormalizedEmail = table.Column(maxLength: 256, nullable: true), 34 | EmailConfirmed = table.Column(nullable: false), 35 | PasswordHash = table.Column(nullable: true), 36 | SecurityStamp = table.Column(nullable: true), 37 | ConcurrencyStamp = table.Column(nullable: true), 38 | PhoneNumber = table.Column(nullable: true), 39 | PhoneNumberConfirmed = table.Column(nullable: false), 40 | TwoFactorEnabled = table.Column(nullable: false), 41 | LockoutEnd = table.Column(nullable: true), 42 | LockoutEnabled = table.Column(nullable: false), 43 | AccessFailedCount = table.Column(nullable: false) 44 | }, 45 | constraints: table => 46 | { 47 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 48 | }); 49 | 50 | migrationBuilder.CreateTable( 51 | name: "AspNetRoleClaims", 52 | columns: table => new 53 | { 54 | Id = table.Column(nullable: false) 55 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 56 | RoleId = table.Column(nullable: false), 57 | ClaimType = table.Column(nullable: true), 58 | ClaimValue = table.Column(nullable: true) 59 | }, 60 | constraints: table => 61 | { 62 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 63 | table.ForeignKey( 64 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 65 | column: x => x.RoleId, 66 | principalTable: "AspNetRoles", 67 | principalColumn: "Id", 68 | onDelete: ReferentialAction.Cascade); 69 | }); 70 | 71 | migrationBuilder.CreateTable( 72 | name: "AspNetUserClaims", 73 | columns: table => new 74 | { 75 | Id = table.Column(nullable: false) 76 | .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), 77 | UserId = table.Column(nullable: false), 78 | ClaimType = table.Column(nullable: true), 79 | ClaimValue = table.Column(nullable: true) 80 | }, 81 | constraints: table => 82 | { 83 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 84 | table.ForeignKey( 85 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 86 | column: x => x.UserId, 87 | principalTable: "AspNetUsers", 88 | principalColumn: "Id", 89 | onDelete: ReferentialAction.Cascade); 90 | }); 91 | 92 | migrationBuilder.CreateTable( 93 | name: "AspNetUserLogins", 94 | columns: table => new 95 | { 96 | LoginProvider = table.Column(maxLength: 128, nullable: false), 97 | ProviderKey = table.Column(maxLength: 128, nullable: false), 98 | ProviderDisplayName = table.Column(nullable: true), 99 | UserId = table.Column(nullable: false) 100 | }, 101 | constraints: table => 102 | { 103 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 104 | table.ForeignKey( 105 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 106 | column: x => x.UserId, 107 | principalTable: "AspNetUsers", 108 | principalColumn: "Id", 109 | onDelete: ReferentialAction.Cascade); 110 | }); 111 | 112 | migrationBuilder.CreateTable( 113 | name: "AspNetUserRoles", 114 | columns: table => new 115 | { 116 | UserId = table.Column(nullable: false), 117 | RoleId = table.Column(nullable: false) 118 | }, 119 | constraints: table => 120 | { 121 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 122 | table.ForeignKey( 123 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 124 | column: x => x.RoleId, 125 | principalTable: "AspNetRoles", 126 | principalColumn: "Id", 127 | onDelete: ReferentialAction.Cascade); 128 | table.ForeignKey( 129 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 130 | column: x => x.UserId, 131 | principalTable: "AspNetUsers", 132 | principalColumn: "Id", 133 | onDelete: ReferentialAction.Cascade); 134 | }); 135 | 136 | migrationBuilder.CreateTable( 137 | name: "AspNetUserTokens", 138 | columns: table => new 139 | { 140 | UserId = table.Column(nullable: false), 141 | LoginProvider = table.Column(maxLength: 128, nullable: false), 142 | Name = table.Column(maxLength: 128, nullable: false), 143 | Value = table.Column(nullable: true) 144 | }, 145 | constraints: table => 146 | { 147 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 148 | table.ForeignKey( 149 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 150 | column: x => x.UserId, 151 | principalTable: "AspNetUsers", 152 | principalColumn: "Id", 153 | onDelete: ReferentialAction.Cascade); 154 | }); 155 | 156 | migrationBuilder.CreateIndex( 157 | name: "IX_AspNetRoleClaims_RoleId", 158 | table: "AspNetRoleClaims", 159 | column: "RoleId"); 160 | 161 | migrationBuilder.CreateIndex( 162 | name: "RoleNameIndex", 163 | table: "AspNetRoles", 164 | column: "NormalizedName", 165 | unique: true, 166 | filter: "[NormalizedName] IS NOT NULL"); 167 | 168 | migrationBuilder.CreateIndex( 169 | name: "IX_AspNetUserClaims_UserId", 170 | table: "AspNetUserClaims", 171 | column: "UserId"); 172 | 173 | migrationBuilder.CreateIndex( 174 | name: "IX_AspNetUserLogins_UserId", 175 | table: "AspNetUserLogins", 176 | column: "UserId"); 177 | 178 | migrationBuilder.CreateIndex( 179 | name: "IX_AspNetUserRoles_RoleId", 180 | table: "AspNetUserRoles", 181 | column: "RoleId"); 182 | 183 | migrationBuilder.CreateIndex( 184 | name: "EmailIndex", 185 | table: "AspNetUsers", 186 | column: "NormalizedEmail"); 187 | 188 | migrationBuilder.CreateIndex( 189 | name: "UserNameIndex", 190 | table: "AspNetUsers", 191 | column: "NormalizedUserName", 192 | unique: true, 193 | filter: "[NormalizedUserName] IS NOT NULL"); 194 | } 195 | 196 | protected override void Down(MigrationBuilder migrationBuilder) 197 | { 198 | migrationBuilder.DropTable( 199 | name: "AspNetRoleClaims"); 200 | 201 | migrationBuilder.DropTable( 202 | name: "AspNetUserClaims"); 203 | 204 | migrationBuilder.DropTable( 205 | name: "AspNetUserLogins"); 206 | 207 | migrationBuilder.DropTable( 208 | name: "AspNetUserRoles"); 209 | 210 | migrationBuilder.DropTable( 211 | name: "AspNetUserTokens"); 212 | 213 | migrationBuilder.DropTable( 214 | name: "AspNetRoles"); 215 | 216 | migrationBuilder.DropTable( 217 | name: "AspNetUsers"); 218 | } 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Data/Migrations/20220702220206_Multitenancy.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace MultiTenancyDemo.Data.Migrations 6 | { 7 | public partial class Multitenancy : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "Paises", 13 | columns: table => new 14 | { 15 | Id = table.Column(type: "int", nullable: false) 16 | .Annotation("SqlServer:Identity", "1, 1"), 17 | Nombre = table.Column(type: "nvarchar(max)", nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_Paises", x => x.Id); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "Productos", 26 | columns: table => new 27 | { 28 | Id = table.Column(type: "int", nullable: false) 29 | .Annotation("SqlServer:Identity", "1, 1"), 30 | Nombre = table.Column(type: "nvarchar(max)", nullable: false), 31 | TenantId = table.Column(type: "nvarchar(450)", nullable: false) 32 | }, 33 | constraints: table => 34 | { 35 | table.PrimaryKey("PK_Productos", x => x.Id); 36 | }); 37 | 38 | migrationBuilder.InsertData( 39 | table: "Paises", 40 | columns: new[] { "Id", "Nombre" }, 41 | values: new object[] { 1, "República Dominicana" }); 42 | 43 | migrationBuilder.InsertData( 44 | table: "Paises", 45 | columns: new[] { "Id", "Nombre" }, 46 | values: new object[] { 2, "México" }); 47 | 48 | migrationBuilder.InsertData( 49 | table: "Paises", 50 | columns: new[] { "Id", "Nombre" }, 51 | values: new object[] { 3, "Colombia" }); 52 | 53 | migrationBuilder.CreateIndex( 54 | name: "IX_Productos_TenantId", 55 | table: "Productos", 56 | column: "TenantId"); 57 | } 58 | 59 | protected override void Down(MigrationBuilder migrationBuilder) 60 | { 61 | migrationBuilder.DropTable( 62 | name: "Paises"); 63 | 64 | migrationBuilder.DropTable( 65 | name: "Productos"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Entidades/IEntidadComún.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public interface IEntidadComún 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Entidades/IEntidadTenant.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public interface IEntidadTenant 4 | { 5 | string TenantId { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Entidades/País.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public class País: IEntidadComún 4 | { 5 | public int Id { get; set; } 6 | public string Nombre { get; set; } = null!; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Entidades/Producto.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public class Producto: IEntidadTenant 4 | { 5 | public int Id { get; set; } 6 | public string Nombre { get; set; } = null!; 7 | public string TenantId { get; set; } = null!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class ErrorViewModel 4 | { 5 | public string? RequestId { get; set; } 6 | 7 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 8 | } 9 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Models/HomeIndexViewModel.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyDemo.Entidades; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class HomeIndexViewModel 6 | { 7 | public IEnumerable Productos { get; set; } = new List(); 8 | public IEnumerable Países { get; set; } = new List(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Models/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class LoginViewModel 6 | { 7 | [Required(ErrorMessage = "El campo {0} es requerido")] 8 | [EmailAddress(ErrorMessage = "El campo debe ser un correo electrónico válido")] 9 | public string Email { get; set; } = null!; 10 | 11 | [Required(ErrorMessage = "El campo {0} es requerido")] 12 | [DataType(DataType.Password)] 13 | public string Password { get; set; } = null!; 14 | 15 | [Display(Name = "Recuérdame")] 16 | public bool Recuerdame { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Models/RegistroViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class RegistroViewModel 6 | { 7 | [Required] 8 | [EmailAddress] 9 | public string Email { get; set; } = null!; 10 | [Required] 11 | [DataType(DataType.Password)] 12 | public string Password { get; set; } = null!; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/MultiTenancyDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | aspnet-MultiTenancyDemo-6F6DEF8F-D17E-4A52-9AB0-DC8D1394E21C 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Data; 4 | using MultiTenancyDemo.Servicios; 5 | 6 | var builder = WebApplication.CreateBuilder(args); 7 | 8 | // Add services to the container. 9 | var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); 10 | builder.Services.AddDbContext(options => 11 | options.UseSqlServer(connectionString)); 12 | builder.Services.AddDatabaseDeveloperPageExceptionFilter(); 13 | 14 | builder.Services.AddDefaultIdentity(options => 15 | options.SignIn.RequireConfirmedAccount = false) 16 | .AddEntityFrameworkStores(); 17 | builder.Services.AddControllersWithViews(); 18 | 19 | builder.Services.AddTransient(); 20 | 21 | var app = builder.Build(); 22 | 23 | // Configure the HTTP request pipeline. 24 | if (app.Environment.IsDevelopment()) 25 | { 26 | app.UseMigrationsEndPoint(); 27 | } 28 | else 29 | { 30 | app.UseExceptionHandler("/Home/Error"); 31 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 32 | app.UseHsts(); 33 | } 34 | 35 | app.UseHttpsRedirection(); 36 | app.UseStaticFiles(); 37 | 38 | app.UseRouting(); 39 | 40 | app.UseAuthentication(); 41 | app.UseAuthorization(); 42 | 43 | app.MapControllerRoute( 44 | name: "default", 45 | pattern: "{controller=Home}/{action=Index}/{id?}"); 46 | app.MapRazorPages(); 47 | 48 | app.Run(); 49 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:44433", 7 | "sslPort": 44366 8 | } 9 | }, 10 | "profiles": { 11 | "MultiTenancyDemo": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "applicationUrl": "https://localhost:7201;http://localhost:5201", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "IIS Express": { 21 | "commandName": "IISExpress", 22 | "launchBrowser": true, 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql.local", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Servicios/Constantes.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public static class Constantes 4 | { 5 | public const string ClaimTenantId = "tenantId"; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Servicios/ExtensionesTipo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using MultiTenancyDemo.Entidades; 3 | 4 | namespace MultiTenancyDemo.Servicios 5 | { 6 | public static class ExtensionesTipo 7 | { 8 | public static bool DebeSaltarValidaciónTenant(this Type t) 9 | { 10 | var booleanos = new List() 11 | { 12 | t.IsAssignableFrom(typeof(IdentityRole)), 13 | t.IsAssignableFrom(typeof(IdentityRoleClaim)), 14 | t.IsAssignableFrom(typeof(IdentityUser)), 15 | t.IsAssignableFrom(typeof(IdentityUserLogin)), 16 | t.IsAssignableFrom(typeof(IdentityUserRole)), 17 | t.IsAssignableFrom(typeof(IdentityUserToken)), 18 | t.IsAssignableFrom(typeof(IdentityUserClaim)), 19 | typeof(IEntidadComún).IsAssignableFrom(t) 20 | }; 21 | 22 | var resultado = booleanos.Aggregate((b1, b2) => b1 || b2); 23 | 24 | return resultado; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Servicios/IServicioTenant.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public interface IServicioTenant 4 | { 5 | string ObtenerTenant(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Servicios/ServicioTenant.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication; 2 | using Microsoft.AspNetCore.Authentication.Cookies; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace MultiTenancyDemo.Servicios 6 | { 7 | public class ServicioTenant : IServicioTenant 8 | { 9 | private readonly IHttpContextAccessor httpContextAccessor; 10 | 11 | public ServicioTenant(IHttpContextAccessor httpContextAccessor) 12 | { 13 | this.httpContextAccessor = httpContextAccessor; 14 | } 15 | 16 | public string ObtenerTenant() 17 | { 18 | var httpContext = httpContextAccessor.HttpContext; 19 | 20 | if (httpContext is null) 21 | { 22 | return string.Empty; 23 | } 24 | 25 | var authTicket = DecryptAuthCookie(httpContext); 26 | 27 | if (authTicket is null) 28 | { 29 | return string.Empty; 30 | } 31 | 32 | var claimTenant = authTicket.Principal.Claims.FirstOrDefault(x => x.Type == Constantes.ClaimTenantId); 33 | 34 | if (claimTenant is null) 35 | { 36 | return string.Empty; 37 | } 38 | 39 | return claimTenant.Value; 40 | } 41 | 42 | private static AuthenticationTicket? DecryptAuthCookie(HttpContext httpContext) 43 | { 44 | var opt = httpContext.RequestServices 45 | .GetRequiredService>() 46 | .Get("Identity.Application"); 47 | 48 | var cookie = opt.CookieManager.GetRequestCookie(httpContext, opt.Cookie.Name!); 49 | 50 | return opt.TicketDataFormat.Unprotect(cookie); 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model HomeIndexViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Home Page"; 5 | } 6 | 7 |
8 |

Welcome

9 |

Learn about building Web apps with ASP.NET Core.

10 |
11 | 12 |
13 |

Claims

14 | @if (User.Identity is not null && User.Identity.IsAuthenticated) 15 | { 16 | @foreach (var claim in User.Claims) 17 | { 18 |

@claim.Type - @claim.Value

19 | } 20 | } 21 |
22 | 23 |
24 |

Productos

25 | @if (User.Identity is not null && User.Identity.IsAuthenticated) 26 | { 27 | 28 |
29 |
30 | 31 |
32 | 33 |
34 | 35 |
36 |
37 | 38 |
    39 | @foreach (var producto in Model.Productos) 40 | { 41 |
  • @producto.Nombre
  • 42 | } 43 |
44 | } 45 | else 46 | { 47 |

Logueate para que puedas crear y visualizar productos!

48 | } 49 | 50 |
51 | 52 |
53 |

Países

54 |
    55 | @foreach (var país in Model.Países) 56 | { 57 |
  • @país.Nombre
  • 58 | } 59 |
60 |
61 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

@ViewData["Title"]

5 | 6 |

Use this page to detail your site's privacy policy.

7 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

Error.

7 |

An error occurred while processing your request.

8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

12 | Request ID: @Model.RequestId 13 |

14 | } 15 | 16 |

Development Mode

17 |

18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

20 |

21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

26 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - MultiTenancyDemo 7 | 8 | 9 | 10 | 11 | 12 |
13 | 33 |
34 |
35 |
36 | @RenderBody() 37 |
38 |
39 | 40 |
41 |
42 | © 2022 - MultiTenancyDemo - Privacy 43 |
44 |
45 | 46 | 47 | 48 | @await RenderSectionAsync("Scripts", required: false) 49 | 50 | 51 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Shared/_Layout.cshtml.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | a { 11 | color: #0077cc; 12 | } 13 | 14 | .btn-primary { 15 | color: #fff; 16 | background-color: #1b6ec2; 17 | border-color: #1861ac; 18 | } 19 | 20 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 21 | color: #fff; 22 | background-color: #1b6ec2; 23 | border-color: #1861ac; 24 | } 25 | 26 | .border-top { 27 | border-top: 1px solid #e5e5e5; 28 | } 29 | .border-bottom { 30 | border-bottom: 1px solid #e5e5e5; 31 | } 32 | 33 | .box-shadow { 34 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 35 | } 36 | 37 | button.accept-policy { 38 | font-size: 1rem; 39 | line-height: inherit; 40 | } 41 | 42 | .footer { 43 | position: absolute; 44 | bottom: 0; 45 | width: 100%; 46 | white-space: nowrap; 47 | line-height: 60px; 48 | } 49 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @inject SignInManager SignInManager 3 | @inject UserManager UserManager 4 | 5 | 28 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Usuarios/Login.cshtml: -------------------------------------------------------------------------------- 1 | @model LoginViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Login"; 5 | } 6 | 7 |

Login

8 | 9 |
10 |
11 |
12 |
13 | 14 |
15 | 16 | 17 | 18 |
19 | 20 |
21 | 22 | 23 | 24 |
25 | 26 |
27 | 28 | 29 |
30 | 31 | 32 | Crear una nueva cuenta 33 |
34 | 35 |
36 |
37 | 38 | 39 | @section Scripts { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/Usuarios/Registro.cshtml: -------------------------------------------------------------------------------- 1 | @model RegistroViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Registro"; 5 | } 6 | 7 |

Regístrate

8 | 9 |
10 |
11 |
12 |
13 | 14 |
15 | 16 | 17 | 18 |
19 | 20 |
21 | 22 | 23 | 24 |
25 | 26 | 27 | Deseo Loguearme 28 | 29 |
30 |
31 |
32 | 33 | 34 | 35 | @section Scripts { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo 2 | @using MultiTenancyDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-MultiTenancyDemo-6F6DEF8F-D17E-4A52-9AB0-DC8D1394E21C;Trusted_Connection=True;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft.AspNetCore": "Warning" 9 | } 10 | }, 11 | "AllowedHosts": "*" 12 | } 13 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-size: 14px; 3 | } 4 | 5 | @media (min-width: 768px) { 6 | html { 7 | font-size: 16px; 8 | } 9 | } 10 | 11 | html { 12 | position: relative; 13 | min-height: 100%; 14 | } 15 | 16 | body { 17 | margin-bottom: 60px; 18 | } -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavilanch/aspnetcoremultitenancy/d703d9a05ee3d263dc96873ccdf2547144b4f05e/Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2021 Twitter, Inc. 4 | Copyright (c) 2011-2021 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-left: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-left: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr /* rtl:ignore */; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: left; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: left; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: left; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | /* rtl:raw: 382 | [type="tel"], 383 | [type="url"], 384 | [type="email"], 385 | [type="number"] { 386 | direction: ltr; 387 | } 388 | */ 389 | ::-webkit-search-decoration { 390 | -webkit-appearance: none; 391 | } 392 | 393 | ::-webkit-color-swatch-wrapper { 394 | padding: 0; 395 | } 396 | 397 | ::file-selector-button { 398 | font: inherit; 399 | } 400 | 401 | ::-webkit-file-upload-button { 402 | font: inherit; 403 | -webkit-appearance: button; 404 | } 405 | 406 | output { 407 | display: inline-block; 408 | } 409 | 410 | iframe { 411 | border: 0; 412 | } 413 | 414 | summary { 415 | display: list-item; 416 | cursor: pointer; 417 | } 418 | 419 | progress { 420 | vertical-align: baseline; 421 | } 422 | 423 | [hidden] { 424 | display: none !important; 425 | } 426 | 427 | /*# sourceMappingURL=bootstrap-reboot.css.map */ -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.min.css.map */ -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-right: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-right: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr ; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: right; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: right; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: right; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | [type="tel"], 382 | [type="url"], 383 | [type="email"], 384 | [type="number"] { 385 | direction: ltr; 386 | } 387 | ::-webkit-search-decoration { 388 | -webkit-appearance: none; 389 | } 390 | 391 | ::-webkit-color-swatch-wrapper { 392 | padding: 0; 393 | } 394 | 395 | ::file-selector-button { 396 | font: inherit; 397 | } 398 | 399 | ::-webkit-file-upload-button { 400 | font: inherit; 401 | -webkit-appearance: button; 402 | } 403 | 404 | output { 405 | display: inline-block; 406 | } 407 | 408 | iframe { 409 | border: 0; 410 | } 411 | 412 | summary { 413 | display: list-item; 414 | cursor: pointer; 415 | } 416 | 417 | progress { 418 | vertical-align: baseline; 419 | } 420 | 421 | [hidden] { 422 | display: none !important; 423 | } 424 | /*# sourceMappingURL=bootstrap-reboot.rtl.css.map */ -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-right:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-right:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:right}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:right;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:right}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}[type=email],[type=number],[type=tel],[type=url]{direction:ltr}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.rtl.min.css.map */ -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery-validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); 6 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Parte 1 - Usuario por Tenant/MultiTenancyDemo/wwwroot/lib/jquery/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright JS Foundation and other contributors, https://js.foundation/ 2 | 3 | This software consists of voluntary contributions made by many 4 | individuals. For exact contribution history, see the revision history 5 | available at https://github.com/jquery/jquery 6 | 7 | The following license applies to all parts of this software except as 8 | documented below: 9 | 10 | ==== 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the 14 | "Software"), to deal in the Software without restriction, including 15 | without limitation the rights to use, copy, modify, merge, publish, 16 | distribute, sublicense, and/or sell copies of the Software, and to 17 | permit persons to whom the Software is furnished to do so, subject to 18 | the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be 21 | included in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | ==== 32 | 33 | All files located in the node_modules and external directories are 34 | externally maintained libraries used by this software which have their 35 | own licenses; we recommend you read them, as their terms may differ from 36 | the terms above. 37 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.2.32526.322 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiTenancyDemo", "MultiTenancyDemo\MultiTenancyDemo.csproj", "{E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}" 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 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {E3E7BF5C-E38B-4FCF-ABCE-82B8DF2C8C77}.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 = {019731A0-4136-42A5-BC39-546654CC48D9} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Areas/Identity/Pages/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "/Views/Shared/_Layout.cshtml"; 3 | } 4 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Controllers/EmpresasController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.EntityFrameworkCore; 4 | using MultiTenancyDemo.Data; 5 | using MultiTenancyDemo.Entidades; 6 | using MultiTenancyDemo.Models; 7 | using MultiTenancyDemo.Servicios; 8 | 9 | namespace MultiTenancyDemo.Controllers 10 | { 11 | [Authorize] 12 | public class EmpresasController : Controller 13 | { 14 | private readonly ApplicationDbContext context; 15 | private readonly IServicioUsuario servicioUsuario; 16 | private readonly IServicioCambioTenant servicioCambioTenant; 17 | 18 | public EmpresasController(ApplicationDbContext context, 19 | IServicioUsuario servicioUsuario, 20 | IServicioCambioTenant servicioCambioTenant) 21 | { 22 | this.context = context; 23 | this.servicioUsuario = servicioUsuario; 24 | this.servicioCambioTenant = servicioCambioTenant; 25 | } 26 | 27 | public IActionResult Crear() 28 | { 29 | return View(); 30 | } 31 | 32 | [HttpPost] 33 | public async Task Crear(CrearEmpresa crearEmpresa) 34 | { 35 | if (!ModelState.IsValid) 36 | { 37 | return View(crearEmpresa); 38 | } 39 | 40 | var empresa = new Empresa 41 | { 42 | Nombre = crearEmpresa.Nombre 43 | }; 44 | 45 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 46 | empresa.UsuarioCreacionId = usuarioId; 47 | context.Add(empresa); 48 | await context.SaveChangesAsync(); 49 | 50 | // Le damos todos los permisos al usuario que crea la app. 51 | var usuarioEmpresaPermisos = new List(); 52 | 53 | foreach (var permiso in Enum.GetValues()) 54 | { 55 | usuarioEmpresaPermisos.Add(new EmpresaUsuarioPermiso 56 | { 57 | EmpresaId = empresa.Id, 58 | UsuarioId = usuarioId, 59 | Permiso = permiso 60 | }); 61 | } 62 | 63 | context.AddRange(usuarioEmpresaPermisos); 64 | await context.SaveChangesAsync(); 65 | 66 | await servicioCambioTenant.ReemplazarTenant(empresa.Id, usuarioId); 67 | 68 | // Redirigir al usuario al home. 69 | return RedirectToAction("Index", "Home"); 70 | } 71 | 72 | public async Task Cambiar() 73 | { 74 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 75 | var empresas = await context.EmpresasUsuariosPermisos 76 | .Include(x => x.Empresa) 77 | .Where(x => x.UsuarioId == usuarioId) 78 | .Select(x => x.Empresa!).Distinct().ToListAsync(); 79 | 80 | return View(empresas); 81 | } 82 | 83 | [HttpPost] 84 | public async Task Cambiar(Guid id) 85 | { 86 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 87 | await servicioCambioTenant.ReemplazarTenant(id, usuarioId); 88 | return RedirectToAction("Index", "Home"); 89 | } 90 | 91 | 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Data; 4 | using MultiTenancyDemo.Entidades; 5 | using MultiTenancyDemo.Models; 6 | using MultiTenancyDemo.Seguridad; 7 | using System.Diagnostics; 8 | 9 | namespace MultiTenancyDemo.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | private readonly ILogger _logger; 14 | private readonly ApplicationDbContext context; 15 | 16 | public HomeController(ILogger logger, 17 | ApplicationDbContext context) 18 | { 19 | _logger = logger; 20 | this.context = context; 21 | } 22 | 23 | public async Task Index() 24 | { 25 | var modelo = await ConstruirModeloHomeIndex(); 26 | return View(modelo); 27 | } 28 | 29 | [HttpPost] 30 | [TienePermiso(Permisos.Productos_Crear)] 31 | public async Task Index(Producto producto) 32 | { 33 | context.Add(producto); 34 | await context.SaveChangesAsync(); 35 | var modelo = await ConstruirModeloHomeIndex(); 36 | return View(modelo); 37 | } 38 | 39 | 40 | private async Task ConstruirModeloHomeIndex() 41 | { 42 | var productos = await context.Productos.ToListAsync(); 43 | var paises = await context.Paises.ToListAsync(); 44 | 45 | var modelo = new HomeIndexViewModel(); 46 | modelo.Productos = productos; 47 | modelo.Países = paises; 48 | return modelo; 49 | } 50 | 51 | 52 | public IActionResult Privacy() 53 | { 54 | return View(); 55 | } 56 | 57 | [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] 58 | public IActionResult Error() 59 | { 60 | return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Controllers/PermisosController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.EntityFrameworkCore; 4 | using MultiTenancyDemo.Data; 5 | using MultiTenancyDemo.Entidades; 6 | using MultiTenancyDemo.Models; 7 | using MultiTenancyDemo.Seguridad; 8 | using MultiTenancyDemo.Servicios; 9 | using System.ComponentModel.DataAnnotations; 10 | 11 | namespace MultiTenancyDemo.Controllers 12 | { 13 | [Authorize] 14 | public class PermisosController : Controller 15 | { 16 | private readonly ApplicationDbContext context; 17 | private readonly IServicioTenant servicioTenant; 18 | 19 | public PermisosController(ApplicationDbContext context, 20 | IServicioTenant servicioTenant) 21 | { 22 | this.context = context; 23 | this.servicioTenant = servicioTenant; 24 | } 25 | 26 | [TienePermiso(Permisos.Permisos_Leer)] 27 | public async Task Index() 28 | { 29 | var tenantId = new Guid(servicioTenant.ObtenerTenant()); 30 | var modelo = await context.Empresas. 31 | Include(x => x.EmpresaUsuariosPermisos).ThenInclude(x => x.Usuario) 32 | .Where(x => x.Id == tenantId) 33 | .Select(x => new IndexPermisosDTO 34 | { 35 | NombreEmpresa = x.Nombre, 36 | Empleados = x.EmpresaUsuariosPermisos.Select(y => new UsuarioDTO 37 | { 38 | Email = y.Usuario!.Email 39 | }).Distinct() 40 | }).FirstOrDefaultAsync(); 41 | 42 | return View(modelo); 43 | 44 | } 45 | 46 | [TienePermiso(Permisos.Permisos_Leer)] 47 | public async Task Administrar(string email) 48 | { 49 | var tenantId = new Guid(servicioTenant.ObtenerTenant()); 50 | var usuarioId = await context.Users 51 | .Where(x => x.Email == email).Select(x => x.Id).FirstOrDefaultAsync(); 52 | 53 | if (usuarioId is null) 54 | { 55 | return RedirectToAction("Index", "Permisos"); 56 | } 57 | 58 | var permisos = await context.EmpresasUsuariosPermisos 59 | .Where(x => x.EmpresaId == tenantId && x.UsuarioId == usuarioId 60 | && x.Permiso != Permisos.Nulo).ToListAsync(); 61 | 62 | var permisosUsuarioDiccionario = permisos.ToDictionary(x => x.Permiso); 63 | 64 | var modelo = new AdministrarPermisosDTO(); 65 | modelo.UsuarioId = usuarioId; 66 | modelo.Email = email; 67 | 68 | foreach (var permiso in Enum.GetValues()) 69 | { 70 | var campo = typeof(Permisos).GetField(permiso.ToString())!; 71 | var esconder = campo.IsDefined(typeof(EsconderAttribute), false); 72 | 73 | if (esconder) 74 | { 75 | continue; 76 | } 77 | 78 | var descripcion = permiso.ToString(); 79 | 80 | if (campo.IsDefined(typeof(DisplayAttribute), false)) 81 | { 82 | var displayAttr = (DisplayAttribute)Attribute 83 | .GetCustomAttribute(campo, typeof(DisplayAttribute))!; 84 | descripcion = displayAttr.Description; 85 | } 86 | 87 | modelo.Permisos.Add(new PermisoUsuarioDTO() 88 | { 89 | Descripcion = descripcion, 90 | Permiso = permiso, 91 | LoTiene = permisosUsuarioDiccionario.ContainsKey(permiso) 92 | }); 93 | 94 | } 95 | 96 | return View(modelo); 97 | 98 | } 99 | 100 | [TienePermiso(Permisos.Permisos_Modificar)] 101 | [HttpPost] 102 | public async Task Administrar(AdministrarPermisosDTO modelo) 103 | { 104 | var tenantId = new Guid(servicioTenant.ObtenerTenant()); 105 | 106 | // Siempre agregamos el permiso por defecto. 107 | modelo.Permisos.Add(new PermisoUsuarioDTO() 108 | { LoTiene = true, Permiso = Permisos.Nulo }); 109 | 110 | // Borramos todos los permisos de la persona 111 | await context.Database 112 | .ExecuteSqlInterpolatedAsync($@"DELETE EmpresasUsuariosPermisos 113 | WHERE UsuarioId = {modelo.UsuarioId} AND EmpresaId = {tenantId}"); 114 | 115 | // Filtramos los permisos a agregar 116 | var permisosFiltrados = modelo.Permisos 117 | .Where(x => x.LoTiene).Select(x => new EmpresaUsuarioPermiso 118 | { 119 | EmpresaId = tenantId, 120 | UsuarioId = modelo.UsuarioId, 121 | Permiso = x.Permiso 122 | }); 123 | 124 | // Agregamos los permisos a la tabla 125 | context.AddRange(permisosFiltrados); 126 | await context.SaveChangesAsync(); 127 | 128 | return RedirectToAction("Index"); 129 | } 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Controllers/UsuariosController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.EntityFrameworkCore; 4 | using MultiTenancyDemo.Data; 5 | using MultiTenancyDemo.Models; 6 | using MultiTenancyDemo.Servicios; 7 | using System.Security.Claims; 8 | 9 | namespace MultiTenancyDemo.Controllers 10 | { 11 | public class UsuariosController : Controller 12 | { 13 | private readonly UserManager userManager; 14 | private readonly SignInManager signInManager; 15 | private readonly ApplicationDbContext context; 16 | private readonly IServicioCambioTenant servicioCambioTenant; 17 | 18 | public UsuariosController(UserManager userManager, 19 | SignInManager signInManager, 20 | ApplicationDbContext context, 21 | IServicioCambioTenant servicioCambioTenant) 22 | { 23 | this.userManager = userManager; 24 | this.signInManager = signInManager; 25 | this.context = context; 26 | this.servicioCambioTenant = servicioCambioTenant; 27 | } 28 | 29 | 30 | public IActionResult Registro() 31 | { 32 | return View(); 33 | } 34 | 35 | [HttpPost] 36 | public async Task Registro(RegistroViewModel modelo) 37 | { 38 | if (!ModelState.IsValid) 39 | { 40 | return View(modelo); 41 | } 42 | 43 | var usuario = new IdentityUser() { Email = modelo.Email, UserName = modelo.Email }; 44 | 45 | var resultado = await userManager.CreateAsync(usuario, password: modelo.Password); 46 | 47 | if (resultado.Succeeded) 48 | { 49 | await signInManager.SignInAsync(usuario, isPersistent: true); 50 | return RedirectToAction("Index", "Home"); 51 | } 52 | else 53 | { 54 | foreach (var error in resultado.Errors) 55 | { 56 | ModelState.AddModelError(string.Empty, error.Description); 57 | } 58 | 59 | return View(modelo); 60 | } 61 | 62 | } 63 | 64 | 65 | [HttpGet] 66 | public IActionResult Login() 67 | { 68 | return View(); 69 | } 70 | 71 | [HttpPost] 72 | public async Task Login(LoginViewModel modelo) 73 | { 74 | if (!ModelState.IsValid) 75 | { 76 | return View(modelo); 77 | } 78 | 79 | var resultado = await signInManager.PasswordSignInAsync(modelo.Email, 80 | modelo.Password, modelo.Recuerdame, lockoutOnFailure: false); 81 | 82 | if (resultado.Succeeded) 83 | { 84 | var usuario = await userManager.FindByEmailAsync(modelo.Email); 85 | var empresasVinculadas = await context.EmpresasUsuariosPermisos 86 | .Where(x => x.UsuarioId == usuario.Id && x.Permiso == Entidades.Permisos.Nulo) 87 | .OrderBy(x => x.EmpresaId) 88 | .Take(2) 89 | .Select(x => x.EmpresaId).ToListAsync(); 90 | 91 | if (empresasVinculadas.Count == 0) 92 | { 93 | return RedirectToAction("Index", "Home"); 94 | } 95 | else if (empresasVinculadas.Count == 1) 96 | { 97 | await servicioCambioTenant.ReemplazarTenant(empresasVinculadas[0], usuario.Id); 98 | return RedirectToAction("Index", "Home"); 99 | } 100 | else 101 | { 102 | return RedirectToAction("Cambiar", "Empresas"); 103 | } 104 | } 105 | else 106 | { 107 | ModelState.AddModelError(string.Empty, "Nombre de usuario o password incorrecto."); 108 | return View(modelo); 109 | } 110 | } 111 | 112 | 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Controllers/VinculacionesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.EntityFrameworkCore; 4 | using MultiTenancyDemo.Data; 5 | using MultiTenancyDemo.Entidades; 6 | using MultiTenancyDemo.Models; 7 | using MultiTenancyDemo.Servicios; 8 | 9 | namespace MultiTenancyDemo.Controllers 10 | { 11 | [Authorize] 12 | public class VinculacionesController : Controller 13 | { 14 | private readonly ApplicationDbContext context; 15 | private readonly IServicioUsuario servicioUsuario; 16 | private readonly IServicioTenant servicioTenant; 17 | 18 | public VinculacionesController(ApplicationDbContext context, 19 | IServicioUsuario servicioUsuario, IServicioTenant servicioTenant) 20 | { 21 | this.context = context; 22 | this.servicioUsuario = servicioUsuario; 23 | this.servicioTenant = servicioTenant; 24 | } 25 | 26 | public async Task Index() 27 | { 28 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 29 | return await RetornarVinculacionesPendientes(usuarioId); 30 | } 31 | 32 | private async Task RetornarVinculacionesPendientes(string usuarioId) 33 | { 34 | var vinculacionesPendientes = await context.Vinculaciones 35 | .Include(x => x.Empresa) 36 | .Where(x => x.Estatus == VinculacionEstatus.Pendiente 37 | && x.UsuarioId == usuarioId).ToListAsync(); 38 | 39 | return View(vinculacionesPendientes); 40 | } 41 | 42 | [HttpPost] 43 | public async Task Index(Guid empresaId, 44 | VinculacionEstatus vinculacionEstatus) 45 | { 46 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 47 | var vinculacion = await context.Vinculaciones 48 | .FirstOrDefaultAsync(x => x.UsuarioId == usuarioId 49 | && x.EmpresaId == empresaId 50 | && x.Estatus == VinculacionEstatus.Pendiente); 51 | 52 | if (vinculacion is null) 53 | { 54 | ModelState.AddModelError("", "Ha habido un error: vinculación no encontrada"); 55 | return await RetornarVinculacionesPendientes(usuarioId); 56 | } 57 | 58 | if (vinculacionEstatus == VinculacionEstatus.Aceptada) 59 | { 60 | var permisoNulo = new EmpresaUsuarioPermiso() 61 | { 62 | Permiso = Permisos.Nulo, 63 | EmpresaId = empresaId, 64 | UsuarioId = usuarioId 65 | }; 66 | 67 | context.Add(permisoNulo); 68 | } 69 | 70 | vinculacion.Estatus = vinculacionEstatus; 71 | await context.SaveChangesAsync(); 72 | 73 | return RedirectToAction("Cambiar", "Empresas"); 74 | } 75 | 76 | public async Task Vincular() 77 | { 78 | var empresaId = servicioTenant.ObtenerTenant(); 79 | 80 | if (string.IsNullOrEmpty(empresaId)) 81 | { 82 | return RedirectToAction("Index", "Home"); 83 | } 84 | 85 | var empresaIdGuid = new Guid(empresaId); 86 | 87 | var empresa = await context 88 | .Empresas.FirstOrDefaultAsync(x => x.Id == empresaIdGuid); 89 | 90 | if (empresa is null) 91 | { 92 | return RedirectToAction("Index", "Home"); 93 | } 94 | 95 | var modelo = new VincularUsuario 96 | { 97 | EmpresaId = empresa.Id, 98 | NombreEmpresa = empresa.Nombre 99 | }; 100 | 101 | return View(modelo); 102 | 103 | 104 | } 105 | 106 | [HttpPost] 107 | public async Task Vincular(VincularUsuario modelo) 108 | { 109 | if (!ModelState.IsValid) 110 | { 111 | return View(modelo); 112 | } 113 | 114 | var usuarioAVincular = await context.Users 115 | .FirstOrDefaultAsync(x => x.Email == modelo.EmailUsuario); 116 | 117 | if (usuarioAVincular is null) 118 | { 119 | ModelState.AddModelError(nameof(modelo.EmailUsuario), "No existe un usuario con ese email"); 120 | return View(modelo); 121 | } 122 | 123 | var vinculacion = new Vinculacion 124 | { 125 | EmpresaId = modelo.EmpresaId, 126 | UsuarioId = usuarioAVincular.Id, 127 | Estatus = VinculacionEstatus.Pendiente, 128 | FechaCreacion = DateTime.UtcNow 129 | }; 130 | 131 | context.Add(vinculacion); 132 | await context.SaveChangesAsync(); 133 | return RedirectToAction("UsuarioVinculado"); 134 | } 135 | 136 | public IActionResult UsuarioVinculado() 137 | { 138 | return View(); 139 | } 140 | 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Data/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Entidades; 4 | using MultiTenancyDemo.Servicios; 5 | using System.Linq.Expressions; 6 | using System.Reflection; 7 | 8 | namespace MultiTenancyDemo.Data 9 | { 10 | public class ApplicationDbContext : IdentityDbContext 11 | { 12 | private string tenantId; 13 | 14 | public ApplicationDbContext(DbContextOptions options, 15 | IServicioTenant servicioTenant) 16 | : base(options) 17 | { 18 | tenantId = servicioTenant.ObtenerTenant(); 19 | } 20 | 21 | public override Task SaveChangesAsync(CancellationToken cancellationToken = default) 22 | { 23 | foreach (var item in ChangeTracker.Entries().Where(e => e.State == EntityState.Added 24 | && e.Entity is IEntidadTenant)) 25 | { 26 | if (string.IsNullOrEmpty(tenantId)) 27 | { 28 | throw new Exception("TenantId no encontrado al momento de crear el registro."); 29 | } 30 | 31 | var entidad = item.Entity as IEntidadTenant; 32 | entidad!.TenantId = tenantId; 33 | } 34 | 35 | return base.SaveChangesAsync(cancellationToken); 36 | } 37 | 38 | 39 | protected override void OnModelCreating(ModelBuilder builder) 40 | { 41 | base.OnModelCreating(builder); 42 | 43 | builder.Entity() 44 | .HasKey(x => new { x.EmpresaId, x.UsuarioId, x.Permiso }); 45 | 46 | builder.Entity().HasData(new País[] 47 | { 48 | new País{Id = 1, Nombre = "República Dominicana"}, 49 | new País{Id = 2, Nombre = "México"}, 50 | new País{Id = 3, Nombre = "Colombia"} 51 | }); 52 | 53 | 54 | foreach (var entidad in builder.Model.GetEntityTypes()) 55 | { 56 | var tipo = entidad.ClrType; 57 | 58 | if (typeof(IEntidadTenant).IsAssignableFrom(tipo)) 59 | { 60 | var método = typeof(ApplicationDbContext) 61 | .GetMethod(nameof(ArmarFiltroGlobalTenant), 62 | BindingFlags.NonPublic | BindingFlags.Static 63 | )?.MakeGenericMethod(tipo); 64 | 65 | var filtro = método?.Invoke(null, new object[] { this })!; 66 | entidad.SetQueryFilter((LambdaExpression)filtro); 67 | entidad.AddIndex(entidad.FindProperty(nameof(IEntidadTenant.TenantId))!); 68 | } 69 | else if (tipo.DebeSaltarValidaciónTenant()) 70 | { 71 | continue; 72 | } 73 | else 74 | { 75 | throw new Exception($"La entidad {entidad} no ha sido marcada como tenant o común"); 76 | } 77 | } 78 | } 79 | 80 | private static LambdaExpression ArmarFiltroGlobalTenant( 81 | ApplicationDbContext context) 82 | where TEntidad : class, IEntidadTenant 83 | { 84 | Expression> filtro = x => x.TenantId == context.tenantId; 85 | return filtro; 86 | } 87 | 88 | public DbSet Productos => Set(); 89 | public DbSet Paises => Set(); 90 | public DbSet Empresas => Set(); 91 | public DbSet EmpresasUsuariosPermisos => Set(); 92 | public DbSet Vinculaciones => Set(); 93 | 94 | 95 | } 96 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Data/Migrations/20220702220206_Multitenancy.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace MultiTenancyDemo.Data.Migrations 6 | { 7 | public partial class Multitenancy : Migration 8 | { 9 | protected override void Up(MigrationBuilder migrationBuilder) 10 | { 11 | migrationBuilder.CreateTable( 12 | name: "Paises", 13 | columns: table => new 14 | { 15 | Id = table.Column(type: "int", nullable: false) 16 | .Annotation("SqlServer:Identity", "1, 1"), 17 | Nombre = table.Column(type: "nvarchar(max)", nullable: false) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_Paises", x => x.Id); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "Productos", 26 | columns: table => new 27 | { 28 | Id = table.Column(type: "int", nullable: false) 29 | .Annotation("SqlServer:Identity", "1, 1"), 30 | Nombre = table.Column(type: "nvarchar(max)", nullable: false), 31 | TenantId = table.Column(type: "nvarchar(450)", nullable: false) 32 | }, 33 | constraints: table => 34 | { 35 | table.PrimaryKey("PK_Productos", x => x.Id); 36 | }); 37 | 38 | migrationBuilder.InsertData( 39 | table: "Paises", 40 | columns: new[] { "Id", "Nombre" }, 41 | values: new object[] { 1, "República Dominicana" }); 42 | 43 | migrationBuilder.InsertData( 44 | table: "Paises", 45 | columns: new[] { "Id", "Nombre" }, 46 | values: new object[] { 2, "México" }); 47 | 48 | migrationBuilder.InsertData( 49 | table: "Paises", 50 | columns: new[] { "Id", "Nombre" }, 51 | values: new object[] { 3, "Colombia" }); 52 | 53 | migrationBuilder.CreateIndex( 54 | name: "IX_Productos_TenantId", 55 | table: "Productos", 56 | column: "TenantId"); 57 | } 58 | 59 | protected override void Down(MigrationBuilder migrationBuilder) 60 | { 61 | migrationBuilder.DropTable( 62 | name: "Paises"); 63 | 64 | migrationBuilder.DropTable( 65 | name: "Productos"); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Data/Migrations/20220801125621_Empresas.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.EntityFrameworkCore.Migrations; 3 | 4 | #nullable disable 5 | 6 | namespace MultiTenancyDemo.Data.Migrations 7 | { 8 | public partial class Empresas : Migration 9 | { 10 | protected override void Up(MigrationBuilder migrationBuilder) 11 | { 12 | migrationBuilder.CreateTable( 13 | name: "Empresas", 14 | columns: table => new 15 | { 16 | Id = table.Column(type: "uniqueidentifier", nullable: false), 17 | Nombre = table.Column(type: "nvarchar(max)", nullable: false), 18 | UsuarioCreacionId = table.Column(type: "nvarchar(450)", nullable: true) 19 | }, 20 | constraints: table => 21 | { 22 | table.PrimaryKey("PK_Empresas", x => x.Id); 23 | table.ForeignKey( 24 | name: "FK_Empresas_AspNetUsers_UsuarioCreacionId", 25 | column: x => x.UsuarioCreacionId, 26 | principalTable: "AspNetUsers", 27 | principalColumn: "Id"); 28 | }); 29 | 30 | migrationBuilder.CreateTable( 31 | name: "EmpresasUsuariosPermisos", 32 | columns: table => new 33 | { 34 | UsuarioId = table.Column(type: "nvarchar(450)", nullable: false), 35 | EmpresaId = table.Column(type: "uniqueidentifier", nullable: false), 36 | Permiso = table.Column(type: "int", nullable: false) 37 | }, 38 | constraints: table => 39 | { 40 | table.PrimaryKey("PK_EmpresasUsuariosPermisos", x => new { x.EmpresaId, x.UsuarioId, x.Permiso }); 41 | table.ForeignKey( 42 | name: "FK_EmpresasUsuariosPermisos_AspNetUsers_UsuarioId", 43 | column: x => x.UsuarioId, 44 | principalTable: "AspNetUsers", 45 | principalColumn: "Id", 46 | onDelete: ReferentialAction.Cascade); 47 | table.ForeignKey( 48 | name: "FK_EmpresasUsuariosPermisos_Empresas_EmpresaId", 49 | column: x => x.EmpresaId, 50 | principalTable: "Empresas", 51 | principalColumn: "Id", 52 | onDelete: ReferentialAction.Cascade); 53 | }); 54 | 55 | migrationBuilder.CreateTable( 56 | name: "Vinculaciones", 57 | columns: table => new 58 | { 59 | Id = table.Column(type: "int", nullable: false) 60 | .Annotation("SqlServer:Identity", "1, 1"), 61 | EmpresaId = table.Column(type: "uniqueidentifier", nullable: false), 62 | UsuarioId = table.Column(type: "nvarchar(450)", nullable: false), 63 | Estatus = table.Column(type: "int", nullable: false), 64 | FechaCreacion = table.Column(type: "datetime2", nullable: false) 65 | }, 66 | constraints: table => 67 | { 68 | table.PrimaryKey("PK_Vinculaciones", x => x.Id); 69 | table.ForeignKey( 70 | name: "FK_Vinculaciones_AspNetUsers_UsuarioId", 71 | column: x => x.UsuarioId, 72 | principalTable: "AspNetUsers", 73 | principalColumn: "Id", 74 | onDelete: ReferentialAction.Cascade); 75 | table.ForeignKey( 76 | name: "FK_Vinculaciones_Empresas_EmpresaId", 77 | column: x => x.EmpresaId, 78 | principalTable: "Empresas", 79 | principalColumn: "Id", 80 | onDelete: ReferentialAction.Cascade); 81 | }); 82 | 83 | migrationBuilder.CreateIndex( 84 | name: "IX_Empresas_UsuarioCreacionId", 85 | table: "Empresas", 86 | column: "UsuarioCreacionId"); 87 | 88 | migrationBuilder.CreateIndex( 89 | name: "IX_EmpresasUsuariosPermisos_UsuarioId", 90 | table: "EmpresasUsuariosPermisos", 91 | column: "UsuarioId"); 92 | 93 | migrationBuilder.CreateIndex( 94 | name: "IX_Vinculaciones_EmpresaId", 95 | table: "Vinculaciones", 96 | column: "EmpresaId"); 97 | 98 | migrationBuilder.CreateIndex( 99 | name: "IX_Vinculaciones_UsuarioId", 100 | table: "Vinculaciones", 101 | column: "UsuarioId"); 102 | } 103 | 104 | protected override void Down(MigrationBuilder migrationBuilder) 105 | { 106 | migrationBuilder.DropTable( 107 | name: "EmpresasUsuariosPermisos"); 108 | 109 | migrationBuilder.DropTable( 110 | name: "Vinculaciones"); 111 | 112 | migrationBuilder.DropTable( 113 | name: "Empresas"); 114 | } 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/Empresa.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MultiTenancyDemo.Entidades 4 | { 5 | public class Empresa : IEntidadComún 6 | { 7 | public Guid Id { get; set; } 8 | public string Nombre { get; set; } = null!; 9 | public string? UsuarioCreacionId { get; set; } 10 | public IdentityUser UsuarioCreacion { get; set; } = null!; 11 | public List EmpresaUsuariosPermisos { get; set; } = null!; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/EmpresaUsuarioPermiso.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MultiTenancyDemo.Entidades 4 | { 5 | public class EmpresaUsuarioPermiso: IEntidadComún 6 | { 7 | public string UsuarioId { get; set; } = null!; 8 | public Guid EmpresaId { get; set; } 9 | public Permisos Permiso { get; set; } 10 | public IdentityUser? Usuario { get; set; } 11 | public Empresa? Empresa { get; set; } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/IEntidadComún.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public interface IEntidadComún 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/IEntidadTenant.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public interface IEntidadTenant 4 | { 5 | string TenantId { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/País.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public class País: IEntidadComún 4 | { 5 | public int Id { get; set; } 6 | public string Nombre { get; set; } = null!; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/Permisos.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyDemo.Servicios; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace MultiTenancyDemo.Entidades 5 | { 6 | public enum Permisos 7 | { 8 | [Esconder] 9 | Nulo = 0, // Permiso que todos los usuarios tienen por ser miembros de una empresa. Solo se elimina al desvincular a un usuario de una empresa. 10 | [Display(Description = "Puede crear productos")] 11 | Productos_Crear = 1, 12 | [Display(Description = "Puede leer productos")] 13 | Productos_Leer = 2, 14 | Usuarios_Vincular = 3, 15 | Permisos_Leer = 4, 16 | Permisos_Modificar = 5, 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/Producto.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public class Producto: IEntidadTenant 4 | { 5 | public int Id { get; set; } 6 | public string Nombre { get; set; } = null!; 7 | public string TenantId { get; set; } = null!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/Vinculacion.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MultiTenancyDemo.Entidades 4 | { 5 | public class Vinculacion: IEntidadComún 6 | { 7 | public int Id { get; set; } 8 | public Guid EmpresaId { get; set; } 9 | public string UsuarioId { get; set; } = null!; 10 | public VinculacionEstatus Estatus { get; set; } 11 | public DateTime FechaCreacion { get; set; } 12 | public Empresa Empresa { get; set; } = null!; 13 | public IdentityUser Usuario { get; set; } = null!; 14 | 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Entidades/VinculacionEstatus.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Entidades 2 | { 3 | public enum VinculacionEstatus 4 | { 5 | Pendiente = 1, 6 | Aceptada = 2, 7 | Rechazada = 3 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/AdministrarPermisosDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class AdministrarPermisosDTO 4 | { 5 | public string UsuarioId { get; set; } = null!; 6 | public string? Email { get; set; } 7 | public List Permisos { get; set; } = 8 | new List(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/CrearEmpresa.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class CrearEmpresa 6 | { 7 | [Required(ErrorMessage = "El campo {0} es requerido")] 8 | public string Nombre { get; set; } = null!; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/ErrorViewModel.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class ErrorViewModel 4 | { 5 | public string? RequestId { get; set; } 6 | 7 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 8 | } 9 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/HomeIndexViewModel.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyDemo.Entidades; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class HomeIndexViewModel 6 | { 7 | public IEnumerable Productos { get; set; } = new List(); 8 | public IEnumerable Países { get; set; } = new List(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/IndexPermisosDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class IndexPermisosDTO 4 | { 5 | public string NombreEmpresa { get; set; } = null!; 6 | public IEnumerable Empleados { get; set; } = null!; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/LoginViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class LoginViewModel 6 | { 7 | [Required(ErrorMessage = "El campo {0} es requerido")] 8 | [EmailAddress(ErrorMessage = "El campo debe ser un correo electrónico válido")] 9 | public string Email { get; set; } = null!; 10 | 11 | [Required(ErrorMessage = "El campo {0} es requerido")] 12 | [DataType(DataType.Password)] 13 | public string Password { get; set; } = null!; 14 | 15 | [Display(Name = "Recuérdame")] 16 | public bool Recuerdame { get; set; } 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/PermisoUsuarioDTO.cs: -------------------------------------------------------------------------------- 1 | using MultiTenancyDemo.Entidades; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class PermisoUsuarioDTO 6 | { 7 | public Permisos Permiso { get; set; } 8 | public bool LoTiene { get; set; } 9 | public string? Descripcion { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/RegistroViewModel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MultiTenancyDemo.Models 4 | { 5 | public class RegistroViewModel 6 | { 7 | [Required] 8 | [EmailAddress] 9 | public string Email { get; set; } = null!; 10 | [Required] 11 | [DataType(DataType.Password)] 12 | public string Password { get; set; } = null!; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/UsuarioDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class UsuarioDTO 4 | { 5 | public string Email { get; set; } = null!; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Models/VincularUsuario.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Models 2 | { 3 | public class VincularUsuario 4 | { 5 | public Guid EmpresaId { get; set; } 6 | public string NombreEmpresa { get; set; } = null!; 7 | public string EmailUsuario { get; set; } = null!; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/MultiTenancyDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | aspnet-MultiTenancyDemo-6F6DEF8F-D17E-4A52-9AB0-DC8D1394E21C 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.AspNetCore.Identity; 3 | using Microsoft.EntityFrameworkCore; 4 | using MultiTenancyDemo.Data; 5 | using MultiTenancyDemo.Seguridad; 6 | using MultiTenancyDemo.Servicios; 7 | 8 | var builder = WebApplication.CreateBuilder(args); 9 | 10 | // Add services to the container. 11 | var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); 12 | builder.Services.AddDbContext(options => 13 | options.UseSqlServer(connectionString)); 14 | builder.Services.AddDatabaseDeveloperPageExceptionFilter(); 15 | 16 | builder.Services.AddDefaultIdentity(options => 17 | options.SignIn.RequireConfirmedAccount = false) 18 | .AddEntityFrameworkStores(); 19 | 20 | builder.Services.ConfigureApplicationCookie(options => 21 | { 22 | options.LoginPath = new PathString("/usuarios/login"); 23 | }); 24 | 25 | 26 | builder.Services.AddControllersWithViews(); 27 | 28 | builder.Services.AddTransient(); 29 | builder.Services.AddScoped(); 30 | builder.Services.AddTransient(); 31 | builder.Services.AddSingleton(); 32 | builder.Services.AddScoped(); 33 | 34 | 35 | var app = builder.Build(); 36 | 37 | // Configure the HTTP request pipeline. 38 | if (app.Environment.IsDevelopment()) 39 | { 40 | app.UseMigrationsEndPoint(); 41 | } 42 | else 43 | { 44 | app.UseExceptionHandler("/Home/Error"); 45 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 46 | app.UseHsts(); 47 | } 48 | 49 | app.UseHttpsRedirection(); 50 | app.UseStaticFiles(); 51 | 52 | app.UseRouting(); 53 | 54 | app.UseAuthentication(); 55 | app.UseAuthorization(); 56 | 57 | app.MapControllerRoute( 58 | name: "default", 59 | pattern: "{controller=Home}/{action=Index}/{id?}"); 60 | app.MapRazorPages(); 61 | 62 | app.Run(); 63 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:44433", 7 | "sslPort": 44366 8 | } 9 | }, 10 | "profiles": { 11 | "MultiTenancyDemo": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "applicationUrl": "https://localhost:7201;http://localhost:5201", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "IIS Express": { 21 | "commandName": "IISExpress", 22 | "launchBrowser": true, 23 | "environmentVariables": { 24 | "ASPNETCORE_ENVIRONMENT": "Development" 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql.local", 5 | "connectionId": "ConnectionStrings:DefaultConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Seguridad/IAuthorizationServiceExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using MultiTenancyDemo.Entidades; 3 | using MultiTenancyDemo.Servicios; 4 | using System.Security.Claims; 5 | 6 | namespace MultiTenancyDemo.Seguridad 7 | { 8 | public static class IAuthorizationServiceExtensions 9 | { 10 | public static async Task 11 | TienePermiso(this IAuthorizationService authorizationService, 12 | ClaimsPrincipal user, Permisos permiso) 13 | { 14 | if (!user.Identity!.IsAuthenticated) 15 | { 16 | return false; 17 | } 18 | 19 | var nombrePolitica = $"{Constantes.PrefijoPolitica}{permiso}"; 20 | var resultado = await authorizationService 21 | .AuthorizeAsync(user, nombrePolitica); 22 | return resultado.Succeeded; 23 | } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Seguridad/TienePermisoAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using MultiTenancyDemo.Entidades; 3 | using MultiTenancyDemo.Servicios; 4 | 5 | namespace MultiTenancyDemo.Seguridad 6 | { 7 | public class TienePermisoAttribute: AuthorizeAttribute 8 | { 9 | public TienePermisoAttribute(Permisos permisos) 10 | { 11 | Permisos = permisos; 12 | } 13 | 14 | public Permisos Permisos 15 | { 16 | get 17 | { 18 | // TienePermisoProductos_Crear 19 | if (Enum.TryParse(typeof(Permisos), 20 | Policy!.Substring(Constantes.PrefijoPolitica.Length), 21 | ignoreCase: true, out var permiso)) 22 | { 23 | return (Permisos)permiso!; 24 | } 25 | 26 | return Permisos.Nulo; 27 | } 28 | set 29 | { 30 | Policy = $"{Constantes.PrefijoPolitica}{value.ToString()}"; 31 | } 32 | } 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Seguridad/TienePermisoHandler.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Data; 4 | using MultiTenancyDemo.Servicios; 5 | 6 | namespace MultiTenancyDemo.Seguridad 7 | { 8 | public class TienePermisoHandler: AuthorizationHandler 9 | { 10 | private readonly IServicioTenant servicioTenant; 11 | private readonly IServicioUsuario servicioUsuario; 12 | private readonly ApplicationDbContext dbContext; 13 | 14 | public TienePermisoHandler(IServicioTenant servicioTenant, 15 | IServicioUsuario servicioUsuario, 16 | ApplicationDbContext dbContext) 17 | { 18 | this.servicioTenant = servicioTenant; 19 | this.servicioUsuario = servicioUsuario; 20 | this.dbContext = dbContext; 21 | } 22 | 23 | protected override async Task HandleRequirementAsync( 24 | AuthorizationHandlerContext context, 25 | TienePermisoRequirement requirement) 26 | { 27 | var permiso = requirement.Permiso; 28 | var usuarioId = servicioUsuario.ObtenerUsuarioId(); 29 | var tenantId = new Guid(servicioTenant.ObtenerTenant()); 30 | 31 | var tienePermiso = await dbContext.EmpresasUsuariosPermisos 32 | .AnyAsync(x => x.UsuarioId == usuarioId 33 | && x.EmpresaId == tenantId && x.Permiso == permiso); 34 | 35 | if (tienePermiso) 36 | { 37 | context.Succeed(requirement); 38 | } 39 | } 40 | 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Seguridad/TienePermisoPolicyProvider.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using MultiTenancyDemo.Entidades; 3 | using MultiTenancyDemo.Servicios; 4 | 5 | namespace MultiTenancyDemo.Seguridad 6 | { 7 | public class TienePermisoPolicyProvider : IAuthorizationPolicyProvider 8 | { 9 | public Task GetDefaultPolicyAsync() 10 | { 11 | return Task.FromResult( 12 | new AuthorizationPolicyBuilder("Identity.Application") 13 | .RequireAuthenticatedUser().Build()); 14 | } 15 | 16 | public Task GetFallbackPolicyAsync() 17 | { 18 | return Task.FromResult(null!); 19 | } 20 | 21 | public Task GetPolicyAsync(string nombrePolitica) 22 | { 23 | if (nombrePolitica.StartsWith(Constantes.PrefijoPolitica, 24 | StringComparison.OrdinalIgnoreCase) && 25 | Enum.TryParse(typeof(Permisos), 26 | nombrePolitica.Substring(Constantes.PrefijoPolitica.Length), 27 | out var permisoObj)) 28 | { 29 | var permiso = (Permisos)permisoObj!; 30 | var politica = new AuthorizationPolicyBuilder("Identity.Application"); 31 | politica.AddRequirements(new TienePermisoRequirement(permiso)); 32 | return Task.FromResult(politica.Build()); 33 | } 34 | 35 | return Task.FromResult(null!); 36 | 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Seguridad/TienePermisoRequirement.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using MultiTenancyDemo.Entidades; 3 | 4 | namespace MultiTenancyDemo.Seguridad 5 | { 6 | public class TienePermisoRequirement: IAuthorizationRequirement 7 | { 8 | public TienePermisoRequirement(Permisos permisos) 9 | { 10 | Permiso = permisos; 11 | } 12 | 13 | public Permisos Permiso { get; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/Constantes.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public static class Constantes 4 | { 5 | public const string ClaimTenantId = "tenantId"; 6 | public const string PrefijoPolitica = "TienePermiso"; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/EsconderAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public class EsconderAttribute: Attribute 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/ExtensionesTipo.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using MultiTenancyDemo.Entidades; 3 | 4 | namespace MultiTenancyDemo.Servicios 5 | { 6 | public static class ExtensionesTipo 7 | { 8 | public static bool DebeSaltarValidaciónTenant(this Type t) 9 | { 10 | var booleanos = new List() 11 | { 12 | t.IsAssignableFrom(typeof(IdentityRole)), 13 | t.IsAssignableFrom(typeof(IdentityRoleClaim)), 14 | t.IsAssignableFrom(typeof(IdentityUser)), 15 | t.IsAssignableFrom(typeof(IdentityUserLogin)), 16 | t.IsAssignableFrom(typeof(IdentityUserRole)), 17 | t.IsAssignableFrom(typeof(IdentityUserToken)), 18 | t.IsAssignableFrom(typeof(IdentityUserClaim)), 19 | typeof(IEntidadComún).IsAssignableFrom(t) 20 | }; 21 | 22 | var resultado = booleanos.Aggregate((b1, b2) => b1 || b2); 23 | 24 | return resultado; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/IServicioCambioTenant.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public interface IServicioCambioTenant 4 | { 5 | Task ReemplazarTenant(Guid idEmpresa, string usuarioId); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/IServicioTenant.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public interface IServicioTenant 4 | { 5 | string ObtenerTenant(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/IServicioUsuario.cs: -------------------------------------------------------------------------------- 1 | namespace MultiTenancyDemo.Servicios 2 | { 3 | public interface IServicioUsuario 4 | { 5 | string ObtenerUsuarioId(); 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/ServicioCambioTenant.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.EntityFrameworkCore; 3 | using MultiTenancyDemo.Data; 4 | using System.Security.Claims; 5 | 6 | namespace MultiTenancyDemo.Servicios 7 | { 8 | public class ServicioCambioTenant: IServicioCambioTenant 9 | { 10 | private readonly UserManager userManager; 11 | private readonly SignInManager signInManager; 12 | private readonly ApplicationDbContext context; 13 | 14 | public ServicioCambioTenant(UserManager userManager, 15 | SignInManager signInManager, 16 | ApplicationDbContext context) 17 | { 18 | this.userManager = userManager; 19 | this.signInManager = signInManager; 20 | this.context = context; 21 | } 22 | 23 | public async Task ReemplazarTenant(Guid idEmpresa, string usuarioId) 24 | { 25 | var usuario = await userManager.FindByIdAsync(usuarioId); 26 | 27 | var claimTenantExistente = await context.UserClaims 28 | .FirstOrDefaultAsync(x => x.ClaimType == Constantes.ClaimTenantId 29 | && x.UserId == usuarioId); 30 | 31 | if (claimTenantExistente is not null) 32 | { 33 | context.Remove(claimTenantExistente); 34 | } 35 | 36 | var claimTenantNuevo = new Claim(Constantes.ClaimTenantId, 37 | idEmpresa.ToString()); 38 | 39 | await userManager.AddClaimAsync(usuario, claimTenantNuevo); 40 | 41 | await signInManager.SignInAsync(usuario, isPersistent: true); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/ServicioTenant.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authentication; 2 | using Microsoft.AspNetCore.Authentication.Cookies; 3 | using Microsoft.Extensions.Options; 4 | 5 | namespace MultiTenancyDemo.Servicios 6 | { 7 | public class ServicioTenant : IServicioTenant 8 | { 9 | private readonly IHttpContextAccessor httpContextAccessor; 10 | 11 | public ServicioTenant(IHttpContextAccessor httpContextAccessor) 12 | { 13 | this.httpContextAccessor = httpContextAccessor; 14 | } 15 | 16 | public string ObtenerTenant() 17 | { 18 | var httpContext = httpContextAccessor.HttpContext; 19 | 20 | if (httpContext is null) 21 | { 22 | return string.Empty; 23 | } 24 | 25 | var authTicket = DecryptAuthCookie(httpContext); 26 | 27 | if (authTicket is null) 28 | { 29 | return string.Empty; 30 | } 31 | 32 | var claimTenant = authTicket.Principal.Claims.FirstOrDefault(x => x.Type == Constantes.ClaimTenantId); 33 | 34 | if (claimTenant is null) 35 | { 36 | return string.Empty; 37 | } 38 | 39 | return claimTenant.Value; 40 | } 41 | 42 | private static AuthenticationTicket? DecryptAuthCookie(HttpContext httpContext) 43 | { 44 | var opt = httpContext.RequestServices 45 | .GetRequiredService>() 46 | .Get("Identity.Application"); 47 | 48 | var cookie = opt.CookieManager.GetRequestCookie(httpContext, opt.Cookie.Name!); 49 | 50 | return opt.TicketDataFormat.Unprotect(cookie); 51 | } 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Servicios/ServicioUsuario.cs: -------------------------------------------------------------------------------- 1 | using System.Security.Claims; 2 | 3 | namespace MultiTenancyDemo.Servicios 4 | { 5 | public class ServicioUsuario : IServicioUsuario 6 | { 7 | private readonly HttpContext httpContext; 8 | 9 | public ServicioUsuario(IHttpContextAccessor httpContextAccessor) 10 | { 11 | httpContext = httpContextAccessor.HttpContext!; 12 | } 13 | 14 | 15 | public string ObtenerUsuarioId() 16 | { 17 | if (httpContext.User.Identity!.IsAuthenticated) 18 | { 19 | var idClaim = httpContext.User 20 | .Claims.Where(x => x.Type == ClaimTypes.NameIdentifier) 21 | .FirstOrDefault(); 22 | 23 | if (idClaim is null) 24 | { 25 | throw new ApplicationException("El usuario no tiene el claim del ID"); 26 | } 27 | 28 | return idClaim.Value; 29 | } 30 | else 31 | { 32 | throw new ApplicationException("El usuario no está autenticado"); 33 | } 34 | 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Empresas/Cambiar.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo.Entidades 2 | @model List 3 | 4 |

    Escoge la empresa con la que deseas trabajar

    5 | 6 | @if (Model.Count() == 0) 7 | { 8 |

    No hay empresas disponibles.

    9 | } 10 | else 11 | { 12 |
    13 |
    14 | @foreach (var empresa in Model) 15 | { 16 | 17 | } 18 |
    19 |
    20 | } 21 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Empresas/Crear.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo.Entidades 2 | @model CrearEmpresa 3 | 4 |

    Crear Empresa

    5 | 6 |
    7 | 8 |
    9 |
    10 | 11 | 12 | 13 |
    14 | 15 | 16 | Cancelar 17 |
    18 | 19 | @section Scripts { 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Authorization 2 | @using MultiTenancyDemo.Entidades 3 | @using MultiTenancyDemo.Seguridad 4 | @model HomeIndexViewModel 5 | @inject IAuthorizationService _authorizationService 6 | 7 | @{ 8 | ViewData["Title"] = "Home Page"; 9 | } 10 | 11 |
    12 |

    Welcome

    13 |

    Learn about building Web apps with ASP.NET Core.

    14 |
    15 | 16 |
    17 |

    Claims

    18 | @if (User.Identity is not null && User.Identity.IsAuthenticated) 19 | { 20 | @foreach (var claim in User.Claims) 21 | { 22 |

    @claim.Type - @claim.Value

    23 | } 24 | } 25 |
    26 | 27 |
    28 |

    Productos

    29 | @if (User.Identity is not null && User.Identity.IsAuthenticated) 30 | { 31 | if (await _authorizationService.TienePermiso(User, Permisos.Productos_Crear)) 32 | { 33 |
    34 |
    35 | 36 |
    37 | 38 |
    39 | 40 |
    41 |
    42 | } 43 | 44 |
      45 | @foreach (var producto in Model.Productos) 46 | { 47 |
    • @producto.Nombre
    • 48 | } 49 |
    50 | } 51 | else 52 | { 53 |

    Logueate para que puedas crear y visualizar productos!

    54 | } 55 | 56 |
    57 | 58 |
    59 |

    Países

    60 |
      61 | @foreach (var país in Model.Países) 62 | { 63 |
    • @país.Nombre
    • 64 | } 65 |
    66 |
    67 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Home/Privacy.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | ViewData["Title"] = "Privacy Policy"; 3 | } 4 |

    @ViewData["Title"]

    5 | 6 |

    Use this page to detail your site's privacy policy.

    7 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Permisos/Administrar.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo.Entidades 2 | @model AdministrarPermisosDTO 3 | 4 |

    Administrar permisos de @Model.Email

    5 | 6 |
    7 | 8 | 9 | 10 | 11 | 13 | 15 | 16 |
      17 | @for (var i = 0; i < Model.Permisos.Count; i++) 18 | { 19 |
    • 20 | 26 | 27 | @Model.Permisos[i].Descripcion 28 |
    • 29 | } 30 |
    31 |
    32 | 33 | @section Scripts{ 34 | 45 | } 46 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Permisos/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model IndexPermisosDTO 2 | 3 |

    Administrar permisos de la empresa: @Model.NombreEmpresa

    4 | 5 |
    Empleados:
    6 | 7 |
      8 | @foreach (var empleado in Model.Empleados) 9 | { 10 |
    • 11 |
      12 | @empleado.Email 13 |
      14 | 20 |
    • 21 | } 22 |
    23 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Shared/Error.cshtml: -------------------------------------------------------------------------------- 1 | @model ErrorViewModel 2 | @{ 3 | ViewData["Title"] = "Error"; 4 | } 5 | 6 |

    Error.

    7 |

    An error occurred while processing your request.

    8 | 9 | @if (Model.ShowRequestId) 10 | { 11 |

    12 | Request ID: @Model.RequestId 13 |

    14 | } 15 | 16 |

    Development Mode

    17 |

    18 | Swapping to Development environment will display more detailed information about the error that occurred. 19 |

    20 |

    21 | The Development environment shouldn't be enabled for deployed applications. 22 | It can result in displaying sensitive information from exceptions to end users. 23 | For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development 24 | and restarting the app. 25 |

    26 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Authorization 2 | @using MultiTenancyDemo.Entidades 3 | @using MultiTenancyDemo.Seguridad 4 | @inject IAuthorizationService _authorizationService 5 | 6 | 7 | 8 | 9 | 10 | 11 | @ViewData["Title"] - MultiTenancyDemo 12 | 13 | 14 | 15 | 16 | 17 |
    18 | 60 |
    61 |
    62 |
    63 | @RenderBody() 64 |
    65 |
    66 | 67 |
    68 |
    69 | © 2022 - MultiTenancyDemo - Privacy 70 |
    71 |
    72 | 73 | 74 | 75 | @await RenderSectionAsync("Scripts", required: false) 76 | 77 | 78 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Shared/_Layout.cshtml.css: -------------------------------------------------------------------------------- 1 | /* Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | for details on configuring this project to bundle and minify static web assets. */ 3 | 4 | a.navbar-brand { 5 | white-space: normal; 6 | text-align: center; 7 | word-break: break-all; 8 | } 9 | 10 | a { 11 | color: #0077cc; 12 | } 13 | 14 | .btn-primary { 15 | color: #fff; 16 | background-color: #1b6ec2; 17 | border-color: #1861ac; 18 | } 19 | 20 | .nav-pills .nav-link.active, .nav-pills .show > .nav-link { 21 | color: #fff; 22 | background-color: #1b6ec2; 23 | border-color: #1861ac; 24 | } 25 | 26 | .border-top { 27 | border-top: 1px solid #e5e5e5; 28 | } 29 | .border-bottom { 30 | border-bottom: 1px solid #e5e5e5; 31 | } 32 | 33 | .box-shadow { 34 | box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); 35 | } 36 | 37 | button.accept-policy { 38 | font-size: 1rem; 39 | line-height: inherit; 40 | } 41 | 42 | .footer { 43 | position: absolute; 44 | bottom: 0; 45 | width: 100%; 46 | white-space: nowrap; 47 | line-height: 60px; 48 | } 49 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Shared/_LoginPartial.cshtml: -------------------------------------------------------------------------------- 1 | @using Microsoft.AspNetCore.Identity 2 | @inject SignInManager SignInManager 3 | @inject UserManager UserManager 4 | 5 | 28 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Shared/_ValidationScriptsPartial.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Usuarios/Login.cshtml: -------------------------------------------------------------------------------- 1 | @model LoginViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Login"; 5 | } 6 | 7 |

    Login

    8 | 9 |
    10 |
    11 |
    12 |
    13 | 14 |
    15 | 16 | 17 | 18 |
    19 | 20 |
    21 | 22 | 23 | 24 |
    25 | 26 |
    27 | 28 | 29 |
    30 | 31 | 32 | Crear una nueva cuenta 33 |
    34 | 35 |
    36 |
    37 | 38 | 39 | @section Scripts { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Usuarios/Registro.cshtml: -------------------------------------------------------------------------------- 1 | @model RegistroViewModel 2 | 3 | @{ 4 | ViewData["Title"] = "Registro"; 5 | } 6 | 7 |

    Regístrate

    8 | 9 |
    10 |
    11 |
    12 |
    13 | 14 |
    15 | 16 | 17 | 18 |
    19 | 20 |
    21 | 22 | 23 | 24 |
    25 | 26 | 27 | Deseo Loguearme 28 | 29 |
    30 |
    31 |
    32 | 33 | 34 | 35 | @section Scripts { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Vinculaciones/Index.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo.Entidades 2 | @model List 3 | 4 |

    Vinculaciones pendientes

    5 |
    6 | Las siguientes empresas te han invitado para que colabores: 7 |
    8 | 9 |
      10 | @foreach (var vinculacion in Model) 11 | { 12 |
      13 |
    • 14 | 15 |
      16 | La empresa 17 | @vinculacion.Empresa.Nombre te invita a vincularte. 18 |
      19 |
      20 | 23 | 26 |
      27 |
    • 28 |
      29 | } 30 |
    31 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Vinculaciones/UsuarioVinculado.cshtml: -------------------------------------------------------------------------------- 1 | 

    Solicitud de vinculación enviada.

    -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/Vinculaciones/Vincular.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo.Entidades 2 | @model VincularUsuario 3 | 4 |

    Vincular usuario

    5 |
    Vincular usuarios a: @Model.NombreEmpresa
    6 | 7 |
    8 | 9 |
    10 | 11 | 12 | 13 |
    14 | 15 | 16 | 17 |
    18 | 19 | 20 | Cancelar 21 |
    22 | 23 | @section Scripts { 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using MultiTenancyDemo 2 | @using MultiTenancyDemo.Models 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConnectionStrings": { 3 | "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-MultiTenancyDemo-video-2;Trusted_Connection=True;MultipleActiveResultSets=true" 4 | }, 5 | "Logging": { 6 | "LogLevel": { 7 | "Default": "Information", 8 | "Microsoft.AspNetCore": "Warning" 9 | } 10 | }, 11 | "AllowedHosts": "*" 12 | } 13 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | html { 2 | font-size: 14px; 3 | } 4 | 5 | @media (min-width: 768px) { 6 | html { 7 | font-size: 16px; 8 | } 9 | } 10 | 11 | html { 12 | position: relative; 13 | min-height: 100%; 14 | } 15 | 16 | body { 17 | margin-bottom: 60px; 18 | } -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gavilanch/aspnetcoremultitenancy/d703d9a05ee3d263dc96873ccdf2547144b4f05e/Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/js/site.js: -------------------------------------------------------------------------------- 1 | // Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification 2 | // for details on configuring this project to bundle and minify static web assets. 3 | 4 | // Write your JavaScript code. 5 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/bootstrap/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2011-2021 Twitter, Inc. 4 | Copyright (c) 2011-2021 The Bootstrap Authors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-left: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-left: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr /* rtl:ignore */; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: left; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: left; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: left; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | /* rtl:raw: 382 | [type="tel"], 383 | [type="url"], 384 | [type="email"], 385 | [type="number"] { 386 | direction: ltr; 387 | } 388 | */ 389 | ::-webkit-search-decoration { 390 | -webkit-appearance: none; 391 | } 392 | 393 | ::-webkit-color-swatch-wrapper { 394 | padding: 0; 395 | } 396 | 397 | ::file-selector-button { 398 | font: inherit; 399 | } 400 | 401 | ::-webkit-file-upload-button { 402 | font: inherit; 403 | -webkit-appearance: button; 404 | } 405 | 406 | output { 407 | display: inline-block; 408 | } 409 | 410 | iframe { 411 | border: 0; 412 | } 413 | 414 | summary { 415 | display: list-item; 416 | cursor: pointer; 417 | } 418 | 419 | progress { 420 | vertical-align: baseline; 421 | } 422 | 423 | [hidden] { 424 | display: none !important; 425 | } 426 | 427 | /*# sourceMappingURL=bootstrap-reboot.css.map */ -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.min.css.map */ -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */ 8 | *, 9 | *::before, 10 | *::after { 11 | box-sizing: border-box; 12 | } 13 | 14 | @media (prefers-reduced-motion: no-preference) { 15 | :root { 16 | scroll-behavior: smooth; 17 | } 18 | } 19 | 20 | body { 21 | margin: 0; 22 | font-family: var(--bs-body-font-family); 23 | font-size: var(--bs-body-font-size); 24 | font-weight: var(--bs-body-font-weight); 25 | line-height: var(--bs-body-line-height); 26 | color: var(--bs-body-color); 27 | text-align: var(--bs-body-text-align); 28 | background-color: var(--bs-body-bg); 29 | -webkit-text-size-adjust: 100%; 30 | -webkit-tap-highlight-color: rgba(0, 0, 0, 0); 31 | } 32 | 33 | hr { 34 | margin: 1rem 0; 35 | color: inherit; 36 | background-color: currentColor; 37 | border: 0; 38 | opacity: 0.25; 39 | } 40 | 41 | hr:not([size]) { 42 | height: 1px; 43 | } 44 | 45 | h6, h5, h4, h3, h2, h1 { 46 | margin-top: 0; 47 | margin-bottom: 0.5rem; 48 | font-weight: 500; 49 | line-height: 1.2; 50 | } 51 | 52 | h1 { 53 | font-size: calc(1.375rem + 1.5vw); 54 | } 55 | @media (min-width: 1200px) { 56 | h1 { 57 | font-size: 2.5rem; 58 | } 59 | } 60 | 61 | h2 { 62 | font-size: calc(1.325rem + 0.9vw); 63 | } 64 | @media (min-width: 1200px) { 65 | h2 { 66 | font-size: 2rem; 67 | } 68 | } 69 | 70 | h3 { 71 | font-size: calc(1.3rem + 0.6vw); 72 | } 73 | @media (min-width: 1200px) { 74 | h3 { 75 | font-size: 1.75rem; 76 | } 77 | } 78 | 79 | h4 { 80 | font-size: calc(1.275rem + 0.3vw); 81 | } 82 | @media (min-width: 1200px) { 83 | h4 { 84 | font-size: 1.5rem; 85 | } 86 | } 87 | 88 | h5 { 89 | font-size: 1.25rem; 90 | } 91 | 92 | h6 { 93 | font-size: 1rem; 94 | } 95 | 96 | p { 97 | margin-top: 0; 98 | margin-bottom: 1rem; 99 | } 100 | 101 | abbr[title], 102 | abbr[data-bs-original-title] { 103 | -webkit-text-decoration: underline dotted; 104 | text-decoration: underline dotted; 105 | cursor: help; 106 | -webkit-text-decoration-skip-ink: none; 107 | text-decoration-skip-ink: none; 108 | } 109 | 110 | address { 111 | margin-bottom: 1rem; 112 | font-style: normal; 113 | line-height: inherit; 114 | } 115 | 116 | ol, 117 | ul { 118 | padding-right: 2rem; 119 | } 120 | 121 | ol, 122 | ul, 123 | dl { 124 | margin-top: 0; 125 | margin-bottom: 1rem; 126 | } 127 | 128 | ol ol, 129 | ul ul, 130 | ol ul, 131 | ul ol { 132 | margin-bottom: 0; 133 | } 134 | 135 | dt { 136 | font-weight: 700; 137 | } 138 | 139 | dd { 140 | margin-bottom: 0.5rem; 141 | margin-right: 0; 142 | } 143 | 144 | blockquote { 145 | margin: 0 0 1rem; 146 | } 147 | 148 | b, 149 | strong { 150 | font-weight: bolder; 151 | } 152 | 153 | small { 154 | font-size: 0.875em; 155 | } 156 | 157 | mark { 158 | padding: 0.2em; 159 | background-color: #fcf8e3; 160 | } 161 | 162 | sub, 163 | sup { 164 | position: relative; 165 | font-size: 0.75em; 166 | line-height: 0; 167 | vertical-align: baseline; 168 | } 169 | 170 | sub { 171 | bottom: -0.25em; 172 | } 173 | 174 | sup { 175 | top: -0.5em; 176 | } 177 | 178 | a { 179 | color: #0d6efd; 180 | text-decoration: underline; 181 | } 182 | a:hover { 183 | color: #0a58ca; 184 | } 185 | 186 | a:not([href]):not([class]), a:not([href]):not([class]):hover { 187 | color: inherit; 188 | text-decoration: none; 189 | } 190 | 191 | pre, 192 | code, 193 | kbd, 194 | samp { 195 | font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; 196 | font-size: 1em; 197 | direction: ltr ; 198 | unicode-bidi: bidi-override; 199 | } 200 | 201 | pre { 202 | display: block; 203 | margin-top: 0; 204 | margin-bottom: 1rem; 205 | overflow: auto; 206 | font-size: 0.875em; 207 | } 208 | pre code { 209 | font-size: inherit; 210 | color: inherit; 211 | word-break: normal; 212 | } 213 | 214 | code { 215 | font-size: 0.875em; 216 | color: #d63384; 217 | word-wrap: break-word; 218 | } 219 | a > code { 220 | color: inherit; 221 | } 222 | 223 | kbd { 224 | padding: 0.2rem 0.4rem; 225 | font-size: 0.875em; 226 | color: #fff; 227 | background-color: #212529; 228 | border-radius: 0.2rem; 229 | } 230 | kbd kbd { 231 | padding: 0; 232 | font-size: 1em; 233 | font-weight: 700; 234 | } 235 | 236 | figure { 237 | margin: 0 0 1rem; 238 | } 239 | 240 | img, 241 | svg { 242 | vertical-align: middle; 243 | } 244 | 245 | table { 246 | caption-side: bottom; 247 | border-collapse: collapse; 248 | } 249 | 250 | caption { 251 | padding-top: 0.5rem; 252 | padding-bottom: 0.5rem; 253 | color: #6c757d; 254 | text-align: right; 255 | } 256 | 257 | th { 258 | text-align: inherit; 259 | text-align: -webkit-match-parent; 260 | } 261 | 262 | thead, 263 | tbody, 264 | tfoot, 265 | tr, 266 | td, 267 | th { 268 | border-color: inherit; 269 | border-style: solid; 270 | border-width: 0; 271 | } 272 | 273 | label { 274 | display: inline-block; 275 | } 276 | 277 | button { 278 | border-radius: 0; 279 | } 280 | 281 | button:focus:not(:focus-visible) { 282 | outline: 0; 283 | } 284 | 285 | input, 286 | button, 287 | select, 288 | optgroup, 289 | textarea { 290 | margin: 0; 291 | font-family: inherit; 292 | font-size: inherit; 293 | line-height: inherit; 294 | } 295 | 296 | button, 297 | select { 298 | text-transform: none; 299 | } 300 | 301 | [role=button] { 302 | cursor: pointer; 303 | } 304 | 305 | select { 306 | word-wrap: normal; 307 | } 308 | select:disabled { 309 | opacity: 1; 310 | } 311 | 312 | [list]::-webkit-calendar-picker-indicator { 313 | display: none; 314 | } 315 | 316 | button, 317 | [type=button], 318 | [type=reset], 319 | [type=submit] { 320 | -webkit-appearance: button; 321 | } 322 | button:not(:disabled), 323 | [type=button]:not(:disabled), 324 | [type=reset]:not(:disabled), 325 | [type=submit]:not(:disabled) { 326 | cursor: pointer; 327 | } 328 | 329 | ::-moz-focus-inner { 330 | padding: 0; 331 | border-style: none; 332 | } 333 | 334 | textarea { 335 | resize: vertical; 336 | } 337 | 338 | fieldset { 339 | min-width: 0; 340 | padding: 0; 341 | margin: 0; 342 | border: 0; 343 | } 344 | 345 | legend { 346 | float: right; 347 | width: 100%; 348 | padding: 0; 349 | margin-bottom: 0.5rem; 350 | font-size: calc(1.275rem + 0.3vw); 351 | line-height: inherit; 352 | } 353 | @media (min-width: 1200px) { 354 | legend { 355 | font-size: 1.5rem; 356 | } 357 | } 358 | legend + * { 359 | clear: right; 360 | } 361 | 362 | ::-webkit-datetime-edit-fields-wrapper, 363 | ::-webkit-datetime-edit-text, 364 | ::-webkit-datetime-edit-minute, 365 | ::-webkit-datetime-edit-hour-field, 366 | ::-webkit-datetime-edit-day-field, 367 | ::-webkit-datetime-edit-month-field, 368 | ::-webkit-datetime-edit-year-field { 369 | padding: 0; 370 | } 371 | 372 | ::-webkit-inner-spin-button { 373 | height: auto; 374 | } 375 | 376 | [type=search] { 377 | outline-offset: -2px; 378 | -webkit-appearance: textfield; 379 | } 380 | 381 | [type="tel"], 382 | [type="url"], 383 | [type="email"], 384 | [type="number"] { 385 | direction: ltr; 386 | } 387 | ::-webkit-search-decoration { 388 | -webkit-appearance: none; 389 | } 390 | 391 | ::-webkit-color-swatch-wrapper { 392 | padding: 0; 393 | } 394 | 395 | ::file-selector-button { 396 | font: inherit; 397 | } 398 | 399 | ::-webkit-file-upload-button { 400 | font: inherit; 401 | -webkit-appearance: button; 402 | } 403 | 404 | output { 405 | display: inline-block; 406 | } 407 | 408 | iframe { 409 | border: 0; 410 | } 411 | 412 | summary { 413 | display: list-item; 414 | cursor: pointer; 415 | } 416 | 417 | progress { 418 | vertical-align: baseline; 419 | } 420 | 421 | [hidden] { 422 | display: none !important; 423 | } 424 | /*# sourceMappingURL=bootstrap-reboot.rtl.css.map */ -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/bootstrap/dist/css/bootstrap-reboot.rtl.min.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Reboot v5.1.0 (https://getbootstrap.com/) 3 | * Copyright 2011-2021 The Bootstrap Authors 4 | * Copyright 2011-2021 Twitter, Inc. 5 | * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) 6 | * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) 7 | */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:var(--bs-body-font-family);font-size:var(--bs-body-font-size);font-weight:var(--bs-body-font-weight);line-height:var(--bs-body-line-height);color:var(--bs-body-color);text-align:var(--bs-body-text-align);background-color:var(--bs-body-bg);-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-right:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-right:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:right}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:right;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:right}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}[type=email],[type=number],[type=tel],[type=url]{direction:ltr}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important} 8 | /*# sourceMappingURL=bootstrap-reboot.rtl.min.css.map */ -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/jquery-validation-unobtrusive/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) .NET Foundation. All rights reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 4 | these files except in compliance with the License. You may obtain a copy of the 5 | License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software distributed 10 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 11 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 12 | specific language governing permissions and limitations under the License. 13 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/jquery-validation-unobtrusive/jquery.validate.unobtrusive.min.js: -------------------------------------------------------------------------------- 1 | // Unobtrusive validation support library for jQuery and jQuery Validate 2 | // Copyright (c) .NET Foundation. All rights reserved. 3 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. 4 | // @version v3.2.11 5 | !function(a){"function"==typeof define&&define.amd?define("jquery.validate.unobtrusive",["jquery-validation"],a):"object"==typeof module&&module.exports?module.exports=a(require("jquery-validation")):jQuery.validator.unobtrusive=a(jQuery)}(function(a){function e(a,e,n){a.rules[e]=n,a.message&&(a.messages[e]=a.message)}function n(a){return a.replace(/^\s+|\s+$/g,"").split(/\s*,\s*/g)}function t(a){return a.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g,"\\$1")}function r(a){return a.substr(0,a.lastIndexOf(".")+1)}function i(a,e){return 0===a.indexOf("*.")&&(a=a.replace("*.",e)),a}function o(e,n){var r=a(this).find("[data-valmsg-for='"+t(n[0].name)+"']"),i=r.attr("data-valmsg-replace"),o=i?a.parseJSON(i)!==!1:null;r.removeClass("field-validation-valid").addClass("field-validation-error"),e.data("unobtrusiveContainer",r),o?(r.empty(),e.removeClass("input-validation-error").appendTo(r)):e.hide()}function d(e,n){var t=a(this).find("[data-valmsg-summary=true]"),r=t.find("ul");r&&r.length&&n.errorList.length&&(r.empty(),t.addClass("validation-summary-errors").removeClass("validation-summary-valid"),a.each(n.errorList,function(){a("
  • ").html(this.message).appendTo(r)}))}function s(e){var n=e.data("unobtrusiveContainer");if(n){var t=n.attr("data-valmsg-replace"),r=t?a.parseJSON(t):null;n.addClass("field-validation-valid").removeClass("field-validation-error"),e.removeData("unobtrusiveContainer"),r&&n.empty()}}function l(e){var n=a(this),t="__jquery_unobtrusive_validation_form_reset";if(!n.data(t)){n.data(t,!0);try{n.data("validator").resetForm()}finally{n.removeData(t)}n.find(".validation-summary-errors").addClass("validation-summary-valid").removeClass("validation-summary-errors"),n.find(".field-validation-error").addClass("field-validation-valid").removeClass("field-validation-error").removeData("unobtrusiveContainer").find(">*").removeData("unobtrusiveContainer")}}function u(e){var n=a(e),t=n.data(v),r=a.proxy(l,e),i=f.unobtrusive.options||{},u=function(n,t){var r=i[n];r&&a.isFunction(r)&&r.apply(e,t)};return t||(t={options:{errorClass:i.errorClass||"input-validation-error",errorElement:i.errorElement||"span",errorPlacement:function(){o.apply(e,arguments),u("errorPlacement",arguments)},invalidHandler:function(){d.apply(e,arguments),u("invalidHandler",arguments)},messages:{},rules:{},success:function(){s.apply(e,arguments),u("success",arguments)}},attachValidation:function(){n.off("reset."+v,r).on("reset."+v,r).validate(this.options)},validate:function(){return n.validate(),n.valid()}},n.data(v,t)),t}var m,f=a.validator,v="unobtrusiveValidation";return f.unobtrusive={adapters:[],parseElement:function(e,n){var t,r,i,o=a(e),d=o.parents("form")[0];d&&(t=u(d),t.options.rules[e.name]=r={},t.options.messages[e.name]=i={},a.each(this.adapters,function(){var n="data-val-"+this.name,t=o.attr(n),s={};void 0!==t&&(n+="-",a.each(this.params,function(){s[this]=o.attr(n+this)}),this.adapt({element:e,form:d,message:t,params:s,rules:r,messages:i}))}),a.extend(r,{__dummy__:!0}),n||t.attachValidation())},parse:function(e){var n=a(e),t=n.parents().addBack().filter("form").add(n.find("form")).has("[data-val=true]");n.find("[data-val=true]").each(function(){f.unobtrusive.parseElement(this,!0)}),t.each(function(){var a=u(this);a&&a.attachValidation()})}},m=f.unobtrusive.adapters,m.add=function(a,e,n){return n||(n=e,e=[]),this.push({name:a,params:e,adapt:n}),this},m.addBool=function(a,n){return this.add(a,function(t){e(t,n||a,!0)})},m.addMinMax=function(a,n,t,r,i,o){return this.add(a,[i||"min",o||"max"],function(a){var i=a.params.min,o=a.params.max;i&&o?e(a,r,[i,o]):i?e(a,n,i):o&&e(a,t,o)})},m.addSingleVal=function(a,n,t){return this.add(a,[n||"val"],function(r){e(r,t||a,r.params[n])})},f.addMethod("__dummy__",function(a,e,n){return!0}),f.addMethod("regex",function(a,e,n){var t;return!!this.optional(e)||(t=new RegExp(n).exec(a),t&&0===t.index&&t[0].length===a.length)}),f.addMethod("nonalphamin",function(a,e,n){var t;return n&&(t=a.match(/\W/g),t=t&&t.length>=n),t}),f.methods.extension?(m.addSingleVal("accept","mimtype"),m.addSingleVal("extension","extension")):m.addSingleVal("extension","extension","accept"),m.addSingleVal("regex","pattern"),m.addBool("creditcard").addBool("date").addBool("digits").addBool("email").addBool("number").addBool("url"),m.addMinMax("length","minlength","maxlength","rangelength").addMinMax("range","min","max","range"),m.addMinMax("minlength","minlength").addMinMax("maxlength","minlength","maxlength"),m.add("equalto",["other"],function(n){var o=r(n.element.name),d=n.params.other,s=i(d,o),l=a(n.form).find(":input").filter("[name='"+t(s)+"']")[0];e(n,"equalTo",l)}),m.add("required",function(a){"INPUT"===a.element.tagName.toUpperCase()&&"CHECKBOX"===a.element.type.toUpperCase()||e(a,"required",!0)}),m.add("remote",["url","type","additionalfields"],function(o){var d={url:o.params.url,type:o.params.type||"GET",data:{}},s=r(o.element.name);a.each(n(o.params.additionalfields||o.element.name),function(e,n){var r=i(n,s);d.data[r]=function(){var e=a(o.form).find(":input").filter("[name='"+t(r)+"']");return e.is(":checkbox")?e.filter(":checked").val()||e.filter(":hidden").val()||"":e.is(":radio")?e.filter(":checked").val()||"":e.val()}}),e(o,"remote",d)}),m.add("password",["min","nonalphamin","regex"],function(a){a.params.min&&e(a,"minlength",a.params.min),a.params.nonalphamin&&e(a,"nonalphamin",a.params.nonalphamin),a.params.regex&&e(a,"regex",a.params.regex)}),m.add("fileextensions",["extensions"],function(a){e(a,"extension",a.params.extensions)}),a(function(){f.unobtrusive.parse(document)}),f.unobtrusive}); 6 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/jquery-validation/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | ===================== 3 | 4 | Copyright Jörn Zaefferer 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /Parte 2 - Tenant por Empresa/MultiTenancyDemo/wwwroot/lib/jquery/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright JS Foundation and other contributors, https://js.foundation/ 2 | 3 | This software consists of voluntary contributions made by many 4 | individuals. For exact contribution history, see the revision history 5 | available at https://github.com/jquery/jquery 6 | 7 | The following license applies to all parts of this software except as 8 | documented below: 9 | 10 | ==== 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining 13 | a copy of this software and associated documentation files (the 14 | "Software"), to deal in the Software without restriction, including 15 | without limitation the rights to use, copy, modify, merge, publish, 16 | distribute, sublicense, and/or sell copies of the Software, and to 17 | permit persons to whom the Software is furnished to do so, subject to 18 | the following conditions: 19 | 20 | The above copyright notice and this permission notice shall be 21 | included in all copies or substantial portions of the Software. 22 | 23 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 27 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 28 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 29 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 30 | 31 | ==== 32 | 33 | All files located in the node_modules and external directories are 34 | externally maintained libraries used by this software which have their 35 | own licenses; we recommend you read them, as their terms may differ from 36 | the terms above. 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tutoriales relacionados con Multi-Tenancy y ASP.NET Core 2 | 3 | Parte 1: Un usuario por tenant: https://youtu.be/-OW7fbq5Ui8 4 | 5 | Parte 2: Una tenant por empresa: https://youtu.be/wOSQ3hc7SRs 6 | 7 | Parte 3: Una base de datos por tenant: TBD 8 | --------------------------------------------------------------------------------