├── .gitattributes ├── 9781484255087.jpg ├── Chapter_01 ├── HelloWorldMVC │ ├── Controllers │ │ └── HomeController.cs │ ├── HelloWorldMVC.csproj │ ├── HelloWorldMVC.sln │ ├── Models │ │ └── AppMessage.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ │ ├── Home │ │ │ └── Index.cshtml │ │ └── _ViewImports.cshtml │ ├── appsettings.Development.json │ └── appsettings.json ├── HelloWorldRazorPages │ ├── HelloWorldRazorPages.csproj │ ├── HelloWorldRazorPages.sln │ ├── Models │ │ └── AppMessage.cs │ ├── Pages │ │ ├── Index.cshtml │ │ ├── Index.cshtml.cs │ │ └── _ViewImports.cshtml │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json └── HelloWorldWebApi │ ├── Controllers │ └── ValuesController.cs │ ├── HelloWorldWebApi.csproj │ ├── HelloWorldWebApi.sln │ ├── Models │ └── AppMessage.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── appsettings.Development.json │ └── appsettings.json ├── Chapter_03 └── EmployeeManager.Mvc │ ├── Controllers │ ├── EmployeeManagerController.cs │ └── SecurityController.cs │ ├── EmployeeManager.Mvc.csproj │ ├── EmployeeManager.Mvc.sln │ ├── Migrations │ ├── 20191110114947_IdentityMigration.Designer.cs │ ├── 20191110114947_IdentityMigration.cs │ └── AppIdentityDbContextModelSnapshot.cs │ ├── Models │ ├── AppDbContext.cs │ ├── Country.cs │ ├── Employee.cs │ ├── Register.cs │ └── SignIn.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Security │ ├── AppIdentityDbContext.cs │ ├── AppIdentityRole.cs │ └── AppIdentityUser.cs │ ├── Startup.cs │ ├── Views │ ├── EmployeeManager │ │ ├── Delete.cshtml │ │ ├── Insert.cshtml │ │ ├── List.cshtml │ │ └── Update.cshtml │ ├── Security │ │ ├── AccessDenied.cshtml │ │ ├── Register.cshtml │ │ └── SignIn.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ └── Styles │ └── site.css ├── Chapter_04 └── EmployeeManager.RazorPages │ ├── EmployeeManager.RazorPages.csproj │ ├── EmployeeManager.RazorPages.sln │ ├── Models │ ├── AppDbContext.cs │ ├── Country.cs │ ├── Employee.cs │ ├── Register.cs │ └── SignIn.cs │ ├── Pages │ ├── EmployeeManager │ │ ├── Delete.cshtml │ │ ├── Delete.cshtml.cs │ │ ├── Insert.cshtml │ │ ├── Insert.cshtml.cs │ │ ├── List.cshtml │ │ ├── List.cshtml.cs │ │ ├── Update.cshtml │ │ └── Update.cshtml.cs │ ├── Error.cshtml │ ├── Error.cshtml.cs │ ├── Security │ │ ├── AccessDenied.cshtml │ │ ├── AccessDenied.cshtml.cs │ │ ├── Register.cshtml │ │ ├── Register.cshtml.cs │ │ ├── SignIn.cshtml │ │ ├── SignIn.cshtml.cs │ │ ├── SignOut.cshtml │ │ └── SignOut.cshtml.cs │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Security │ ├── AppIdentityDbContext.cs │ ├── AppIdentityRole.cs │ └── AppIdentityUser.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ └── Styles │ └── site.css ├── Chapter_05 ├── EmployeeManager.Api │ ├── Controllers │ │ ├── CountriesController.cs │ │ └── EmployeesController.cs │ ├── EmployeeManager.Api.csproj │ ├── EmployeeManager.Api.sln │ ├── Models │ │ ├── AppDbContext.cs │ │ ├── Country.cs │ │ └── Employee.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Repositories │ │ ├── CountrySqlRepository.cs │ │ ├── CountryStProcRepository.cs │ │ ├── EmployeeSqlRepository.cs │ │ ├── EmployeeStProcRepository.cs │ │ ├── ICountryRepository.cs │ │ └── IEmployeeRepository.cs │ ├── Startup.cs │ ├── Stored Procedures.txt │ ├── appsettings.Development.json │ └── appsettings.json └── EmployeeManager.ApiClient │ ├── Controllers │ ├── EmployeeManagerController.cs │ └── SecurityController.cs │ ├── EmployeeManager.ApiClient.csproj │ ├── EmployeeManager.ApiClient.sln │ ├── Models │ ├── Country.cs │ ├── Employee.cs │ ├── Register.cs │ ├── SignIn.cs │ └── WebApiConfig.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Security │ ├── AppIdentityDbContext.cs │ ├── AppIdentityRole.cs │ └── AppIdentityUser.cs │ ├── Startup.cs │ ├── Views │ ├── EmployeeManager │ │ ├── Delete.cshtml │ │ ├── Insert.cshtml │ │ ├── List.cshtml │ │ └── Update.cshtml │ ├── Security │ │ ├── AccessDenied.cshtml │ │ ├── Register.cshtml │ │ └── SignIn.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ └── Styles │ └── site.css ├── Chapter_06 └── EmployeeManager.Jquery │ ├── Controllers │ ├── CountriesController.cs │ ├── EmployeeManagerController.cs │ ├── EmployeesController.cs │ └── SecurityController.cs │ ├── EmployeeManager.Jquery.csproj │ ├── EmployeeManager.Jquery.sln │ ├── Models │ ├── AppDbContext.cs │ ├── Country.cs │ └── Employee.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Security │ ├── Register.cs │ ├── SignIn.cs │ └── User.cs │ ├── Startup.cs │ ├── Views │ ├── EmployeeManager │ │ ├── Delete.cshtml │ │ ├── Insert.cshtml │ │ ├── List.cshtml │ │ ├── Register.cshtml │ │ ├── SignIn.cshtml │ │ └── Update.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ └── Styles │ └── site.css ├── Chapter_07 ├── EmployeeManager.Angular │ ├── Controllers │ │ ├── CountriesController.cs │ │ ├── EmployeesController.cs │ │ ├── SecurityController.cs │ │ └── SpaController.cs │ ├── EmployeeManager.Angular.csproj │ ├── EmployeeManager.Angular.sln │ ├── Models │ │ ├── AppDbContext.cs │ │ ├── Country.cs │ │ └── Employee.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Security │ │ ├── Register.cs │ │ ├── SignIn.cs │ │ └── User.cs │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ ├── 3rdpartylicenses.txt │ │ ├── Styles │ │ └── site.css │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main-es2015.c78aa99469b0552b25c7.js │ │ ├── main-es5.abcfb90056ba55e2ceac.js │ │ ├── polyfills-es2015.585ff42b5603db69e08c.js │ │ ├── polyfills-es5.ee0d5f960ce47213e70c.js │ │ ├── runtime-es2015.c53cfa7e76780343722f.js │ │ ├── runtime-es5.ba44b74264daa95943c7.js │ │ └── styles.72fbc74fc75807d3ad17.css └── EmployeeManagerAngularApp │ ├── .editorconfig │ ├── .gitignore │ ├── README.md │ ├── angular.json │ ├── browserslist │ ├── e2e │ ├── protractor.conf.js │ ├── src │ │ ├── app.e2e-spec.ts │ │ └── app.po.ts │ └── tsconfig.e2e.json │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── app │ │ ├── app-routing.module.ts │ │ ├── app.component.html │ │ ├── app.component.ts │ │ ├── app.module.ts │ │ ├── countries-api │ │ │ └── countries-api.service.ts │ │ ├── employee-delete │ │ │ ├── employee-delete.component.html │ │ │ └── employee-delete.component.ts │ │ ├── employee-insert │ │ │ ├── employee-insert.component.html │ │ │ └── employee-insert.component.ts │ │ ├── employee-list │ │ │ ├── employee-list.component.html │ │ │ └── employee-list.component.ts │ │ ├── employee-update │ │ │ ├── employee-update.component.html │ │ │ └── employee-update.component.ts │ │ ├── employees-api │ │ │ └── employees-api.service.ts │ │ ├── models │ │ │ ├── country.ts │ │ │ ├── employee.ts │ │ │ └── user.ts │ │ ├── register │ │ │ ├── register.component.html │ │ │ └── register.component.ts │ │ ├── security-api │ │ │ └── security-api.service.ts │ │ ├── signin │ │ │ ├── signin.component.html │ │ │ └── signin.component.ts │ │ └── signout │ │ │ ├── signout.component.html │ │ │ └── signout.component.ts │ ├── assets │ │ └── .gitkeep │ ├── browserslist │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── favicon.ico │ ├── index.html │ ├── karma.conf.js │ ├── main.js │ ├── main.js.map │ ├── main.ts │ ├── polyfills.ts │ ├── styles.css │ ├── test.ts │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ └── tslint.json │ ├── tsconfig.json │ └── tslint.json ├── Chapter_08 └── EmployeeManager.Blazor.ServerSide │ ├── App.razor │ ├── EmployeeManager.Blazor.ServerSide.csproj │ ├── EmployeeManager.Blazor.ServerSide.sln │ ├── Models │ ├── AppDbContext.cs │ ├── Country.cs │ ├── Employee.cs │ ├── Register.cs │ └── SignIn.cs │ ├── Pages │ ├── Delete.razor │ ├── Insert.razor │ ├── List.razor │ ├── Security │ │ ├── Register.cshtml │ │ ├── Register.cshtml.cs │ │ ├── SignIn.cshtml │ │ ├── SignIn.cshtml.cs │ │ ├── SignOut.cshtml │ │ ├── SignOut.cshtml.cs │ │ ├── _Layout.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── Update.razor │ └── _Host.cshtml │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Repositories │ ├── CountryRepository.cs │ ├── EmployeeRepository.cs │ ├── ICountryRepository.cs │ └── IEmployeeRepository.cs │ ├── Security │ ├── AppIdentityDbContext.cs │ ├── AppIdentityRole.cs │ └── AppIdentityUser.cs │ ├── Shared │ └── MainLayout.razor │ ├── Startup.cs │ ├── _Imports.razor │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ ├── Styles │ └── site.css │ └── favicon.ico ├── Chapter_09 ├── EmployeeManager.AzureSql │ ├── Controllers │ │ ├── EmployeeManagerController.cs │ │ └── SecurityController.cs │ ├── EmployeeManager.AzureSql.csproj │ ├── EmployeeManager.AzureSql.sln │ ├── Models │ │ ├── AppDbContext.cs │ │ ├── Country.cs │ │ ├── Employee.cs │ │ ├── Register.cs │ │ └── SignIn.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Repositories │ │ ├── CountryRepository.cs │ │ ├── EmployeeRepository.cs │ │ ├── ICountryRepository.cs │ │ └── IEmployeeRepository.cs │ ├── Security │ │ ├── AppIdentityDbContext.cs │ │ ├── AppIdentityRole.cs │ │ └── AppIdentityUser.cs │ ├── Startup.cs │ ├── Views │ │ ├── EmployeeManager │ │ │ ├── Delete.cshtml │ │ │ ├── Insert.cshtml │ │ │ ├── List.cshtml │ │ │ └── Update.cshtml │ │ ├── Security │ │ │ ├── AccessDenied.cshtml │ │ │ ├── Register.cshtml │ │ │ └── SignIn.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ ├── Scripts │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ ├── jquery.min.map │ │ ├── jquery.validate.js │ │ ├── jquery.validate.min.js │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ │ └── Styles │ │ └── site.css ├── EmployeeManager.CosmosDB.EFCore │ ├── Controllers │ │ ├── EmployeeManagerController.cs │ │ └── SecurityController.cs │ ├── EmployeeManager.CosmosDB.csproj │ ├── EmployeeManager.CosmosDB.sln │ ├── Models │ │ ├── AppDbContext.cs │ │ ├── AppUser.cs │ │ ├── Country.cs │ │ ├── Employee.cs │ │ ├── Register.cs │ │ └── SignIn.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ │ ├── EmployeeManager │ │ │ ├── Delete.cshtml │ │ │ ├── Insert.cshtml │ │ │ ├── List.cshtml │ │ │ └── Update.cshtml │ │ ├── Security │ │ │ ├── AccessDenied.cshtml │ │ │ ├── Register.cshtml │ │ │ └── SignIn.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ ├── Scripts │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ ├── jquery.min.map │ │ ├── jquery.validate.js │ │ ├── jquery.validate.min.js │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ │ └── Styles │ │ └── site.css ├── EmployeeManager.CosmosDB │ ├── Controllers │ │ ├── EmployeeManagerController.cs │ │ └── SecurityController.cs │ ├── EmployeeManager.CosmosDB.csproj │ ├── EmployeeManager.CosmosDB.sln │ ├── Models │ │ ├── AppUser.cs │ │ ├── Country.cs │ │ ├── Employee.cs │ │ ├── Register.cs │ │ └── SignIn.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ │ ├── EmployeeManager │ │ │ ├── Delete.cshtml │ │ │ ├── Insert.cshtml │ │ │ ├── List.cshtml │ │ │ └── Update.cshtml │ │ ├── Security │ │ │ ├── AccessDenied.cshtml │ │ │ ├── Register.cshtml │ │ │ └── SignIn.cshtml │ │ ├── Shared │ │ │ └── _Layout.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ │ ├── Scripts │ │ ├── jquery.js │ │ ├── jquery.min.js │ │ ├── jquery.min.map │ │ ├── jquery.validate.js │ │ ├── jquery.validate.min.js │ │ ├── jquery.validate.unobtrusive.js │ │ └── jquery.validate.unobtrusive.min.js │ │ └── Styles │ │ └── site.css └── EmployeeManager.MongoDB │ ├── Controllers │ ├── EmployeeManagerController.cs │ └── SecurityController.cs │ ├── EmployeeManager.MongoDB.csproj │ ├── EmployeeManager.MongoDB.sln │ ├── Models │ ├── AppUser.cs │ ├── Country.cs │ ├── Employee.cs │ ├── Register.cs │ └── SignIn.cs │ ├── Program.cs │ ├── Properties │ └── launchSettings.json │ ├── Startup.cs │ ├── Views │ ├── EmployeeManager │ │ ├── Delete.cshtml │ │ ├── Insert.cshtml │ │ ├── List.cshtml │ │ └── Update.cshtml │ ├── Security │ │ ├── AccessDenied.cshtml │ │ ├── Register.cshtml │ │ └── SignIn.cshtml │ ├── Shared │ │ └── _Layout.cshtml │ ├── _ViewImports.cshtml │ └── _ViewStart.cshtml │ ├── appsettings.Development.json │ ├── appsettings.json │ └── wwwroot │ ├── Scripts │ ├── jquery.js │ ├── jquery.min.js │ ├── jquery.min.map │ ├── jquery.validate.js │ ├── jquery.validate.min.js │ ├── jquery.validate.unobtrusive.js │ └── jquery.validate.unobtrusive.min.js │ └── Styles │ └── site.css ├── Contributing.md ├── LICENSE.txt ├── README.md └── Scripts ├── 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 /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /9781484255087.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-database-prog-using-asp.net-core-3/2479b490874c127b5eba1a43b492a6fe4828fadf/9781484255087.jpg -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Controllers/HomeController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using HelloWorldMVC.Models; 7 | 8 | 9 | namespace HelloWorldMVC.Controllers 10 | { 11 | public class HomeController : Controller 12 | { 13 | public IActionResult Index() 14 | { 15 | AppMessage obj = new AppMessage() { 16 | Message = "Hello World!" 17 | }; 18 | return View(obj); 19 | } 20 | 21 | [HttpPost] 22 | public IActionResult Index(AppMessage obj) 23 | { 24 | ViewBag.Message = "Message changed."; 25 | return View(obj); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/HelloWorldMVC.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/HelloWorldMVC.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldMVC", "HelloWorldMVC.csproj", "{8334EA31-D21D-4B37-BD6D-5F519AB01E9A}" 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 | {8334EA31-D21D-4B37-BD6D-5F519AB01E9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8334EA31-D21D-4B37-BD6D-5F519AB01E9A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8334EA31-D21D-4B37-BD6D-5F519AB01E9A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8334EA31-D21D-4B37-BD6D-5F519AB01E9A}.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 = {C7786191-7DD4-4B6C-AFFA-2CADFDB12071} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Models/AppMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace HelloWorldMVC.Models 7 | { 8 | public class AppMessage 9 | { 10 | public string Message { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace HelloWorldMVC 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49328", 7 | "sslPort": 44338 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "HelloWorldMVC": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | 11 | 12 | namespace HelloWorldMVC 13 | { 14 | public class Startup 15 | { 16 | public void ConfigureServices(IServiceCollection services) 17 | { 18 | services.AddControllersWithViews(); 19 | } 20 | 21 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 22 | { 23 | if (env.IsDevelopment()) 24 | { 25 | app.UseDeveloperExceptionPage(); 26 | } 27 | 28 | app.UseStaticFiles(); 29 | 30 | app.UseRouting(); 31 | 32 | app.UseEndpoints(endpoints => 33 | { 34 | endpoints.MapControllerRoute( 35 | name: "default", 36 | pattern: "{controller=Home}/{action=Index}/{id?}"); 37 | }); 38 | 39 | 40 | 41 | 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Views/Home/Index.cshtml: -------------------------------------------------------------------------------- 1 | @model HelloWorldMVC.Models.AppMessage 2 | 3 | 4 | 5 | Hello World App 6 | 7 | 8 |

@Model.Message

9 |
10 |

@ViewBag.Message

11 |
12 | 13 |

14 | 15 |

16 | 17 |
18 | 19 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @addTagHelper *,Microsoft.AspNetCore.Mvc.TagHelpers 2 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldMVC/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/HelloWorldRazorPages.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/HelloWorldRazorPages.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldRazorPages", "HelloWorldRazorPages.csproj", "{FC77A0F8-C1E3-410E-B18F-E86369845D08}" 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 | {FC77A0F8-C1E3-410E-B18F-E86369845D08}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {FC77A0F8-C1E3-410E-B18F-E86369845D08}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {FC77A0F8-C1E3-410E-B18F-E86369845D08}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {FC77A0F8-C1E3-410E-B18F-E86369845D08}.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 = {EE279264-469E-46A1-AD8B-74E665B5962B} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Models/AppMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace HelloWorldRazorPages.Models 7 | { 8 | public class AppMessage 9 | { 10 | public string Message { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Pages/Index.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | 3 | @model HelloWorldRazorPages.Pages.IndexModel 4 | 5 | 6 | 7 | Hello World App 8 | 9 | 10 |

@Model.Heading.Message

11 |
12 |

@Model.SubHeading

13 |
14 | 15 |

16 | 17 |

18 | 19 |
20 | 21 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Pages/Index.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | using HelloWorldRazorPages.Models; 8 | 9 | 10 | namespace HelloWorldRazorPages.Pages 11 | { 12 | public class IndexModel : PageModel 13 | { 14 | [BindProperty] 15 | public AppMessage Heading { get; set; } 16 | 17 | public string SubHeading { get; set; } 18 | 19 | public void OnGet() 20 | { 21 | this.Heading = new AppMessage(); 22 | this.Heading.Message = "Hello World!"; 23 | } 24 | 25 | public void OnPost() 26 | { 27 | this.SubHeading = "Message changed."; 28 | } 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Pages/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @addTagHelper *,Microsoft.AspNetCore.Mvc.TagHelpers 2 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace HelloWorldRazorPages 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49291", 7 | "sslPort": 44308 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "HelloWorldRazorPages": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Http; 8 | using Microsoft.Extensions.DependencyInjection; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.AspNetCore.Routing; 11 | 12 | 13 | namespace HelloWorldRazorPages 14 | { 15 | public class Startup 16 | { 17 | public void ConfigureServices(IServiceCollection services) 18 | { 19 | services.AddRazorPages(); 20 | } 21 | 22 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 23 | { 24 | if (env.IsDevelopment()) 25 | { 26 | app.UseDeveloperExceptionPage(); 27 | } 28 | 29 | app.UseStaticFiles(); 30 | 31 | app.UseRouting(); 32 | 33 | app.UseEndpoints(endpoints => 34 | { 35 | endpoints.MapRazorPages(); 36 | }); 37 | 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldRazorPages/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/Controllers/ValuesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using HelloWorldWebApi.Models; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | 9 | 10 | namespace HelloWorldWebApi.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | 14 | public class ValuesController : Controller 15 | { 16 | [HttpGet] 17 | public IEnumerable Get() 18 | { 19 | List messages = new List(); 20 | messages.Add(new AppMessage() { Message = "Hello World!" }); 21 | messages.Add(new AppMessage() { Message = "Hello Galaxy!" }); 22 | messages.Add(new AppMessage() { Message = "Hello Universe!" }); 23 | 24 | return messages; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/HelloWorldWebApi.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/HelloWorldWebApi.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HelloWorldWebApi", "HelloWorldWebApi.csproj", "{1BF5E068-E411-4A17-96D4-01CF61B57FFB}" 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 | {1BF5E068-E411-4A17-96D4-01CF61B57FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1BF5E068-E411-4A17-96D4-01CF61B57FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1BF5E068-E411-4A17-96D4-01CF61B57FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1BF5E068-E411-4A17-96D4-01CF61B57FFB}.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 = {BFD3A840-363F-44C9-8E13-3CB503CFB151} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/Models/AppMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace HelloWorldWebApi.Models 7 | { 8 | public class AppMessage 9 | { 10 | public string Message { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace HelloWorldWebApi 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49318", 7 | "sslPort": 44382 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "HelloWorldWebApi": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Options; 12 | using Microsoft.Extensions.Hosting; 13 | 14 | 15 | namespace HelloWorldWebApi 16 | { 17 | public class Startup 18 | { 19 | public void ConfigureServices(IServiceCollection services) 20 | { 21 | services.AddControllers(); 22 | //.AddNewtonsoftJson(); 23 | } 24 | 25 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 26 | { 27 | if (env.IsDevelopment()) 28 | { 29 | app.UseDeveloperExceptionPage(); 30 | } 31 | 32 | app.UseStaticFiles(); 33 | 34 | app.UseRouting(); 35 | 36 | app.UseEndpoints(endpoints => 37 | { 38 | endpoints.MapControllers(); 39 | }); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_01/HelloWorldWebApi/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "Microsoft.Hosting.Lifetime": "Information" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/EmployeeManager.Mvc.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/EmployeeManager.Mvc.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManager.Mvc", "EmployeeManager.Mvc.csproj", "{7AA2A14B-400B-4A7A-A8BE-91828D44F99C}" 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 | {7AA2A14B-400B-4A7A-A8BE-91828D44F99C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {7AA2A14B-400B-4A7A-A8BE-91828D44F99C}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {7AA2A14B-400B-4A7A-A8BE-91828D44F99C}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {7AA2A14B-400B-4A7A-A8BE-91828D44F99C}.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 = {A7F573F6-6FA6-454E-8FB9-EB17EDDEC625} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | 12 | namespace EmployeeManager.Mvc.Models 13 | { 14 | public class AppDbContext:DbContext 15 | { 16 | 17 | public AppDbContext(DbContextOptions options) : base(options) 18 | { 19 | 20 | } 21 | 22 | 23 | public DbSet Employees { get; set; } 24 | 25 | public DbSet Countries { get; set; } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.Mvc.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.Mvc.Models 10 | { 11 | public class Register 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Compare("Password")] 23 | [Display(Name = "Confirm Password")] 24 | public string ConfirmPassword { get; set; } 25 | 26 | [Required] 27 | [Display(Name = "Email")] 28 | [EmailAddress] 29 | public string Email { get; set; } 30 | 31 | [Required] 32 | [Display(Name = "Full Name")] 33 | public string FullName { get; set; } 34 | 35 | [Required] 36 | [Display(Name = "Birth Date")] 37 | public DateTime BirthDate { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.Mvc.Models 10 | { 11 | public class SignIn 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Display(Name = "Remember Me")] 23 | public bool RememberMe { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.Mvc 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49438", 7 | "sslPort": 44383 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.Mvc": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Security/AppIdentityDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | namespace EmployeeManager.Mvc.Security 10 | { 11 | public class AppIdentityDbContext : IdentityDbContext 12 | { 13 | public AppIdentityDbContext 14 | (DbContextOptions options) 15 | : base(options) 16 | { 17 | //nothing here 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Security/AppIdentityRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.Mvc.Security 10 | { 11 | public class AppIdentityRole : IdentityRole 12 | { 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Security/AppIdentityUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.Mvc.Security 10 | { 11 | public class AppIdentityUser : IdentityUser 12 | { 13 | public string FullName { get; set; } 14 | public DateTime BirthDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 | 4 |

List of Employees

5 | 6 |

@TempData["Message"]

7 | 8 | Insert 11 | 12 |

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | @foreach(var item in Model) 23 | { 24 | 25 | 26 | 27 | 28 | 29 | 34 | 39 | 40 | } 41 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 30 | Update 33 | 35 | Delete 38 |
-------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 |
:
:
:
21 | 22 |
25 |
26 | 27 |

Create New User Account

28 | 29 |
-------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 |

13 | Employee Manager 14 |

15 |
16 |
17 | @RenderBody() 18 |
19 |
20 |
21 | @if (User.Identity.IsAuthenticated) 22 | { 23 |

You are signed in as @User.Identity.Name

24 |
25 | 26 |
27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.Mvc 2 | @using EmployeeManager.Mvc.Models 3 | @using EmployeeManager.Mvc.Security 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.Authorization 6 | 7 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 8 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_03/EmployeeManager.Mvc/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "ConnectionStrings": { 10 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/EmployeeManager.RazorPages.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/EmployeeManager.RazorPages.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManager.RazorPages", "EmployeeManager.RazorPages.csproj", "{131EBF3B-5FDB-430B-A4DF-12FCB6B36A18}" 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 | {131EBF3B-5FDB-430B-A4DF-12FCB6B36A18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {131EBF3B-5FDB-430B-A4DF-12FCB6B36A18}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {131EBF3B-5FDB-430B-A4DF-12FCB6B36A18}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {131EBF3B-5FDB-430B-A4DF-12FCB6B36A18}.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 = {03B97247-3604-47DA-8DCB-8C77DE276D2C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | 10 | namespace EmployeeManager.RazorPages.Models 11 | { 12 | public class AppDbContext:DbContext 13 | { 14 | 15 | public AppDbContext(DbContextOptions options) : base(options) 16 | { 17 | 18 | } 19 | 20 | 21 | public DbSet Employees { get; set; } 22 | 23 | public DbSet Countries { get; set; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.RazorPages.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.RazorPages.Models 10 | { 11 | public class Register 12 | { 13 | [Required] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Compare("Password")] 21 | public string ConfirmPassword { get; set; } 22 | 23 | [Required] 24 | [EmailAddress] 25 | public string Email { get; set; } 26 | 27 | [Required] 28 | public string FullName { get; set; } 29 | 30 | [Required] 31 | public DateTime BirthDate { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.RazorPages.Models 10 | { 11 | public class SignIn 12 | { 13 | [Required] 14 | public string UserName { get; set; } 15 | [Required] 16 | [DataType(DataType.Password)] 17 | public string Password { get; set; } 18 | [Required] 19 | public bool RememberMe { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | 3 | @model ListModel 4 | 5 |

List of Employees

6 | 7 |

@TempData["Message"]

8 | 9 | Insert 10 | 11 |

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @foreach (var item in Model.Employees) 22 | { 23 | 24 | 25 | 26 | 27 | 28 | 33 | 37 | 38 | } 39 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 29 | Update 32 | 34 | Delete 36 |
-------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/EmployeeManager/List.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | using EmployeeManager.RazorPages.Models; 8 | using Microsoft.AspNetCore.Authorization; 9 | using Microsoft.EntityFrameworkCore; 10 | 11 | 12 | namespace EmployeeManager.RazorPages.Pages 13 | { 14 | [Authorize(Roles = "Manager")] 15 | public class ListModel : PageModel 16 | { 17 | private readonly AppDbContext db = null; 18 | 19 | public List Employees { get; set; } 20 | 21 | public ListModel(AppDbContext db) 22 | { 23 | this.db = db; 24 | } 25 | 26 | public void OnGet() 27 | { 28 | this.Employees = (from e in db.Employees orderby e.EmployeeID select e).ToList(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model ErrorModel 3 | 4 |

5 | Unexpected error while processing this request. 6 |

7 | 8 |

@Model.Code

9 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | 8 | namespace EmployeeManager.RazorPages.Pages 9 | { 10 | public class ErrorModel : PageModel 11 | { 12 | public string Code { get; set; } 13 | 14 | public void OnGet([FromQuery]int code) 15 | { 16 | if (code > 0) 17 | { 18 | this.Code = "Status Code : " + code; 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model AccessDeniedModel 3 | @{ 4 | } 5 | 6 |

7 | There was an unexpected error while signing in to the system. 8 |

-------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Security/AccessDenied.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | 8 | namespace EmployeeManager.RazorPages.Pages.Security 9 | { 10 | public class AccessDeniedModel : PageModel 11 | { 12 | public void OnGet() 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model SignInModel 3 | @{ 4 | } 5 | 6 | 7 | 8 |

Sign In

9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 |
25 | 26 |
29 |
30 | 31 |

Create New User Account

32 | 33 |
-------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Security/SignOut.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model SignOutModel 3 | @{ 4 | } 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Security/SignOut.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | using EmployeeManager.RazorPages.Models; 8 | using Microsoft.AspNetCore.Identity; 9 | using EmployeeManager.RazorPages.Security; 10 | using Microsoft.AspNetCore.Authorization; 11 | 12 | namespace EmployeeManager.RazorPages.Pages.Security 13 | { 14 | [Authorize] 15 | public class SignOutModel : PageModel 16 | { 17 | private readonly SignInManager signinManager; 18 | 19 | public SignOutModel(SignInManager signinManager) 20 | { 21 | this.signinManager = signinManager; 22 | } 23 | 24 | public async Task OnPostAsync() 25 | { 26 | await signinManager.SignOutAsync(); 27 | return RedirectToPage("/Security/SignIn"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Employee Manager 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | Employee Manager 15 |

16 |
17 |
18 | @RenderBody() 19 |
20 | 21 |
22 |
23 | @if (User.Identity.IsAuthenticated) 24 | { 25 |

You are signed in as @User.Identity.Name

26 |
27 | 28 |
29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.RazorPages 2 | @using EmployeeManager.RazorPages.Pages 3 | @using EmployeeManager.RazorPages.Pages.Security 4 | @using EmployeeManager.RazorPages.Models 5 | 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 7 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Pages/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.RazorPages 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49607", 7 | "sslPort": 44322 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.RazorPages": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Security/AppIdentityDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | namespace EmployeeManager.RazorPages.Security 12 | { 13 | public class AppIdentityDbContext : IdentityDbContext 14 | { 15 | public AppIdentityDbContext 16 | (DbContextOptions options) 17 | : base(options) 18 | { 19 | //nothing here 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Security/AppIdentityRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.RazorPages.Security 10 | { 11 | public class AppIdentityRole : IdentityRole 12 | { 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/Security/AppIdentityUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.RazorPages.Security 10 | { 11 | public class AppIdentityUser : IdentityUser 12 | { 13 | public string FullName { get; set; } 14 | public DateTime BirthDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_04/EmployeeManager.RazorPages/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "ConnectionStrings": { 10 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Controllers/CountriesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using EmployeeManager.Api.Models; 7 | using Microsoft.EntityFrameworkCore; 8 | using EmployeeManager.Api.Repositories; 9 | 10 | 11 | namespace EmployeeManager.Api.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | public class CountriesController : ControllerBase 15 | { 16 | 17 | private readonly ICountryRepository countryRepository = null; 18 | 19 | public CountriesController(ICountryRepository countryRepository) 20 | { 21 | this.countryRepository = countryRepository; 22 | } 23 | 24 | 25 | [HttpGet] 26 | public List Get() 27 | { 28 | return countryRepository.SelectAll(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/EmployeeManager.Api.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | 10 | namespace EmployeeManager.Api.Models 11 | { 12 | public class AppDbContext:DbContext 13 | { 14 | 15 | public AppDbContext(DbContextOptions options) : base(options) 16 | { 17 | 18 | } 19 | 20 | 21 | public DbSet Employees { get; set; } 22 | 23 | public DbSet Countries { get; set; } 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.Api.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.Api 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49683", 7 | "sslPort": 44364 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.Api": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Repositories/CountrySqlRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Api.Models; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | namespace EmployeeManager.Api.Repositories 10 | { 11 | public class CountrySqlRepository : ICountryRepository 12 | { 13 | 14 | private readonly AppDbContext db = null; 15 | 16 | public CountrySqlRepository(AppDbContext db) 17 | { 18 | this.db = db; 19 | } 20 | 21 | public List SelectAll() 22 | { 23 | List data = db.Countries.FromSqlRaw("SELECT CountryID, Name FROM Countries ORDER BY Name ASC").ToList(); 24 | return data; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Repositories/CountryStProcRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Api.Models; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | namespace EmployeeManager.Api.Repositories 10 | { 11 | public class CountryStProcRepository : ICountryRepository 12 | { 13 | 14 | private readonly AppDbContext db = null; 15 | 16 | public CountryStProcRepository(AppDbContext db) 17 | { 18 | this.db = db; 19 | } 20 | 21 | public List SelectAll() 22 | { 23 | List data = db.Countries.FromSqlRaw("EXEC Countries_SelectAll").ToList(); 24 | return data; 25 | } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Repositories/ICountryRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Api.Models; 6 | 7 | 8 | namespace EmployeeManager.Api.Repositories 9 | { 10 | public interface ICountryRepository 11 | { 12 | List SelectAll(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/Repositories/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Api.Models; 6 | 7 | 8 | namespace EmployeeManager.Api.Repositories 9 | { 10 | public interface IEmployeeRepository 11 | { 12 | List SelectAll(); 13 | Employee SelectByID(int id); 14 | void Insert(Employee emp); 15 | void Update(Employee emp); 16 | void Delete(int id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "ConnectionStrings": { 10 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/EmployeeManager.ApiClient.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/EmployeeManager.ApiClient.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29006.145 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManager.ApiClient", "EmployeeManager.ApiClient.csproj", "{8D31A0A7-4C22-4FFF-BC99-C64BA0EB74DD}" 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 | {8D31A0A7-4C22-4FFF-BC99-C64BA0EB74DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {8D31A0A7-4C22-4FFF-BC99-C64BA0EB74DD}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {8D31A0A7-4C22-4FFF-BC99-C64BA0EB74DD}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {8D31A0A7-4C22-4FFF-BC99-C64BA0EB74DD}.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 = {1AAF8F17-5F18-4A20-9AA3-F2561CA10CCD} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.ApiClient.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.ApiClient.Models 10 | { 11 | public class Register 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Compare("Password")] 23 | [Display(Name = "Confirm Password")] 24 | public string ConfirmPassword { get; set; } 25 | 26 | [Required] 27 | [Display(Name = "Email")] 28 | [EmailAddress] 29 | public string Email { get; set; } 30 | 31 | [Required] 32 | [Display(Name = "Full Name")] 33 | public string FullName { get; set; } 34 | 35 | [Required] 36 | [Display(Name = "Birth Date")] 37 | public DateTime BirthDate { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.ApiClient.Models 10 | { 11 | public class SignIn 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Display(Name = "Remember Me")] 23 | public bool RememberMe { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Models/WebApiConfig.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.ApiClient.Models 7 | { 8 | public class WebApiConfig 9 | { 10 | public string BaseUrl { get; set; } 11 | public string EmployeesApiUrl { get; set; } 12 | public string CountriesApiUrl { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.ApiClient 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49716", 7 | "sslPort": 44390 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.ApiClient": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Security/AppIdentityDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | namespace EmployeeManager.ApiClient.Security 12 | { 13 | public class AppIdentityDbContext : IdentityDbContext 14 | { 15 | public AppIdentityDbContext 16 | (DbContextOptions options) 17 | : base(options) 18 | { 19 | //nothing here 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Security/AppIdentityRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.ApiClient.Security 10 | { 11 | public class AppIdentityRole : IdentityRole 12 | { 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Security/AppIdentityUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.ApiClient.Security 10 | { 11 | public class AppIdentityUser : IdentityUser 12 | { 13 | public string FullName { get; set; } 14 | public DateTime BirthDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 |

List of Employees

4 | 5 |

@TempData["Message"]

6 | 7 | @Html.ActionLink("Insert","Insert","EmployeeManager",null,new { @class= "linkbutton" }) 8 | 9 |

10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | @foreach(var item in Model) 20 | { 21 | 22 | 23 | 24 | 25 | 26 | 29 | 32 | 33 | } 34 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 27 | @Html.ActionLink("Update", "Update", "EmployeeManager", new { id=item.EmployeeID },new { @class="linkbutton"}) 28 | 30 | @Html.ActionLink("Delete", "Delete", "EmployeeManager", new { id = item.EmployeeID }, new { @class = "linkbutton" }) 31 |
-------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/Security/Register.cshtml: -------------------------------------------------------------------------------- 1 | @model Register 2 | 3 | 4 |

Create New User Account

5 | 6 | @using (Html.BeginForm("Register", "Security", FormMethod.Post)) 7 | { 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 | 33 | 34 | 37 | 38 |
@Html.LabelFor(m=>m.UserName) :@Html.TextBoxFor(m=>m.UserName)
@Html.LabelFor(m => m.Password) :@Html.PasswordFor(m=>m.Password)
@Html.LabelFor(m => m.ConfirmPassword) :@Html.PasswordFor(m => m.ConfirmPassword)
@Html.LabelFor(m => m.Email) :@Html.TextBoxFor(m => m.Email)
@Html.LabelFor(m => m.FullName) :@Html.TextBoxFor(m => m.FullName)
@Html.LabelFor(m => m.BirthDate) :@Html.TextBoxFor(m => m.BirthDate, null, new { type = "date" })
35 | 36 |
39 | @Html.ValidationSummary(null,new { @class="message" }) 40 | 41 |

@Html.ActionLink("Go To Login Page", "SignIn", "Security")

42 | 43 | } -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 | 6 | @using (Html.BeginForm("SignIn", "Security", FormMethod.Post)) 7 | { 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 25 | 26 |
@Html.LabelFor(m => m.UserName) :@Html.TextBoxFor(m => m.UserName)
@Html.LabelFor(m => m.Password) :@Html.PasswordFor(m => m.Password)
@Html.LabelFor(m => m.RememberMe) :@Html.CheckBoxFor(m => m.RememberMe)
23 | 24 |
27 | @Html.ValidationSummary(null, new { @class = "message" }) 28 | 29 |

@Html.ActionLink("Create New User Account", "Register", "Security")

30 | 31 | } -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 |

13 | Employee Manager 14 |

15 |
16 |
17 | @RenderBody() 18 |
19 |
20 |
21 | @if (User.Identity.IsAuthenticated) 22 | { 23 |

You are signed in as @User.Identity.Name

24 | @using (Html.BeginForm("SignOut", "Security", FormMethod.Post)) 25 | { 26 | 27 | } 28 | } 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.ApiClient 2 | @using EmployeeManager.ApiClient.Models 3 | @using EmployeeManager.ApiClient.Security 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.Authorization 6 | 7 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 8 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_05/EmployeeManager.ApiClient/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "AppSettings": { 3 | "BaseUrl": "https://localhost:44364", 4 | "EmployeesApiUrl": "/api/employees", 5 | "CountriesApiUrl": "/api/countries" 6 | }, 7 | 8 | "ConnectionStrings": { 9 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Controllers/CountriesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using EmployeeManager.Jquery.Models; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.AspNetCore.Authorization; 9 | 10 | namespace EmployeeManager.Jquery.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [Authorize(Roles = "Manager")] 14 | public class CountriesController : ControllerBase 15 | { 16 | 17 | private readonly AppDbContext db = null; 18 | 19 | public CountriesController(AppDbContext db) 20 | { 21 | this.db = db; 22 | } 23 | 24 | 25 | [HttpGet] 26 | public async Task> GetAsync() 27 | { 28 | List countries=await db.Countries.ToListAsync(); 29 | return countries; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Controllers/EmployeeManagerController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | 9 | 10 | namespace EmployeeManager.Jquery.Controllers 11 | { 12 | public class EmployeeManagerController : Controller 13 | { 14 | public IActionResult List() 15 | { 16 | return View(); 17 | } 18 | 19 | public IActionResult Insert() 20 | { 21 | return View(); 22 | } 23 | 24 | public IActionResult Update(int id) 25 | { 26 | ViewBag.EmployeeID = id; 27 | return View(); 28 | } 29 | 30 | public IActionResult Delete(int id) 31 | { 32 | ViewBag.EmployeeID = id; 33 | return View(); 34 | } 35 | 36 | public IActionResult Register() 37 | { 38 | return View(); 39 | } 40 | 41 | public IActionResult SignIn() 42 | { 43 | return View(); 44 | } 45 | 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/EmployeeManager.Jquery.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/EmployeeManager.Jquery.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28729.10 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManager.Jquery", "EmployeeManager.Jquery.csproj", "{3C34B927-EB81-4170-B393-9627923F6F37}" 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 | {3C34B927-EB81-4170-B393-9627923F6F37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {3C34B927-EB81-4170-B393-9627923F6F37}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {3C34B927-EB81-4170-B393-9627923F6F37}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {3C34B927-EB81-4170-B393-9627923F6F37}.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 = {58AEFE8F-7AF2-4C42-A58A-341D843F1CB8} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.EntityFrameworkCore; 9 | using EmployeeManager.Jquery.Security; 10 | 11 | 12 | namespace EmployeeManager.Jquery.Models 13 | { 14 | public class AppDbContext:DbContext 15 | { 16 | 17 | public AppDbContext(DbContextOptions options) : base(options) 18 | { 19 | 20 | } 21 | 22 | 23 | public DbSet Employees { get; set; } 24 | 25 | public DbSet Countries { get; set; } 26 | 27 | public DbSet Users { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.Jquery.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | 8 | 9 | namespace EmployeeManager.Jquery.Models 10 | { 11 | public class Employee 12 | { 13 | [Key] 14 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 15 | [Required] 16 | [Display(Name ="Employee ID")] 17 | public int EmployeeID { get; set; } 18 | 19 | [Required] 20 | [StringLength(10)] 21 | [Display(Name = "First Name")] 22 | public string FirstName { get; set; } 23 | 24 | [Required] 25 | [StringLength(20)] 26 | [Display(Name = "Last Name")] 27 | public string LastName { get; set; } 28 | 29 | [Required] 30 | [StringLength(30)] 31 | [Display(Name = "Title")] 32 | public string Title { get; set; } 33 | 34 | [Required] 35 | [Display(Name = "Birth Date")] 36 | public DateTime BirthDate { get; set; } 37 | 38 | [Required] 39 | [Display(Name = "Hire Date")] 40 | public DateTime HireDate { get; set; } 41 | 42 | 43 | [Required] 44 | [StringLength(15)] 45 | [Display(Name = "Country")] 46 | [Column("Country")] 47 | public string Country { get; set; } 48 | 49 | 50 | [StringLength(500)] 51 | [Display(Name = "Notes")] 52 | public string Notes { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace EmployeeManager.Jquery 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49578", 7 | "sslPort": 44351 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.Jquery": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Security/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.Jquery.Security 8 | { 9 | public class Register 10 | { 11 | 12 | [Required] 13 | [Display(Name = "User Name")] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | [Display(Name = "Password")] 18 | public string Password { get; set; } 19 | 20 | [Required] 21 | [Compare("Password")] 22 | [Display(Name = "Confirm Password")] 23 | public string ConfirmPassword { get; set; } 24 | 25 | [Required] 26 | [Display(Name = "Email")] 27 | [EmailAddress] 28 | public string Email { get; set; } 29 | 30 | [Required] 31 | [Display(Name = "Full Name")] 32 | public string FullName { get; set; } 33 | 34 | [Required] 35 | [Display(Name = "Birth Date")] 36 | public DateTime BirthDate { get; set; } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Security/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.Jquery.Security 8 | { 9 | public class SignIn 10 | { 11 | [Required] 12 | [Display(Name = "User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Security/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | 8 | 9 | namespace EmployeeManager.Jquery.Security 10 | { 11 | public class User 12 | { 13 | [Key] 14 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 15 | [Required] 16 | [Display(Name ="User ID")] 17 | public int UserID { get; set; } 18 | 19 | [Required] 20 | [StringLength(20)] 21 | [Display(Name = "User Name")] 22 | public string UserName { get; set; } 23 | 24 | [Required] 25 | [StringLength(20)] 26 | [Display(Name = "Password")] 27 | public string Password { get; set; } 28 | 29 | 30 | [Required] 31 | [Display(Name = "Email")] 32 | [EmailAddress] 33 | public string Email { get; set; } 34 | 35 | [Required] 36 | [Display(Name = "Full Name")] 37 | public string FullName { get; set; } 38 | 39 | [Required] 40 | [Display(Name = "Birth Date")] 41 | public DateTime BirthDate { get; set; } 42 | 43 | 44 | [Required] 45 | [StringLength(50)] 46 | [Display(Name = "Role")] 47 | public string Role { get; set; } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Employee Manager 7 | 8 | 9 | 10 | 11 | 12 |

13 | Employee Manager 14 |

15 |
16 |
17 | @RenderBody() 18 |
19 |
20 |
21 | 22 | 38 | 39 |

40 |
41 | 42 |
43 | 44 | 45 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.Jquery 2 | @using EmployeeManager.Jquery.Models 3 | @using EmployeeManager.Jquery.Security 4 | 5 | 6 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 7 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_06/EmployeeManager.Jquery/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "ConnectionStrings": { 10 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 11 | }, 12 | 13 | "Jwt": { 14 | "Key": "c65decd0-c396-4083-a71e-f8ad42cf7f7d", 15 | "Issuer": "Employee Manager Security API", 16 | "Audience": "Employee Manager Client App" 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Controllers/CountriesController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using EmployeeManager.Angular.Models; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.AspNetCore.Authorization; 9 | 10 | namespace EmployeeManager.Angular.Controllers 11 | { 12 | [Route("api/[controller]")] 13 | [Authorize(Roles = "Manager")] 14 | public class CountriesController : ControllerBase 15 | { 16 | 17 | private readonly AppDbContext db = null; 18 | 19 | public CountriesController(AppDbContext db) 20 | { 21 | this.db = db; 22 | } 23 | 24 | 25 | [HttpGet] 26 | public async Task GetAsync() 27 | { 28 | List countries = await db.Countries.ToListAsync(); 29 | return Ok(countries); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Controllers/SpaController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.AspNetCore.Mvc; 7 | 8 | 9 | namespace EmployeeManager.Angular.Controllers 10 | { 11 | public class SpaController : Controller 12 | { 13 | public IActionResult Index([FromServices]IWebHostEnvironment env) 14 | { 15 | return new PhysicalFileResult(env.WebRootPath + "/index.html", "text/html"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/EmployeeManager.Angular.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/EmployeeManager.Angular.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29006.145 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManager.Angular", "EmployeeManager.Angular.csproj", "{825FC2E4-9DBC-426C-BCB9-369E0AD26963}" 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 | {825FC2E4-9DBC-426C-BCB9-369E0AD26963}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {825FC2E4-9DBC-426C-BCB9-369E0AD26963}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {825FC2E4-9DBC-426C-BCB9-369E0AD26963}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {825FC2E4-9DBC-426C-BCB9-369E0AD26963}.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 = {C1246419-CF1F-47F4-A26C-C9301B55F30C} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.EntityFrameworkCore; 9 | using EmployeeManager.Angular.Security; 10 | 11 | 12 | namespace EmployeeManager.Angular.Models 13 | { 14 | public class AppDbContext:DbContext 15 | { 16 | 17 | public AppDbContext(DbContextOptions options) : base(options) 18 | { 19 | 20 | } 21 | 22 | 23 | public DbSet Employees { get; set; } 24 | 25 | public DbSet Countries { get; set; } 26 | 27 | public DbSet Users { get; set; } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.Angular.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Models/Employee.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | 8 | 9 | namespace EmployeeManager.Angular.Models 10 | { 11 | public class Employee 12 | { 13 | [Key] 14 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 15 | [Required] 16 | [Display(Name ="Employee ID")] 17 | public int EmployeeID { get; set; } 18 | 19 | [Required] 20 | [StringLength(10)] 21 | [Display(Name = "First Name")] 22 | public string FirstName { get; set; } 23 | 24 | [Required] 25 | [StringLength(20)] 26 | [Display(Name = "Last Name")] 27 | public string LastName { get; set; } 28 | 29 | [Required] 30 | [StringLength(30)] 31 | [Display(Name = "Title")] 32 | public string Title { get; set; } 33 | 34 | [Required] 35 | [Display(Name = "Birth Date")] 36 | public DateTime BirthDate { get; set; } 37 | 38 | [Required] 39 | [Display(Name = "Hire Date")] 40 | public DateTime HireDate { get; set; } 41 | 42 | 43 | [Required] 44 | [StringLength(15)] 45 | [Display(Name = "Country")] 46 | [Column("Country")] 47 | public string Country { get; set; } 48 | 49 | 50 | [StringLength(500)] 51 | [Display(Name = "Notes")] 52 | public string Notes { get; set; } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace EmployeeManager.Angular 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49578", 7 | "sslPort": 44305 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.Jquery": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Security/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.Angular.Security 8 | { 9 | public class Register 10 | { 11 | 12 | [Required] 13 | [Display(Name = "User Name")] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | [Display(Name = "Password")] 18 | public string Password { get; set; } 19 | 20 | [Required] 21 | [Compare("Password")] 22 | [Display(Name = "Confirm Password")] 23 | public string ConfirmPassword { get; set; } 24 | 25 | [Required] 26 | [Display(Name = "Email")] 27 | [EmailAddress] 28 | public string Email { get; set; } 29 | 30 | [Required] 31 | [Display(Name = "Full Name")] 32 | public string FullName { get; set; } 33 | 34 | [Required] 35 | [Display(Name = "Birth Date")] 36 | public DateTime BirthDate { get; set; } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Security/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.Angular.Security 8 | { 9 | public class SignIn 10 | { 11 | [Required] 12 | [StringLength(20)] 13 | [Display(Name = "User Name")] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | [StringLength(20)] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/Security/User.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | 8 | 9 | namespace EmployeeManager.Angular.Security 10 | { 11 | public class User 12 | { 13 | [Key] 14 | [DatabaseGenerated(DatabaseGeneratedOption.Identity)] 15 | [Required] 16 | [Display(Name = "User ID")] 17 | public int UserID { get; set; } 18 | 19 | [Required] 20 | [StringLength(20)] 21 | [Display(Name = "User Name")] 22 | public string UserName { get; set; } 23 | 24 | [Required] 25 | [StringLength(20)] 26 | [Display(Name = "Password")] 27 | public string Password { get; set; } 28 | 29 | 30 | [Required] 31 | [Display(Name = "Email")] 32 | [EmailAddress] 33 | public string Email { get; set; } 34 | 35 | [Required] 36 | [Display(Name = "Full Name")] 37 | public string FullName { get; set; } 38 | 39 | [Required] 40 | [Display(Name = "Birth Date")] 41 | public DateTime BirthDate { get; set; } 42 | 43 | 44 | [Required] 45 | [StringLength(50)] 46 | [Display(Name = "Role")] 47 | public string Role { get; set; } 48 | 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "ConnectionStrings": { 10 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 11 | }, 12 | 13 | 14 | "Jwt": { 15 | "Key": "c65decd0-c396-4083-a71e-f8ad42cf7f7d", 16 | "Issuer": "Employee Manager Security API", 17 | "Audience": "Employee Manager Client App" 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-database-prog-using-asp.net-core-3/2479b490874c127b5eba1a43b492a6fe4828fadf/Chapter_07/EmployeeManager.Angular/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManager.Angular/wwwroot/runtime-es2015.c53cfa7e76780343722f.js: -------------------------------------------------------------------------------- 1 | !function(e){function r(r){for(var n,f,i=r[0],l=r[1],a=r[2],c=0,s=[];c 0.5% 8 | last 2 versions 9 | Firefox ESR 10 | not dead 11 | not IE 9-11 -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('Welcome to EmployeeManagerAngularApp!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText() { 9 | return element(by.css('app-root h1')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "employee-manager-angular-app", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~8.1.0", 15 | "@angular/common": "~8.1.0", 16 | "@angular/compiler": "~8.1.0", 17 | "@angular/core": "~8.1.0", 18 | "@angular/forms": "~8.1.0", 19 | "@angular/platform-browser": "~8.1.0", 20 | "@angular/platform-browser-dynamic": "~8.1.0", 21 | "@angular/router": "~8.1.0", 22 | "core-js": "^2.5.4", 23 | "rxjs": "~6.5.2", 24 | "tslib": "^1.9.0", 25 | "zone.js": "~0.9.1" 26 | }, 27 | "devDependencies": { 28 | "@angular-devkit/build-angular": "~0.801.0", 29 | "@angular/cli": "~8.1.0", 30 | "@angular/compiler-cli": "~8.1.0", 31 | "@angular/language-service": "~8.1.0", 32 | "@types/node": "~8.9.4", 33 | "@types/jasmine": "~2.8.8", 34 | "@types/jasminewd2": "~2.0.3", 35 | "codelyzer": "^5.0.1", 36 | "jasmine-core": "~2.99.1", 37 | "jasmine-spec-reporter": "~4.2.1", 38 | "karma": "~4.0.0", 39 | "karma-chrome-launcher": "~2.2.0", 40 | "karma-coverage-istanbul-reporter": "~2.0.1", 41 | "karma-jasmine": "~1.1.2", 42 | "karma-jasmine-html-reporter": "^0.2.2", 43 | "protractor": "~5.4.0", 44 | "ts-node": "~7.0.0", 45 | "tslint": "~5.11.0", 46 | "typescript": "~3.4.5" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | 5 | import { EmployeeListComponent } from './employee-list/employee-list.component'; 6 | import { EmployeeInsertComponent } from './employee-insert/employee-insert.component'; 7 | import { EmployeeUpdateComponent } from './employee-update/employee-update.component'; 8 | import { EmployeeDeleteComponent } from './employee-delete/employee-delete.component'; 9 | import { SignInComponent } from './signin/signin.component'; 10 | import { RegisterComponent } from './register/register.component'; 11 | 12 | 13 | 14 | 15 | const routes: Routes = [ 16 | { path: "", redirectTo: "employees/list", pathMatch: 'full' }, 17 | { path: "register", component: RegisterComponent }, 18 | { path: "signin", component: SignInComponent }, 19 | { path: "employees/list", component: EmployeeListComponent }, 20 | { path: "employees/insert", component: EmployeeInsertComponent }, 21 | { path: "employees/update/:id", component: EmployeeUpdateComponent }, 22 | { path: "employees/delete/:id", component: EmployeeDeleteComponent }, 23 | { path: '**', component: EmployeeListComponent } 24 | ]; 25 | 26 | @NgModule({ 27 | imports: [RouterModule.forRoot(routes)], 28 | exports: [RouterModule] 29 | }) 30 | export class AppRoutingModule { } 31 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

Employee Manager

2 |
3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html' 6 | }) 7 | 8 | 9 | export class AppComponent { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/countries-api/countries-api.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | 4 | 5 | @Injectable() 6 | export class CountriesApiService { 7 | 8 | //baseUrl: string = 'http://localhost:5000/api/countries'; 9 | 10 | baseUrl: string = '/api/countries'; 11 | 12 | constructor(private _http: HttpClient) { 13 | 14 | } 15 | 16 | selectAll() { 17 | return this._http.get(this.baseUrl, { 18 | headers: new HttpHeaders({ 19 | "Authorization": "Bearer " + sessionStorage.getItem('token') 20 | }) 21 | }); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/employee-list/employee-list.component.html: -------------------------------------------------------------------------------- 1 |

List of Employees

2 | 3 | 4 | 5 |

{{message}}

6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 31 | 32 | 33 |
Employee IDFirst NameLast NameTitleAction
{{emp.employeeID}}{{emp.firstName}}{{emp.lastName}}{{emp.title}} 26 | 27 | 29 | 30 |
34 | 35 |
36 | 37 | 38 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/models/country.ts: -------------------------------------------------------------------------------- 1 | export class Country { 2 | countryID: number; 3 | name: string; 4 | } 5 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/models/employee.ts: -------------------------------------------------------------------------------- 1 | export class Employee { 2 | employeeID: number; 3 | firstName: string; 4 | lastName: string; 5 | title: string; 6 | birthDate: Date; 7 | hireDate: Date; 8 | country: string; 9 | notes: string; 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/models/user.ts: -------------------------------------------------------------------------------- 1 | export class User { 2 | userName: string; 3 | password: string; 4 | email: string; 5 | fullName: string; 6 | birthDate: Date; 7 | } 8 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/register/register.component.html: -------------------------------------------------------------------------------- 1 |

Create New User Account

2 | 3 | 4 |

{{message}}

5 | 6 | 7 |
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 | 33 | 34 | 35 | 38 | 39 |
User Name :
Password :
Confirm Password :
Email :
Full Name :
Birth Date :
36 | 37 |
40 |
41 |

42 | Go to Sign-In Page 43 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/security-api/security-api.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { HttpClient, HttpHeaders } from '@angular/common/http'; 3 | import { User } from '../models/user'; 4 | 5 | 6 | @Injectable() 7 | export class SecurityApiService { 8 | 9 | 10 | //baseUrl: string = 'http://localhost:5000/api/security'; 11 | baseUrl: string = '/api/security'; 12 | client: HttpClient; 13 | 14 | constructor(client: HttpClient) { 15 | this.client = client; 16 | } 17 | 18 | 19 | signIn(usr: User) { 20 | return this.client.post(this.baseUrl + "/signin", usr); 21 | } 22 | 23 | 24 | register(usr: User) { 25 | return this.client.post(this.baseUrl + "/register", usr, { responseType: 'text'}); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/signout/signout.component.html: -------------------------------------------------------------------------------- 1 | 2 |

You are signed in as {{userName}}

3 | 4 | 5 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/app/signout/signout.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 3 | import { Router, ActivatedRoute } from '@angular/router'; 4 | import { SecurityApiService } from '../security-api/security-api.service'; 5 | 6 | 7 | @Component({ 8 | selector: 'app-signout', 9 | templateUrl: './signout.component.html' 10 | }) 11 | export class SignOutComponent implements OnInit { 12 | 13 | userName: string; 14 | router: Router; 15 | 16 | constructor(router: Router) { 17 | this.router = router; 18 | } 19 | 20 | signout_click() { 21 | sessionStorage.removeItem('token'); 22 | sessionStorage.removeItem('userName'); 23 | this.router.navigate(["/signin"]); 24 | } 25 | 26 | ngOnInit() { 27 | this.userName = sessionStorage.getItem('userName'); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-database-prog-using-asp.net-core-3/2479b490874c127b5eba1a43b492a6fe4828fadf/Chapter_07/EmployeeManagerAngularApp/src/assets/.gitkeep -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-database-prog-using-asp.net-core-3/2479b490874c127b5eba1a43b492a6fe4828fadf/Chapter_07/EmployeeManagerAngularApp/src/favicon.ico -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false 30 | }); 31 | }; -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/main.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var core_1 = require("@angular/core"); 4 | var platform_browser_dynamic_1 = require("@angular/platform-browser-dynamic"); 5 | var app_module_1 = require("./app/app.module"); 6 | var environment_1 = require("./environments/environment"); 7 | if (environment_1.environment.production) { 8 | core_1.enableProdMode(); 9 | } 10 | platform_browser_dynamic_1.platformBrowserDynamic().bootstrapModule(app_module_1.AppModule) 11 | .catch(function (err) { return console.log(err); }); 12 | //# sourceMappingURL=main.js.map -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/main.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"main.js","sourceRoot":"","sources":["main.ts"],"names":[],"mappings":";;AAAA,sCAA+C;AAC/C,8EAA2E;AAE3E,+CAA6C;AAC7C,0DAAyD;AAEzD,IAAI,yBAAW,CAAC,UAAU,EAAE;IAC1B,qBAAc,EAAE,CAAC;CAClB;AAED,iDAAsB,EAAE,CAAC,eAAe,CAAC,sBAAS,CAAC;KAChD,KAAK,CAAC,UAAA,GAAG,IAAI,OAAA,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,EAAhB,CAAgB,CAAC,CAAC"} -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": [ 9 | "src/test.ts", 10 | "**/*.spec.ts" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": [ 7 | "jasmine", 8 | "node" 9 | ] 10 | }, 11 | "files": [ 12 | "test.ts", 13 | "polyfills.ts" 14 | ], 15 | "include": [ 16 | "**/*.spec.ts", 17 | "**/*.d.ts" 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_07/EmployeeManagerAngularApp/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "downlevelIteration": true, 6 | "outDir": "./dist/out-tsc", 7 | "sourceMap": true, 8 | "declaration": false, 9 | "module": "esnext", 10 | "moduleResolution": "node", 11 | "emitDecoratorMetadata": true, 12 | "experimentalDecorators": true, 13 | "importHelpers": true, 14 | "target": "es2015", 15 | "typeRoots": [ 16 | "node_modules/@types" 17 | ], 18 | "lib": [ 19 | "es2018", 20 | "dom" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |

You are not authorized to view this page.

6 |

To sign in click here.

7 |
8 |
9 |
10 | 11 | 12 | 13 |

Sorry, there's nothing at this address.

14 |
15 |
16 |
17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/EmployeeManager.Blazor.ServerSide.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/EmployeeManager.Blazor.ServerSide.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29006.145 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManager.Blazor.ServerSide", "EmployeeManager.Blazor.ServerSide.csproj", "{94904BDA-D2CA-420C-8E12-FAE6A7D22780}" 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 | {94904BDA-D2CA-420C-8E12-FAE6A7D22780}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {94904BDA-D2CA-420C-8E12-FAE6A7D22780}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {94904BDA-D2CA-420C-8E12-FAE6A7D22780}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {94904BDA-D2CA-420C-8E12-FAE6A7D22780}.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 = {A758AC76-D7C3-418D-BD66-63687D50E815} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.Extensions.Configuration; 6 | using Microsoft.EntityFrameworkCore; 7 | 8 | 9 | namespace EmployeeManager.Blazor.ServerSide.Models 10 | { 11 | public class AppDbContext:DbContext 12 | { 13 | 14 | public AppDbContext(DbContextOptions options) : base(options) 15 | { 16 | 17 | } 18 | 19 | 20 | public DbSet Employees { get; set; } 21 | 22 | public DbSet Countries { get; set; } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.Blazor.ServerSide.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.Blazor.ServerSide.Models 10 | { 11 | public class Register 12 | { 13 | [Required] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Compare("Password")] 21 | public string ConfirmPassword { get; set; } 22 | 23 | [Required] 24 | [EmailAddress] 25 | public string Email { get; set; } 26 | 27 | [Required] 28 | public string FullName { get; set; } 29 | 30 | [Required] 31 | public DateTime BirthDate { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.Blazor.ServerSide.Models 10 | { 11 | public class SignIn 12 | { 13 | [Required] 14 | public string UserName { get; set; } 15 | 16 | [Required] 17 | [DataType(DataType.Password)] 18 | public string Password { get; set; } 19 | 20 | [Required] 21 | public bool RememberMe { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model SignInModel 3 | @{ 4 | } 5 | 6 | 7 | 8 |

Sign In

9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 |
25 | 26 |
29 |
30 | 31 |

Create New User Account

32 | 33 |
-------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/SignOut.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model SignOutModel 3 | @{ 4 | } 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/SignOut.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | using EmployeeManager.Blazor.ServerSide.Models; 8 | using Microsoft.AspNetCore.Identity; 9 | using EmployeeManager.Blazor.ServerSide.Security; 10 | using Microsoft.AspNetCore.Authorization; 11 | 12 | namespace EmployeeManager.Blazor.ServerSide.Pages.Security 13 | { 14 | [Authorize] 15 | public class SignOutModel : PageModel 16 | { 17 | private readonly SignInManager signinManager; 18 | 19 | public SignOutModel(SignInManager signinManager) 20 | { 21 | this.signinManager = signinManager; 22 | } 23 | 24 | public async Task OnGetAsync() 25 | { 26 | await signinManager.SignOutAsync(); 27 | return RedirectToPage("/Security/SignIn"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Employee Manager 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | Employee Manager 15 |

16 |
17 |
18 | @RenderBody() 19 |
20 | 21 |
22 |
23 | @if (User.Identity.IsAuthenticated) 24 | { 25 |

You are signed in as @User.Identity.Name

26 |
27 | 28 |
29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | 2 | @using EmployeeManager.Blazor.ServerSide.Pages.Security 3 | 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/Security/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @namespace EmployeeManager.Blazor.ServerSide.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | 5 | 6 | 7 | 8 | 9 | 10 | Employee Manager 11 | 12 | 13 | 14 | 15 | @(await Html.RenderComponentAsync(RenderMode.ServerPrerendered)) 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace EmployeeManager.Blazor.ServerSide 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:50082", 7 | "sslPort": 44318 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.Blazor.ServerSide": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Repositories/CountryRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using EmployeeManager.Blazor.ServerSide.Models; 7 | using Microsoft.EntityFrameworkCore; 8 | using Microsoft.AspNetCore.Authorization; 9 | 10 | namespace EmployeeManager.Blazor.ServerSide.Repositories 11 | { 12 | public class CountryRepository : ICountryRepository 13 | { 14 | 15 | private readonly AppDbContext db = null; 16 | 17 | public CountryRepository(AppDbContext db) 18 | { 19 | this.db = db; 20 | } 21 | 22 | public List SelectAll() 23 | { 24 | return db.Countries.ToList(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Repositories/EmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using EmployeeManager.Blazor.ServerSide.Models; 7 | using Microsoft.AspNetCore.Authorization; 8 | using Microsoft.EntityFrameworkCore; 9 | using System.Data.SqlClient; 10 | using System.Data; 11 | using System.Text.Json.Serialization; 12 | 13 | 14 | namespace EmployeeManager.Blazor.ServerSide.Repositories 15 | { 16 | public class EmployeeRepository : IEmployeeRepository 17 | { 18 | 19 | private AppDbContext db = null; 20 | 21 | public EmployeeRepository(AppDbContext db) 22 | { 23 | this.db = db; 24 | } 25 | 26 | 27 | public List SelectAll() 28 | { 29 | return db.Employees.ToList(); 30 | } 31 | 32 | 33 | public Employee SelectByID(int id) 34 | { 35 | return db.Employees.Find(id); 36 | } 37 | 38 | 39 | public void Insert(Employee emp) 40 | { 41 | db.Employees.Add(emp); 42 | db.SaveChanges(); 43 | } 44 | 45 | public void Update(Employee emp) 46 | { 47 | db.Employees.Update(emp); 48 | db.SaveChanges(); 49 | } 50 | 51 | public void Delete(int id) 52 | { 53 | Employee emp = db.Employees.Find(id); 54 | db.Employees.Remove(emp); 55 | db.SaveChanges(); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Repositories/ICountryRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Blazor.ServerSide.Models; 6 | 7 | 8 | namespace EmployeeManager.Blazor.ServerSide.Repositories 9 | { 10 | public interface ICountryRepository 11 | { 12 | List SelectAll(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Repositories/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.Blazor.ServerSide.Models; 6 | 7 | 8 | namespace EmployeeManager.Blazor.ServerSide.Repositories 9 | { 10 | public interface IEmployeeRepository 11 | { 12 | List SelectAll(); 13 | Employee SelectByID(int id); 14 | void Insert(Employee emp); 15 | void Update(Employee emp); 16 | void Delete(int id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Security/AppIdentityDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | namespace EmployeeManager.Blazor.ServerSide.Security 12 | { 13 | public class AppIdentityDbContext : IdentityDbContext 14 | { 15 | public AppIdentityDbContext 16 | (DbContextOptions options) 17 | : base(options) 18 | { 19 | //nothing here 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Security/AppIdentityRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.Blazor.ServerSide.Security 10 | { 11 | public class AppIdentityRole : IdentityRole 12 | { 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Security/AppIdentityUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.Blazor.ServerSide.Security 10 | { 11 | public class AppIdentityUser : IdentityUser 12 | { 13 | public string FullName { get; set; } 14 | public DateTime BirthDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |

Employee Manager

4 | 5 |
6 | 7 |
8 | @Body 9 |
10 | 11 |
12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 |

You are signed in as @context.User.Identity.Name

20 | Sign Out 21 |
22 | 23 | 24 | 25 |
26 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Components 3 | @using Microsoft.AspNetCore.Components.Forms 4 | @using Microsoft.AspNetCore.Components.Routing 5 | @using Microsoft.JSInterop 6 | @using Microsoft.AspNetCore.Authentication 7 | @using Microsoft.AspNetCore.Authorization 8 | @using Microsoft.AspNetCore.Identity 9 | 10 | @using EmployeeManager.Blazor.ServerSide 11 | @using EmployeeManager.Blazor.ServerSide.Shared 12 | @using EmployeeManager.Blazor.ServerSide.Models 13 | @using EmployeeManager.Blazor.ServerSide.Repositories 14 | @using EmployeeManager.Blazor.ServerSide.Pages.Security 15 | 16 | @using Microsoft.AspNetCore.Components.Web 17 | @using Microsoft.AspNetCore.Components.Authorization 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | 10 | "ConnectionStrings": { 11 | "AppDb": "data source=.;initial catalog=Northwind;integrated security=true" 12 | }, 13 | 14 | "AllowedHosts": "*" 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_08/EmployeeManager.Blazor.ServerSide/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Apress/beg-database-prog-using-asp.net-core-3/2479b490874c127b5eba1a43b492a6fe4828fadf/Chapter_08/EmployeeManager.Blazor.ServerSide/wwwroot/favicon.ico -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/EmployeeManager.AzureSql.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | all 11 | runtime; build; native; contentfiles; analyzers; buildtransitive 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/EmployeeManager.AzureSql.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManager.AzureSql", "EmployeeManager.AzureSql.csproj", "{BC1B2826-0D06-45E2-BD78-F644A1FE624A}" 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 | {BC1B2826-0D06-45E2-BD78-F644A1FE624A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {BC1B2826-0D06-45E2-BD78-F644A1FE624A}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {BC1B2826-0D06-45E2-BD78-F644A1FE624A}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {BC1B2826-0D06-45E2-BD78-F644A1FE624A}.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 = {8063023D-1952-4F90-BC64-F8D444B82C56} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.Extensions.Configuration; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | 12 | namespace EmployeeManager.AzureSql.Models 13 | { 14 | public class AppDbContext:DbContext 15 | { 16 | 17 | public AppDbContext(DbContextOptions options) : base(options) 18 | { 19 | 20 | } 21 | 22 | 23 | public DbSet Employees { get; set; } 24 | 25 | public DbSet Countries { get; set; } 26 | 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | namespace EmployeeManager.AzureSql.Models 7 | { 8 | public class Country 9 | { 10 | public int CountryID { get; set; } 11 | public string Name { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.AzureSql.Models 10 | { 11 | public class Register 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Compare("Password")] 23 | [Display(Name = "Confirm Password")] 24 | public string ConfirmPassword { get; set; } 25 | 26 | [Required] 27 | [Display(Name = "Email")] 28 | [EmailAddress] 29 | public string Email { get; set; } 30 | 31 | [Required] 32 | [Display(Name = "Full Name")] 33 | public string FullName { get; set; } 34 | 35 | [Required] 36 | [Display(Name = "Birth Date")] 37 | public DateTime BirthDate { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using System.ComponentModel.DataAnnotations; 7 | 8 | 9 | namespace EmployeeManager.AzureSql.Models 10 | { 11 | public class SignIn 12 | { 13 | [Required] 14 | [Display(Name = "User Name")] 15 | public string UserName { get; set; } 16 | 17 | [Required] 18 | [Display(Name = "Password")] 19 | public string Password { get; set; } 20 | 21 | [Required] 22 | [Display(Name = "Remember Me")] 23 | public bool RememberMe { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.AzureSql 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49248", 7 | "sslPort": 44345 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.AzureSql": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Repositories/ICountryRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.AzureSql.Models; 6 | 7 | 8 | namespace EmployeeManager.AzureSql.Repositories 9 | { 10 | public interface ICountryRepository 11 | { 12 | List SelectAll(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Repositories/IEmployeeRepository.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using EmployeeManager.AzureSql.Models; 6 | 7 | 8 | namespace EmployeeManager.AzureSql.Repositories 9 | { 10 | public interface IEmployeeRepository 11 | { 12 | List SelectAll(); 13 | Employee SelectByID(int id); 14 | void Insert(Employee emp); 15 | void Update(Employee emp); 16 | void Delete(int id); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Security/AppIdentityDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | 7 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 8 | using Microsoft.EntityFrameworkCore; 9 | 10 | 11 | namespace EmployeeManager.AzureSql.Security 12 | { 13 | public class AppIdentityDbContext : IdentityDbContext 14 | { 15 | public AppIdentityDbContext 16 | (DbContextOptions options) 17 | : base(options) 18 | { 19 | //nothing here 20 | } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Security/AppIdentityRole.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.AzureSql.Security 10 | { 11 | public class AppIdentityRole : IdentityRole 12 | { 13 | public string Description { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Security/AppIdentityUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | 6 | using Microsoft.AspNetCore.Identity; 7 | 8 | 9 | namespace EmployeeManager.AzureSql.Security 10 | { 11 | public class AppIdentityUser : IdentityUser 12 | { 13 | public string FullName { get; set; } 14 | public DateTime BirthDate { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 | 4 |

List of Employees

5 | 6 |

@TempData["Message"]

7 | 8 | Insert 11 | 12 |

13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | @foreach(var item in Model) 23 | { 24 | 25 | 26 | 27 | 28 | 29 | 34 | 39 | 40 | } 41 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 30 | Update 33 | 35 | Delete 38 |
-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 |
:
:
:
21 | 22 |
25 |
26 | 27 |

Create New User Account

28 | 29 |
-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 |

13 | Employee Manager 14 |

15 |
16 |
17 | @RenderBody() 18 |
19 |
20 |
21 | @if (User.Identity.IsAuthenticated) 22 | { 23 |

You are signed in as @User.Identity.Name

24 |
25 | 26 |
27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.AzureSql 2 | @using EmployeeManager.AzureSql.Models 3 | @using EmployeeManager.AzureSql.Security 4 | @using Microsoft.AspNetCore.Identity 5 | @using Microsoft.AspNetCore.Authorization 6 | 7 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 8 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.AzureSql/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | 10 | 11 | "ConnectionStrings": { 12 | "AppDb": "your_connection_string_here" 13 | } 14 | 15 | } 16 | 17 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/EmployeeManager.CosmosDB.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/EmployeeManager.CosmosDB.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManager.CosmosDB", "EmployeeManager.CosmosDB.csproj", "{ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}" 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 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.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 = {F6257364-64A9-4FC8-9B22-F12A829BEAA1} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Models/AppDbContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.EntityFrameworkCore; 6 | using EmployeeManager.CosmosDB.Models; 7 | 8 | namespace EmployeeManager.CosmosDB.Models 9 | { 10 | public class AppDbContext:DbContext 11 | { 12 | public AppDbContext(DbContextOptions options) : base(options) 13 | { 14 | 15 | } 16 | public DbSet Employees { get; set; } 17 | public DbSet Countries { get; set; } 18 | public DbSet Users { get; set; } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Models/AppUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json; 7 | using System.ComponentModel.DataAnnotations; 8 | 9 | 10 | namespace EmployeeManager.CosmosDB.Models 11 | { 12 | [Table("Users")] 13 | public class AppUser 14 | { 15 | [Key] 16 | public Guid DocumentID { get; set; } 17 | public string UserName { get; set; } 18 | public string Password { get; set; } 19 | public string Email { get; set; } 20 | public string FullName { get; set; } 21 | public DateTime BirthDate { get; set; } 22 | public string Role { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using Newtonsoft.Json; 8 | 9 | 10 | namespace EmployeeManager.CosmosDB.Models 11 | { 12 | public class Country 13 | { 14 | [Key] 15 | public Guid DocumentID { get; set; } 16 | 17 | public int CountryID { get; set; } 18 | 19 | public string Name { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.CosmosDB.Models 8 | { 9 | public class Register 10 | { 11 | [Required] 12 | [Display(Name ="User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Compare("Password")] 21 | [Display(Name = "Confirm Password")] 22 | public string ConfirmPassword { get; set; } 23 | 24 | 25 | [Required] 26 | [Display(Name = "Email")] 27 | [EmailAddress] 28 | public string Email { get; set; } 29 | 30 | 31 | [Required] 32 | [Display(Name = "Full Name")] 33 | public string FullName { get; set; } 34 | 35 | 36 | [Required] 37 | [Display(Name = "Birth Date")] 38 | public DateTime BirthDate { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.CosmosDB.Models 8 | { 9 | public class SignIn 10 | { 11 | [Required] 12 | [Display(Name = "User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Display(Name = "Remember Me")] 21 | public bool RememberMe { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.CosmosDB 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49685", 7 | "sslPort": 44359 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.CosmosDB": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 | 4 |

List of Employees

5 | 6 |

@TempData["Message"]

7 | 8 | Insert 9 | 10 |
11 |
12 | 13 | @if (Model == null || Model.Count == 0) 14 | { 15 |
No data found.
16 | } 17 | else 18 | { 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | @foreach (var item in Model) 28 | { 29 | 30 | 31 | 32 | 33 | 34 | 39 | 44 | 45 | } 46 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 35 | Update 38 | 40 | Delete 43 |
47 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 |
:
:
:
21 | 22 |
25 |
26 | 27 |

Create New User Account

28 | 29 |
-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | Employee Manager 15 |

16 |
17 |
18 | @RenderBody() 19 |
20 |
21 |
22 | @if (User.Identity.IsAuthenticated) 23 | { 24 |

You are signed in as @User.Identity.Name

25 |
26 | 27 |
28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.CosmosDB 2 | @using EmployeeManager.CosmosDB.Models 3 | 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB.EFCore/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "CosmosDBSettings": { 10 | "Server": "your_server_here", 11 | "PrimaryKey": "your_primary_key_here", 12 | "DatabaseName": "your_database_name_here" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/EmployeeManager.CosmosDB.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/EmployeeManager.CosmosDB.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28822.285 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmployeeManager.CosmosDB", "EmployeeManager.CosmosDB.csproj", "{ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}" 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 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {ACED746B-9DAB-4B75-BAA7-A69550DE8F8E}.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 = {F6257364-64A9-4FC8-9B22-F12A829BEAA1} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Models/AppUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Newtonsoft.Json; 7 | using System.ComponentModel.DataAnnotations; 8 | 9 | 10 | namespace EmployeeManager.CosmosDB.Models 11 | { 12 | [Table("Users")] 13 | public class AppUser 14 | { 15 | [JsonProperty(PropertyName = "id")] 16 | public Guid DocumentID { get; set; } 17 | 18 | [JsonProperty(PropertyName = "userName")] 19 | public string UserName { get; set; } 20 | 21 | 22 | [JsonProperty(PropertyName = "password")] 23 | public string Password { get; set; } 24 | 25 | 26 | [JsonProperty(PropertyName = "email")] 27 | public string Email { get; set; } 28 | 29 | 30 | [JsonProperty(PropertyName = "fullName")] 31 | public string FullName { get; set; } 32 | 33 | 34 | [JsonProperty(PropertyName = "birthDate")] 35 | public DateTime BirthDate { get; set; } 36 | 37 | 38 | [JsonProperty(PropertyName = "role")] 39 | public string Role { get; set; } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.ComponentModel.DataAnnotations; 6 | using System.ComponentModel.DataAnnotations.Schema; 7 | using Newtonsoft.Json; 8 | 9 | 10 | namespace EmployeeManager.CosmosDB.Models 11 | { 12 | public class Country 13 | { 14 | [JsonProperty(PropertyName = "id")] 15 | public Guid DocumentID { get; set; } 16 | 17 | [JsonProperty(PropertyName = "countryID")] 18 | public int CountryID { get; set; } 19 | 20 | [JsonProperty(PropertyName = "name")] 21 | public string Name { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.CosmosDB.Models 8 | { 9 | public class Register 10 | { 11 | [Required] 12 | [Display(Name ="User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Compare("Password")] 21 | [Display(Name = "Confirm Password")] 22 | public string ConfirmPassword { get; set; } 23 | 24 | 25 | [Required] 26 | [Display(Name = "Email")] 27 | [EmailAddress] 28 | public string Email { get; set; } 29 | 30 | 31 | [Required] 32 | [Display(Name = "Full Name")] 33 | public string FullName { get; set; } 34 | 35 | 36 | [Required] 37 | [Display(Name = "Birth Date")] 38 | public DateTime BirthDate { get; set; } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.CosmosDB.Models 8 | { 9 | public class SignIn 10 | { 11 | [Required] 12 | [Display(Name = "User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Display(Name = "Remember Me")] 21 | public bool RememberMe { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Hosting; 6 | using Microsoft.Extensions.Configuration; 7 | using Microsoft.Extensions.Hosting; 8 | using Microsoft.Extensions.Logging; 9 | 10 | namespace EmployeeManager.CosmosDB 11 | { 12 | public class Program 13 | { 14 | public static void Main(string[] args) 15 | { 16 | CreateHostBuilder(args).Build().Run(); 17 | } 18 | 19 | public static IHostBuilder CreateHostBuilder(string[] args) => 20 | Host.CreateDefaultBuilder(args) 21 | .ConfigureWebHostDefaults(webBuilder => 22 | { 23 | webBuilder.UseStartup(); 24 | }); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49685", 7 | "sslPort": 44389 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.CosmosDB": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 | 4 |

List of Employees

5 | 6 |

@TempData["Message"]

7 | 8 | Insert 9 | 10 |
11 |
12 | 13 | @if (Model == null || Model.Count == 0) 14 | { 15 |
No data found.
16 | } 17 | else 18 | { 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | @foreach (var item in Model) 28 | { 29 | 30 | 31 | 32 | 33 | 34 | 39 | 44 | 45 | } 46 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 35 | Update 38 | 40 | Delete 43 |
47 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 |
:
:
:
21 | 22 |
25 |
26 | 27 |

Create New User Account

28 | 29 |
-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Employee Manager 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | Employee Manager 15 |

16 |
17 |
18 | @RenderBody() 19 |
20 |
21 |
22 | @if (User.Identity.IsAuthenticated) 23 | { 24 |

You are signed in as @User.Identity.Name

25 |
26 | 27 |
28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.CosmosDB 2 | @using EmployeeManager.CosmosDB.Models 3 | 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.CosmosDB/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "CosmosDBSettings": { 10 | "Server": "your_server_here", 11 | "PrimaryKey": "your_primary_key_here", 12 | "DatabaseName": "Northwind", 13 | "EmployeeCollectionName": "Employees", 14 | "CountryCollectionName": "Countries", 15 | "UserCollectionName": "Users" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/EmployeeManager.MongoDB.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netcoreapp3.0 5 | EmployeeManager.MongoDB 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/EmployeeManager.MongoDB.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28902.138 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EmployeeManager.MongoDB", "EmployeeManager.MongoDB.csproj", "{D9CF710C-1C1F-4CB0-8639-C5152A3E61A8}" 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 | {D9CF710C-1C1F-4CB0-8639-C5152A3E61A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {D9CF710C-1C1F-4CB0-8639-C5152A3E61A8}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {D9CF710C-1C1F-4CB0-8639-C5152A3E61A8}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {D9CF710C-1C1F-4CB0-8639-C5152A3E61A8}.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 = {ABDB8F6B-E8F7-4630-A746-736EAC013086} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Models/AppUser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations.Schema; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using MongoDB.Bson.Serialization.Attributes; 7 | using MongoDB.Bson; 8 | using System.ComponentModel.DataAnnotations; 9 | 10 | namespace EmployeeManager.MongoDB.Models 11 | { 12 | public class AppUser 13 | { 14 | [BsonId] 15 | public ObjectId DocumentID { get; set; } 16 | 17 | [BsonElement("userName")] 18 | public string UserName { get; set; } 19 | 20 | 21 | [BsonElement("password")] 22 | public string Password { get; set; } 23 | 24 | [BsonElement("email")] 25 | public string Email { get; set; } 26 | 27 | [BsonElement("fullName")] 28 | public string FullName { get; set; } 29 | 30 | 31 | [BsonElement("birthDate")] 32 | [BsonDateTimeOptions(DateOnly = true)] 33 | public DateTime BirthDate { get; set; } 34 | 35 | [BsonElement("role")] 36 | public string Role { get; set; } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Models/Country.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using MongoDB.Bson.Serialization.Attributes; 6 | using MongoDB.Bson; 7 | 8 | 9 | namespace EmployeeManager.MongoDB.Models 10 | { 11 | public class Country 12 | { 13 | [BsonId] 14 | public ObjectId DocumentID { get; set; } 15 | 16 | [BsonElement("countryID")] 17 | public int CountryID { get; set; } 18 | 19 | [BsonElement("name")] 20 | public string Name { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Models/Register.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.MongoDB.Models 8 | { 9 | public class Register 10 | { 11 | [Required] 12 | [Display(Name = "User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Compare("Password")] 21 | [Display(Name = "Confirm Password")] 22 | public string ConfirmPassword { get; set; } 23 | 24 | [Required] 25 | [Display(Name = "Email")] 26 | [EmailAddress] 27 | public string Email { get; set; } 28 | 29 | 30 | [Required] 31 | [Display(Name = "Full Name")] 32 | public string FullName { get; set; } 33 | 34 | 35 | [Required] 36 | [Display(Name = "Birth Date")] 37 | public DateTime BirthDate { get; set; } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Models/SignIn.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel.DataAnnotations; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | 7 | namespace EmployeeManager.MongoDB.Models 8 | { 9 | public class SignIn 10 | { 11 | [Required] 12 | [Display(Name ="User Name")] 13 | public string UserName { get; set; } 14 | 15 | [Required] 16 | [Display(Name = "Password")] 17 | public string Password { get; set; } 18 | 19 | [Required] 20 | [Display(Name = "Remember Me")] 21 | public bool RememberMe { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Hosting; 10 | using Microsoft.Extensions.Logging; 11 | 12 | namespace EmployeeManager.MongoDB 13 | { 14 | public class Program 15 | { 16 | public static void Main(string[] args) 17 | { 18 | CreateHostBuilder(args).Build().Run(); 19 | } 20 | 21 | public static IHostBuilder CreateHostBuilder(string[] args) => 22 | Host.CreateDefaultBuilder(args) 23 | .ConfigureWebHostDefaults(webBuilder => 24 | { 25 | webBuilder.UseStartup(); 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:49293", 7 | "sslPort": 44394 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "EmployeeManager.NoSql": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Development" 23 | }, 24 | "applicationUrl": "http://localhost:5000" 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/EmployeeManager/List.cshtml: -------------------------------------------------------------------------------- 1 | @model List 2 | 3 | 4 |

List of Employees

5 | 6 |

@TempData["Message"]

7 | 8 | Insert 9 | 10 |
11 |
12 | 13 | @if (Model == null || Model.Count == 0) 14 | { 15 |
No data found.
16 | } 17 | else 18 | { 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | @foreach (var item in Model) 28 | { 29 | 30 | 31 | 32 | 33 | 34 | 39 | 44 | 45 | } 46 |
Employee IDFirst NameLast NameTitleActions
@item.EmployeeID@item.FirstName@item.LastName@item.Title 35 | Update 38 | 40 | Delete 43 |
47 | } -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/Security/AccessDenied.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 |

4 | There was an unexpected error while signing in to the system. 5 |

-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/Security/SignIn.cshtml: -------------------------------------------------------------------------------- 1 | @model SignIn 2 | 3 | 4 |

Sign In

5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 23 | 24 |
:
:
:
21 | 22 |
25 |
26 | 27 |

Create New User Account

28 | 29 |
-------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/Shared/_Layout.cshtml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Employee Manager 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | Employee Manager 15 |

16 |
17 |
18 | @RenderBody() 19 |
20 |
21 |
22 | @if (User.Identity.IsAuthenticated) 23 | { 24 |

You are signed in as @User.Identity.Name

25 |
26 | 27 |
28 | } 29 | 30 | 31 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using EmployeeManager.MongoDB 2 | @using EmployeeManager.MongoDB.Models 3 | 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/Views/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_09/EmployeeManager.MongoDB/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | 9 | "MongoDBSettings": { 10 | "Server": "mongodb://localhost:27017", 11 | "DatabaseName": "Northwind", 12 | "EmployeeCollectionName": "Employees", 13 | "CountryCollectionName": "Countries", 14 | "UserCollectionName": "Users" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing to Apress Source Code 2 | 3 | Copyright for Apress source code belongs to the author(s). However, under fair use you are encouraged to fork and contribute minor corrections and updates for the benefit of the author(s) and other readers. 4 | 5 | ## How to Contribute 6 | 7 | 1. Make sure you have a GitHub account. 8 | 2. Fork the repository for the relevant book. 9 | 3. Create a new branch on which to make your change, e.g. 10 | `git checkout -b my_code_contribution` 11 | 4. Commit your change. Include a commit message describing the correction. Please note that if your commit message is not clear, the correction will not be accepted. 12 | 5. Submit a pull request. 13 | 14 | Thank you for your contribution! -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Freeware License, some rights reserved 2 | 3 | Copyright (c) 2019 Bipin Joshi 4 | 5 | Permission is hereby granted, free of charge, to anyone obtaining a copy 6 | of this software and associated documentation files (the "Software"), 7 | to work with the Software within the limits of freeware distribution and fair use. 8 | This includes the rights to use, copy, and modify the Software for personal use. 9 | Users are also allowed and encouraged to submit corrections and modifications 10 | to the Software for the benefit of other users. 11 | 12 | It is not allowed to reuse, modify, or redistribute the Software for 13 | commercial use in any way, or for a user’s educational materials such as books 14 | or blog articles without prior permission from the copyright holder. 15 | 16 | The above copyright notice and this permission notice need to be included 17 | in all copies or substantial portions of the software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS OR APRESS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apress Source Code 2 | 3 | This repository accompanies [*Beginning Database Programming Using ASP.NET Core 3*](https://www.apress.com/9781484255087) by Bipin Joshi (Apress, 2019). 4 | 5 | [comment]: #cover 6 | ![Cover image](9781484255087.jpg) 7 | 8 | Download the files as a zip using the green button, or clone the repository to your machine using Git. 9 | 10 | ## Releases 11 | 12 | Release v1.0 corresponds to the code in the published book, without corrections or updates. 13 | 14 | ## Contributions 15 | 16 | See the file Contributing.md for more information on how you can contribute to this repository. -------------------------------------------------------------------------------- /Scripts/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 | -------------------------------------------------------------------------------- /Scripts/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 | --------------------------------------------------------------------------------