├── Chapter_09 ├── MyBGList │ ├── dotnet │ ├── Models │ │ ├── ApiUser.cs │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ ├── Mechanic.cs │ │ └── Csv │ │ │ └── BggRecord.cs │ ├── Constants │ │ ├── RoleNames.cs │ │ └── CustomLogEvents.cs │ ├── DTO │ │ ├── LoginDTO.cs │ │ ├── DomainDTO.cs │ │ ├── MechanicDTO.cs │ │ ├── RestDTO.cs │ │ ├── BoardGameDTO.cs │ │ ├── LinkDTO.cs │ │ ├── RegisterDTO.cs │ │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── Attributes │ │ ├── ManualValidationFilterAttribute.cs │ │ ├── SortOrderValidatorAttribute.cs │ │ └── SortColumnValidatorAttribute.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Extensions │ │ └── DistributedCacheExtensions.cs │ └── Swagger │ │ ├── SortOrderFilter.cs │ │ └── SortColumnFilter.cs └── Exercises │ └── RoleNames.cs ├── Chapter_10 ├── MyBGList │ ├── dotnet │ ├── libman.json │ ├── Models │ │ ├── ApiUser.cs │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ ├── Mechanic.cs │ │ └── Csv │ │ │ └── BggRecord.cs │ ├── Constants │ │ ├── RoleNames.cs │ │ └── CustomLogEvents.cs │ ├── DTO │ │ ├── LoginDTO.cs │ │ ├── DomainDTO.cs │ │ ├── MechanicDTO.cs │ │ ├── RestDTO.cs │ │ ├── BoardGameDTO.cs │ │ ├── LinkDTO.cs │ │ ├── RegisterDTO.cs │ │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── gRPC │ │ └── grpc.proto │ ├── appsettings.json │ ├── Attributes │ │ ├── ManualValidationFilterAttribute.cs │ │ ├── SortOrderValidatorAttribute.cs │ │ └── SortColumnValidatorAttribute.cs │ ├── Properties │ │ └── launchSettings.json │ ├── GraphQL │ │ └── Query.cs │ ├── Extensions │ │ └── DistributedCacheExtensions.cs │ ├── Swagger │ │ ├── SortOrderFilter.cs │ │ └── SortColumnFilter.cs │ └── Controllers │ │ └── GrpcController.cs └── Exercises │ ├── 10.5.2-GraphQL.Query-Mutation.json │ ├── 10.5.1-GraphQL.Query.json │ └── grpc.proto ├── Chapter_11 ├── MyBGList │ ├── dotnet │ ├── libman.json │ ├── Models │ │ ├── ApiUser.cs │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ ├── Mechanic.cs │ │ └── Csv │ │ │ └── BggRecord.cs │ ├── Constants │ │ ├── RoleNames.cs │ │ └── CustomLogEvents.cs │ ├── DTO │ │ ├── DomainDTO.cs │ │ ├── MechanicDTO.cs │ │ ├── RestDTO.cs │ │ ├── BoardGameDTO.cs │ │ ├── LinkDTO.cs │ │ ├── LoginDTO.cs │ │ ├── RegisterDTO.cs │ │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── Swagger │ │ ├── CustomDocumentFilter.cs │ │ ├── CustomKeyValueFilter.cs │ │ ├── PasswordRequestFilter.cs │ │ ├── SortOrderFilter.cs │ │ ├── SortColumnFilter.cs │ │ └── AuthRequirementFilter.cs │ ├── Attributes │ │ ├── CustomKeyValueAttribute.cs │ │ ├── ManualValidationFilterAttribute.cs │ │ ├── SortOrderValidatorAttribute.cs │ │ └── SortColumnValidatorAttribute.cs │ ├── gRPC │ │ └── grpc.proto │ ├── appsettings.json │ ├── Properties │ │ └── launchSettings.json │ ├── GraphQL │ │ └── Query.cs │ ├── Extensions │ │ └── DistributedCacheExtensions.cs │ └── Controllers │ │ └── GrpcController.cs └── Exercises │ └── UsernameRequestFilter.cs ├── Chapter_12 └── MyBGList │ ├── dotnet │ ├── libman.json │ ├── Models │ ├── ApiUser.cs │ ├── BoardGames_Domains.cs │ ├── BoardGames_Mechanics.cs │ ├── Domain.cs │ ├── Mechanic.cs │ └── Csv │ │ └── BggRecord.cs │ ├── .config │ └── dotnet-tools.json │ ├── Constants │ ├── RoleNames.cs │ └── CustomLogEvents.cs │ ├── DTO │ ├── DomainDTO.cs │ ├── MechanicDTO.cs │ ├── RestDTO.cs │ ├── BoardGameDTO.cs │ ├── LinkDTO.cs │ ├── LoginDTO.cs │ ├── RegisterDTO.cs │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── Swagger │ ├── CustomDocumentFilter.cs │ ├── CustomKeyValueFilter.cs │ ├── PasswordRequestFilter.cs │ ├── SortOrderFilter.cs │ ├── SortColumnFilter.cs │ └── AuthRequirementFilter.cs │ ├── Attributes │ ├── CustomKeyValueAttribute.cs │ ├── ManualValidationFilterAttribute.cs │ ├── SortOrderValidatorAttribute.cs │ └── SortColumnValidatorAttribute.cs │ ├── gRPC │ └── grpc.proto │ ├── appsettings.json │ ├── Properties │ └── launchSettings.json │ ├── GraphQL │ └── Query.cs │ └── Extensions │ └── DistributedCacheExtensions.cs ├── Chapter_07 └── MyBGList │ ├── Logs │ └── _placeholder.txt │ ├── DTO │ ├── DomainDTO.cs │ ├── MechanicDTO.cs │ ├── RestDTO.cs │ ├── BoardGameDTO.cs │ ├── LinkDTO.cs │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── Models │ ├── BoardGames_Domains.cs │ ├── BoardGames_Mechanics.cs │ ├── Domain.cs │ ├── Mechanic.cs │ └── Csv │ │ └── BggRecord.cs │ ├── appsettings.json │ ├── Attributes │ ├── ManualValidationFilterAttribute.cs │ ├── SortOrderValidatorAttribute.cs │ └── SortColumnValidatorAttribute.cs │ ├── Constants │ └── CustomLogEvents.cs │ ├── Properties │ └── launchSettings.json │ └── Swagger │ ├── SortOrderFilter.cs │ └── SortColumnFilter.cs ├── Chapter_02 ├── MyBGList │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── BoardGame.cs │ ├── Controllers │ │ ├── ErrorController.cs │ │ └── BoardGamesController.cs │ ├── MyBGList.csproj │ ├── Properties │ │ └── launchSettings.json │ └── Program.cs └── Exercises │ ├── appsettings.Development.json │ ├── appsettings.Staging.json │ ├── appsettings.json │ ├── BoardGame.cs │ ├── launchSettings.json │ ├── Program.cs │ └── BoardGamesController.cs ├── Chapter_03 ├── MyBGList │ ├── appsettings.Development.json │ ├── DTO │ │ ├── RestDTO.cs │ │ └── LinkDTO.cs │ ├── BoardGame.cs │ ├── appsettings.json │ ├── MyBGList.csproj │ ├── Properties │ │ └── launchSettings.json │ └── Controllers │ │ └── BoardGamesController.cs ├── MyBGList_ApiVersion │ ├── appsettings.Development.json │ ├── BoardGame.cs │ ├── DTO │ │ ├── v1 │ │ │ ├── RestDTO.cs │ │ │ └── LinkDTO.cs │ │ └── v2 │ │ │ └── RestDTO.cs │ ├── appsettings.json │ ├── MyBGList_ApiVersion.csproj │ └── Properties │ │ └── launchSettings.json └── Exercises │ └── Controllers │ └── v3 │ └── CodeOnDemandController.cs ├── Chapter_04 ├── MyBGList │ ├── appsettings.Development.json │ ├── DTO │ │ ├── RestDTO.cs │ │ └── LinkDTO.cs │ ├── appsettings.json │ ├── Models │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ └── Mechanic.cs │ ├── Properties │ │ └── launchSettings.json │ ├── MyBGList.csproj │ └── Controllers │ │ └── BoardGamesController.cs └── Exercises │ └── Model │ ├── BoardGames_Domains.cs │ ├── BoardGames_Categories.cs │ ├── BoardGames_Mechanics.cs │ ├── Publisher.cs │ ├── Category.cs │ ├── Domain.cs │ └── Mechanic.cs ├── Chapter_05 ├── MyBGList │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── DTO │ │ ├── RestDTO.cs │ │ ├── BoardGameDTO.cs │ │ └── LinkDTO.cs │ ├── Models │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ ├── Mechanic.cs │ │ └── Csv │ │ │ └── BggRecord.cs │ ├── Properties │ │ └── launchSettings.json │ └── MyBGList.csproj └── Exercises │ └── DTO │ └── BoardGameDTO.cs ├── Chapter_06 ├── MyBGList │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── DTO │ │ ├── DomainDTO.cs │ │ ├── MechanicDTO.cs │ │ ├── RestDTO.cs │ │ ├── BoardGameDTO.cs │ │ ├── LinkDTO.cs │ │ └── RequestDTO.cs │ ├── Models │ │ ├── BoardGames_Domains.cs │ │ ├── BoardGames_Mechanics.cs │ │ ├── Domain.cs │ │ ├── Mechanic.cs │ │ └── Csv │ │ │ └── BggRecord.cs │ ├── Attributes │ │ ├── ManualValidationFilterAttribute.cs │ │ ├── SortOrderValidatorAttribute.cs │ │ └── SortColumnValidatorAttribute.cs │ ├── Properties │ │ └── launchSettings.json │ ├── MyBGList.csproj │ └── Swagger │ │ ├── SortOrderFilter.cs │ │ └── SortColumnFilter.cs └── Exercises │ ├── DTO │ ├── MechanicDTO.cs │ └── DomainDTO.cs │ └── Attributes │ └── LettersOnlyValidatorAttribute.cs ├── Chapter_08 └── MyBGList │ ├── DTO │ ├── DomainDTO.cs │ ├── MechanicDTO.cs │ ├── RestDTO.cs │ ├── BoardGameDTO.cs │ ├── LinkDTO.cs │ └── RequestDTO.cs │ ├── appsettings.Development.json │ ├── Models │ ├── BoardGames_Domains.cs │ ├── BoardGames_Mechanics.cs │ ├── Domain.cs │ ├── Mechanic.cs │ └── Csv │ │ └── BggRecord.cs │ ├── appsettings.json │ ├── Attributes │ ├── ManualValidationFilterAttribute.cs │ ├── SortOrderValidatorAttribute.cs │ └── SortColumnValidatorAttribute.cs │ ├── Constants │ └── CustomLogEvents.cs │ ├── Properties │ └── launchSettings.json │ ├── Extensions │ └── DistributedCacheExtensions.cs │ └── Swagger │ ├── SortOrderFilter.cs │ └── SortColumnFilter.cs ├── LICENSE ├── Chapter_12.sln ├── Chapter_07.sln ├── Chapter_09.sln └── Chapter_08.sln /Chapter_09/MyBGList/dotnet: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/dotnet: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/dotnet: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/dotnet: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Logs/_placeholder.txt: -------------------------------------------------------------------------------- 1 | Placeholder file -------------------------------------------------------------------------------- /Chapter_10/MyBGList/libman.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "defaultProvider": "cdnjs", 4 | "libraries": [] 5 | } -------------------------------------------------------------------------------- /Chapter_11/MyBGList/libman.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "defaultProvider": "cdnjs", 4 | "libraries": [] 5 | } -------------------------------------------------------------------------------- /Chapter_12/MyBGList/libman.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.0", 3 | "defaultProvider": "cdnjs", 4 | "libraries": [] 5 | } -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/ApiUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class ApiUser : IdentityUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/ApiUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class ApiUser : IdentityUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/ApiUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class ApiUser : IdentityUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/ApiUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class ApiUser : IdentityUser 6 | { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "6.0.9", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "UseDeveloperExceptionPage": false 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public List Links { get; set; } = new List(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public List Links { get; set; } = new List(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/BoardGame.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList 2 | { 3 | public class BoardGame 4 | { 5 | public int Id { get; set; } 6 | 7 | public string? Name { get; set; } 8 | 9 | public int? Year { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/BoardGame.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList 2 | { 3 | public class BoardGame 4 | { 5 | public int Id { get; set; } 6 | 7 | public string? Name { get; set; } 8 | 9 | public int? Year { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_02/Exercises/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true, 9 | "UseSwagger": true 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_02/Exercises/appsettings.Staging.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "UseDeveloperExceptionPage": true, 9 | "UseSwagger": true 10 | } 11 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/BoardGame.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList 2 | { 3 | public class BoardGame 4 | { 5 | public int Id { get; set; } 6 | 7 | public string? Name { get; set; } 8 | 9 | public int? Year { get; set; } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/DTO/v1/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO.v1 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public List Links { get; set; } = new List(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_02/Exercises/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "UseDeveloperExceptionPage": false, 10 | "UseSwagger": false 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "AllowedOrigins": "*", 10 | "UseDeveloperExceptionPage": false, 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "AllowedOrigins": "*", 10 | "UseDeveloperExceptionPage": false, 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "AllowedOrigins": "*", 10 | "UseDeveloperExceptionPage": false, 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "AllowedOrigins": "*", 10 | "UseDeveloperExceptionPage": false 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*", 9 | "AllowedOrigins": "*", 10 | "UseDeveloperExceptionPage": false, 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/DTO/v2/RestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.DTO.v1; 2 | 3 | namespace MyBGList.DTO.v2 4 | { 5 | public class RestDTO 6 | { 7 | public T Items { get; set; } = default!; 8 | 9 | public List Links { get; set; } = new List(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Constants/RoleNames.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public static class RoleNames 4 | { 5 | public const string PowerUser = "PowerUser"; 6 | public const string Moderator = "Moderator"; 7 | public const string Administrator = "Administrator"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Constants/RoleNames.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public static class RoleNames 4 | { 5 | public const string PowerUser = "PowerUser"; 6 | public const string Moderator = "Moderator"; 7 | public const string Administrator = "Administrator"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Constants/RoleNames.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public static class RoleNames 4 | { 5 | public const string PowerUser = "PowerUser"; 6 | public const string Moderator = "Moderator"; 7 | public const string Administrator = "Administrator"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Constants/RoleNames.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public static class RoleNames 4 | { 5 | public const string PowerUser = "PowerUser"; 6 | public const string Moderator = "Moderator"; 7 | public const string Administrator = "Administrator"; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_09/Exercises/RoleNames.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public static class RoleNames 4 | { 5 | public const string Moderator = "Moderator"; 6 | public const string Administrator = "Administrator"; 7 | public const string SuperAdmin = "SuperAdmin"; // Exercise 9.5.1 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/LoginDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class LoginDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | public string? Password { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/LoginDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class LoginDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | public string? Password { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_02/Exercises/BoardGame.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList 2 | { 3 | public class BoardGame 4 | { 5 | public int Id { get; set; } 6 | 7 | public string? Name { get; set; } 8 | 9 | public int? Year { get; set; } 10 | 11 | public int? MinPlayers { get; set; } 12 | 13 | public int? MaxPlayers { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class MechanicDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter_10/Exercises/10.5.2-GraphQL.Query-Mutation.json: -------------------------------------------------------------------------------- 1 | query { 2 | boardGames( 3 | where: { name: { eq: "Axis & Allies" }, year: { eq: 2004 } } 4 | ) { 5 | nodes { 6 | id 7 | } 8 | } 9 | } 10 | 11 | 12 | mutation { 13 | updateBoardGame(model: { 14 | id:10093 15 | name:"Axis & Allies: Revised" 16 | }) { 17 | id, 18 | name 19 | } 20 | } -------------------------------------------------------------------------------- /Chapter_05/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/RestDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class RestDTO 4 | { 5 | public T Data { get; set; } = default!; 6 | 7 | public int? PageIndex { get; set; } 8 | 9 | public int? PageSize { get; set; } 10 | 11 | public int? RecordCount { get; set; } 12 | 13 | public List Links { get; set; } = new List(); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class BoardGameDTO 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | public string? Name { get; set; } 13 | 14 | public int? Year { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_06/Exercises/DTO/MechanicDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | using MyBGList.Attributes; 5 | 6 | namespace MyBGList.DTO 7 | { 8 | public class MechanicDTO 9 | { 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [LettersOnly(UseRegex = true)] 14 | public string? Name { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning", 6 | "MyBGList": "Debug" 7 | } 8 | }, 9 | "Serilog": { 10 | "MinimumLevel": { 11 | "Default": "Information", 12 | "Override": { 13 | "Microsoft.AspNetCore": "Warning", 14 | "MyBGList": "Debug" 15 | } 16 | } 17 | }, 18 | "UseDeveloperExceptionPage": true 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/DTO/v1/LinkDTO.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.DTO.v1 2 | { 3 | public class LinkDTO 4 | { 5 | public LinkDTO(string href, string rel, string type) 6 | { 7 | Href = href; 8 | Rel = rel; 9 | Type = type; 10 | } 11 | 12 | public string Href { get; private set; } 13 | 14 | public string Rel { get; private set; } 15 | 16 | public string Type { get; private set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/LoginDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace MyBGList.DTO 5 | { 6 | public class LoginDTO 7 | { 8 | [Required] 9 | [MaxLength(255)] 10 | [CustomKeyValue("x-test-1", "value 1")] 11 | [CustomKeyValue("x-test-2", "value 2")] 12 | public string? UserName { get; set; } 13 | 14 | [Required] 15 | public string? Password { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/LoginDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace MyBGList.DTO 5 | { 6 | public class LoginDTO 7 | { 8 | [Required] 9 | [MaxLength(255)] 10 | [CustomKeyValue("x-test-1", "value 1")] 11 | [CustomKeyValue("x-test-2", "value 2")] 12 | public string? UserName { get; set; } 13 | 14 | [Required] 15 | public string? Password { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/RegisterDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class RegisterDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | [EmailAddress] 13 | [MaxLength(255)] 14 | public string? Email { get; set; } 15 | 16 | [Required] 17 | public string? Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/RegisterDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class RegisterDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | [EmailAddress] 13 | [MaxLength(255)] 14 | public string? Email { get; set; } 15 | 16 | [Required] 17 | public string? Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/RegisterDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class RegisterDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | [EmailAddress] 13 | [MaxLength(255)] 14 | public string? Email { get; set; } 15 | 16 | [Required] 17 | public string? Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/RegisterDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.DTO 4 | { 5 | public class RegisterDTO 6 | { 7 | [Required] 8 | [MaxLength(255)] 9 | public string? UserName { get; set; } 10 | 11 | [Required] 12 | [EmailAddress] 13 | [MaxLength(255)] 14 | public string? Email { get; set; } 15 | 16 | [Required] 17 | public string? Password { get; set; } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/CustomDocumentFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | 5 | namespace MyBGList.Swagger 6 | { 7 | internal class CustomDocumentFilter : IDocumentFilter 8 | { 9 | public void Apply( 10 | OpenApiDocument swaggerDoc, 11 | DocumentFilterContext context) 12 | { 13 | swaggerDoc.Info.Title = "MyBGList Web API"; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/CustomDocumentFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | 5 | namespace MyBGList.Swagger 6 | { 7 | internal class CustomDocumentFilter : IDocumentFilter 8 | { 9 | public void Apply( 10 | OpenApiDocument swaggerDoc, 11 | DocumentFilterContext context) 12 | { 13 | swaggerDoc.Info.Title = "MyBGList Web API"; 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter_10/Exercises/10.5.1-GraphQL.Query.json: -------------------------------------------------------------------------------- 1 | query { 2 | boardGames( 3 | where: { name: { startsWith: "war" } }, 4 | order: { name: ASC }, 5 | first:10 ) { 6 | nodes { 7 | id 8 | name 9 | year 10 | minPlayers 11 | maxPlayers 12 | playTime 13 | boardGames_Domains { 14 | domain { 15 | id 16 | name 17 | } 18 | } 19 | boardGames_Mechanics { 20 | mechanic { 21 | id 22 | name 23 | } 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Attributes/CustomKeyValueAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Attributes 2 | { 3 | [AttributeUsage( 4 | AttributeTargets.Property | AttributeTargets.Parameter, 5 | AllowMultiple = true)] 6 | public class CustomKeyValueAttribute : Attribute 7 | { 8 | public CustomKeyValueAttribute(string? key, string? value) 9 | { 10 | Key = key; 11 | Value = value; 12 | } 13 | 14 | public string? Key { get; set; } 15 | 16 | public string? Value { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Attributes/CustomKeyValueAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Attributes 2 | { 3 | [AttributeUsage( 4 | AttributeTargets.Property | AttributeTargets.Parameter, 5 | AllowMultiple = true)] 6 | public class CustomKeyValueAttribute : Attribute 7 | { 8 | public CustomKeyValueAttribute(string? key, string? value) 9 | { 10 | Key = key; 11 | Value = value; 12 | } 13 | 14 | public string? Key { get; set; } 15 | 16 | public string? Value { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/gRPC/grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "MyBGList.gRPC"; 4 | 5 | package Grpc; 6 | 7 | service Grpc { 8 | rpc GetBoardGame (BoardGameRequest) returns (BoardGameResponse); 9 | rpc UpdateBoardGame (UpdateBoardGameRequest) returns (BoardGameResponse); 10 | } 11 | 12 | message BoardGameRequest { 13 | int32 id = 1; 14 | } 15 | 16 | message UpdateBoardGameRequest { 17 | int32 id = 1; 18 | string name = 2; 19 | } 20 | 21 | message BoardGameResponse { 22 | int32 id = 1; 23 | string name = 2; 24 | int32 year = 3; 25 | } -------------------------------------------------------------------------------- /Chapter_11/MyBGList/gRPC/grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "MyBGList.gRPC"; 4 | 5 | package Grpc; 6 | 7 | service Grpc { 8 | rpc GetBoardGame (BoardGameRequest) returns (BoardGameResponse); 9 | rpc UpdateBoardGame (UpdateBoardGameRequest) returns (BoardGameResponse); 10 | } 11 | 12 | message BoardGameRequest { 13 | int32 id = 1; 14 | } 15 | 16 | message UpdateBoardGameRequest { 17 | int32 id = 1; 18 | string name = 2; 19 | } 20 | 21 | message BoardGameResponse { 22 | int32 id = 1; 23 | string name = 2; 24 | int32 year = 3; 25 | } -------------------------------------------------------------------------------- /Chapter_12/MyBGList/gRPC/grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "MyBGList.gRPC"; 4 | 5 | package Grpc; 6 | 7 | service Grpc { 8 | rpc GetBoardGame (BoardGameRequest) returns (BoardGameResponse); 9 | rpc UpdateBoardGame (UpdateBoardGameRequest) returns (BoardGameResponse); 10 | } 11 | 12 | message BoardGameRequest { 13 | int32 id = 1; 14 | } 15 | 16 | message UpdateBoardGameRequest { 17 | int32 id = 1; 18 | string name = 2; 19 | } 20 | 21 | message BoardGameResponse { 22 | int32 id = 1; 23 | string name = 2; 24 | int32 year = 3; 25 | } -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Domains 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int DomainId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Domain? Domain { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_05/Exercises/DTO/BoardGameDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace MyBGList.DTO 5 | { 6 | public class BoardGameDTO 7 | { 8 | [Required] 9 | public int Id { get; set; } 10 | 11 | public string? Name { get; set; } 12 | 13 | public int? Year { get; set; } 14 | 15 | public int? MinPlayers { get; set; } 16 | 17 | public int? MaxPlayers { get; set; } 18 | 19 | public int? PlayTime { get; set; } 20 | 21 | public int? MinAge { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/BoardGames_Categories.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Categories 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int CategoryId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Category? Category { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Models 4 | { 5 | public class BoardGames_Mechanics 6 | { 7 | [Key] 8 | [Required] 9 | public int BoardGameId { get; set; } 10 | 11 | [Key] 12 | [Required] 13 | public int MechanicId { get; set; } 14 | 15 | [Required] 16 | public DateTime CreatedDate { get; set; } 17 | 18 | public BoardGame? BoardGame { get; set; } 19 | 20 | public Mechanic? Mechanic { get; set; } 21 | 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/Controllers/ErrorController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Diagnostics; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace MyBGList.Controllers 5 | { 6 | [ApiController] 7 | public class ErrorController : ControllerBase 8 | { 9 | [Route("/error")] 10 | [HttpGet] 11 | public IActionResult Error() 12 | { 13 | return Problem(); 14 | } 15 | 16 | [Route("/error/test")] 17 | [HttpGet] 18 | public IActionResult Test() 19 | { 20 | throw new Exception("test"); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/MyBGList.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/MyBGList.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "AllowedHosts": "*", 24 | "AllowedOrigins": "*", 25 | "UseDeveloperExceptionPage": false 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "AllowedHosts": "*", 24 | "AllowedOrigins": "*", 25 | "UseDeveloperExceptionPage": false 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Models/BoardGames_Domains.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | public class BoardGames_Domains 7 | { 8 | [Key] 9 | [Required] 10 | public int BoardGameId { get; set; } 11 | 12 | [Key] 13 | [Required] 14 | public int DomainId { get; set; } 15 | 16 | [Required] 17 | public DateTime CreatedDate { get; set; } 18 | 19 | public BoardGame? BoardGame { get; set; } 20 | 21 | public Domain? Domain { get; set; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Models/BoardGames_Mechanics.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | public class BoardGames_Mechanics 7 | { 8 | [Key] 9 | [Required] 10 | public int BoardGameId { get; set; } 11 | 12 | [Key] 13 | [Required] 14 | public int MechanicId { get; set; } 15 | 16 | [Required] 17 | public DateTime CreatedDate { get; set; } 18 | 19 | public BoardGame? BoardGame { get; set; } 20 | 21 | public Mechanic? Mechanic { get; set; } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/Publisher.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Publishers")] 7 | public class Publisher 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Domains { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/Category.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Categories")] 7 | public class Category 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Categories { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [Required] 18 | public DateTime CreatedDate { get; set; } 19 | 20 | [Required] 21 | public DateTime LastModifiedDate { get; set; } 22 | 23 | public ICollection? BoardGames_Mechanics { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "JWT": { 24 | "Issuer": "MyBGList", 25 | "Audience": "MyBGList", 26 | "SigningKey": "MyVeryOwnTestSigningKey123$" 27 | }, 28 | "AllowedHosts": "*", 29 | "AllowedOrigins": "*", 30 | "UseDeveloperExceptionPage": false 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "JWT": { 24 | "Issuer": "MyBGList", 25 | "Audience": "MyBGList", 26 | "SigningKey": "MyVeryOwnTestSigningKey123$" 27 | }, 28 | "AllowedHosts": "*", 29 | "AllowedOrigins": "*", 30 | "UseDeveloperExceptionPage": false 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "JWT": { 24 | "Issuer": "MyBGList", 25 | "Audience": "MyBGList", 26 | "SigningKey": "MyVeryOwnTestSigningKey123$" 27 | }, 28 | "AllowedHosts": "*", 29 | "AllowedOrigins": "*", 30 | "UseDeveloperExceptionPage": false 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning", 5 | "MyBGList": "Information" 6 | }, 7 | "Console": { 8 | "FormatterOptions": { 9 | "SingleLine": true, 10 | "TimestampFormat": "HH:mm:ss ", 11 | "UseUtcTimestamp": true 12 | } 13 | } 14 | }, 15 | "Serilog": { 16 | "MinimumLevel": { 17 | "Default": "Warning", 18 | "Override": { 19 | "MyBGList": "Information" 20 | } 21 | } 22 | }, 23 | "JWT": { 24 | "Issuer": "MyBGList", 25 | "Audience": "MyBGList", 26 | "SigningKey": "MyVeryOwnTestSigningKey123$" 27 | }, 28 | "AllowedHosts": "*", 29 | "AllowedOrigins": "*", 30 | "UseDeveloperExceptionPage": false 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/MyBGList_ApiVersion.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Attributes/ManualValidationFilterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.ApplicationModels; 2 | using Microsoft.AspNetCore.Mvc.Infrastructure; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class ManualValidationFilterAttribute 7 | : Attribute, IActionModelConvention 8 | { 9 | public void Apply(ActionModel action) 10 | { 11 | for (var i = 0; i < action.Filters.Count; i++) 12 | { 13 | if (action.Filters[i] is ModelStateInvalidFilter 14 | || action.Filters[i].GetType().Name == 15 | "ModelStateInvalidFilterFactory") 16 | { 17 | action.Filters.RemoveAt(i); 18 | break; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/Domain.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Domains")] 7 | public class Domain 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [MaxLength(200)] 18 | public string Notes { get; set; } = null!; 19 | 20 | [Required] 21 | public int Flags { get; set; } 22 | 23 | [Required] 24 | public DateTime CreatedDate { get; set; } 25 | 26 | [Required] 27 | public DateTime LastModifiedDate { get; set; } 28 | 29 | public ICollection? BoardGames_Domains { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_04/Exercises/Model/Mechanic.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.ComponentModel.DataAnnotations.Schema; 3 | 4 | namespace MyBGList.Models 5 | { 6 | [Table("Mechanics")] 7 | public class Mechanic 8 | { 9 | [Key] 10 | [Required] 11 | public int Id { get; set; } 12 | 13 | [Required] 14 | [MaxLength(200)] 15 | public string Name { get; set; } = null!; 16 | 17 | [MaxLength(200)] 18 | public string Notes { get; set; } = null!; 19 | 20 | [Required] 21 | public int Flags { get; set; } 22 | 23 | [Required] 24 | public DateTime CreatedDate { get; set; } 25 | 26 | [Required] 27 | public DateTime LastModifiedDate { get; set; } 28 | 29 | public ICollection? BoardGames_Mechanics { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/CustomKeyValueFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | using System.Reflection; 5 | 6 | namespace MyBGList.Attributes 7 | { 8 | public class CustomKeyValueFilter : ISchemaFilter 9 | { 10 | public void Apply( 11 | OpenApiSchema schema, 12 | SchemaFilterContext context) 13 | { 14 | var caProvider = context.MemberInfo 15 | ?? context.ParameterInfo 16 | as ICustomAttributeProvider; 17 | 18 | var attributes = caProvider? 19 | .GetCustomAttributes(true) 20 | .OfType(); 21 | 22 | if (attributes != null) 23 | { 24 | foreach (var attribute in attributes) 25 | { 26 | schema.Extensions.Add( 27 | attribute.Key, 28 | new OpenApiString(attribute.Value) 29 | ); 30 | } 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/CustomKeyValueFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | using System.Reflection; 5 | 6 | namespace MyBGList.Attributes 7 | { 8 | public class CustomKeyValueFilter : ISchemaFilter 9 | { 10 | public void Apply( 11 | OpenApiSchema schema, 12 | SchemaFilterContext context) 13 | { 14 | var caProvider = context.MemberInfo 15 | ?? context.ParameterInfo 16 | as ICustomAttributeProvider; 17 | 18 | var attributes = caProvider? 19 | .GetCustomAttributes(true) 20 | .OfType(); 21 | 22 | if (attributes != null) 23 | { 24 | foreach (var attribute in attributes) 25 | { 26 | schema.Extensions.Add( 27 | attribute.Key, 28 | new OpenApiString(attribute.Value) 29 | ); 30 | } 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_06/Exercises/DTO/DomainDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Text.Json.Serialization; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class DomainDTO : IValidatableObject 8 | { 9 | [Required] 10 | public int Id { get; set; } 11 | 12 | [RegularExpression("^[A-Za-z]+$", 13 | ErrorMessage = 14 | "Value must contain only letters(no spaces, digits, or other chars)")] 15 | public string? Name { get; set; } 16 | 17 | public IEnumerable Validate( 18 | ValidationContext validationContext) 19 | { 20 | return (Id != 3 && Name != "Wargames") 21 | ? new[] { new ValidationResult( 22 | "Id and/or Name values must match an allowed Domain.") } 23 | : new ValidationResult[0]; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Constants/CustomLogEvents.cs: -------------------------------------------------------------------------------- 1 | namespace MyBGList.Constants 2 | { 3 | public class CustomLogEvents 4 | { 5 | public const int Error_Get = 50001; 6 | 7 | public const int BoardGamesController_Get = 50110; 8 | public const int BoardGamesController_Post = 50120; 9 | public const int BoardGamesController_Put = 50130; 10 | public const int BoardGamesController_Delete = 50140; 11 | 12 | public const int DomainsController_Get = 50210; 13 | public const int DomainsController_Post = 50220; 14 | public const int DomainsController_Put = 50230; 15 | public const int DomainsController_Delete = 50240; 16 | 17 | public const int MechanicsController_Get = 50310; 18 | public const int MechanicsController_Post = 50320; 19 | public const int MechanicsController_Put = 50330; 20 | public const int MechanicsController_Delete = 50340; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Chapter_02/Exercises/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "boardgames", 17 | "applicationUrl": "https://localhost:55222;http://localhost:55221", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Staging" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:65339/", 8 | "sslPort": 44364 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | }, 19 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 20 | "dotnetRunMessages": true 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_02/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList_ApiVersion/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:40080", 8 | "sslPort": 40443 9 | } 10 | }, 11 | "profiles": { 12 | "MyBGList": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "swagger", 17 | "applicationUrl": "https://localhost:40443;http://localhost:40080", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/GraphQL/Query.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Models; 2 | 3 | namespace MyBGList.GraphQL 4 | { 5 | public class Query 6 | { 7 | [Serial] 8 | [UsePaging] 9 | [UseProjection] 10 | [UseFiltering] 11 | [UseSorting] 12 | public IQueryable GetBoardGames( 13 | [Service] ApplicationDbContext context) 14 | => context.BoardGames; 15 | 16 | [Serial] 17 | [UsePaging] 18 | [UseProjection] 19 | [UseFiltering] 20 | [UseSorting] 21 | public IQueryable GetDomains( 22 | [Service] ApplicationDbContext context) 23 | => context.Domains; 24 | 25 | [Serial] 26 | [UsePaging] 27 | [UseProjection] 28 | [UseFiltering] 29 | [UseSorting] 30 | public IQueryable GetMechanics( 31 | [Service] ApplicationDbContext context) 32 | => context.Mechanics; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/GraphQL/Query.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Models; 2 | 3 | namespace MyBGList.GraphQL 4 | { 5 | public class Query 6 | { 7 | [Serial] 8 | [UsePaging] 9 | [UseProjection] 10 | [UseFiltering] 11 | [UseSorting] 12 | public IQueryable GetBoardGames( 13 | [Service] ApplicationDbContext context) 14 | => context.BoardGames; 15 | 16 | [Serial] 17 | [UsePaging] 18 | [UseProjection] 19 | [UseFiltering] 20 | [UseSorting] 21 | public IQueryable GetDomains( 22 | [Service] ApplicationDbContext context) 23 | => context.Domains; 24 | 25 | [Serial] 26 | [UsePaging] 27 | [UseProjection] 28 | [UseFiltering] 29 | [UseSorting] 30 | public IQueryable GetMechanics( 31 | [Service] ApplicationDbContext context) 32 | => context.Mechanics; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/GraphQL/Query.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Models; 2 | 3 | namespace MyBGList.GraphQL 4 | { 5 | public class Query 6 | { 7 | [Serial] 8 | [UsePaging] 9 | [UseProjection] 10 | [UseFiltering] 11 | [UseSorting] 12 | public IQueryable GetBoardGames( 13 | [Service] ApplicationDbContext context) 14 | => context.BoardGames; 15 | 16 | [Serial] 17 | [UsePaging] 18 | [UseProjection] 19 | [UseFiltering] 20 | [UseSorting] 21 | public IQueryable GetDomains( 22 | [Service] ApplicationDbContext context) 23 | => context.Domains; 24 | 25 | [Serial] 26 | [UsePaging] 27 | [UseProjection] 28 | [UseFiltering] 29 | [UseSorting] 30 | public IQueryable GetMechanics( 31 | [Service] ApplicationDbContext context) 32 | => context.Mechanics; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | builder.Services.AddControllers(); 6 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 7 | builder.Services.AddEndpointsApiExplorer(); 8 | builder.Services.AddSwaggerGen(); 9 | 10 | var app = builder.Build(); 11 | 12 | // Configure the HTTP request pipeline. 13 | if (app.Environment.IsDevelopment()) 14 | { 15 | app.UseSwagger(); 16 | app.UseSwaggerUI(); 17 | } 18 | 19 | if (app.Configuration.GetValue("UseDeveloperExceptionPage")) 20 | app.UseDeveloperExceptionPage(); 21 | else 22 | app.UseExceptionHandler("/error"); 23 | 24 | app.UseHttpsRedirection(); 25 | 26 | app.UseAuthorization(); 27 | 28 | // Minimal API 29 | app.MapGet("/error", () => Results.Problem()); 30 | app.MapGet("/error/test", () => { throw new Exception("test"); }); 31 | 32 | // Controllers 33 | app.MapControllers(); 34 | 35 | app.Run(); 36 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Attributes/SortOrderValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortOrderValidatorAttribute : ValidationAttribute 6 | { 7 | public string[] AllowedValues { get; } = 8 | new[] { "ASC", "DESC" }; 9 | 10 | public SortOrderValidatorAttribute() 11 | : base("Value must be one of the following: {0}.") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && AllowedValues.Contains(strValue)) 20 | return ValidationResult.Success; 21 | 22 | return new ValidationResult( 23 | FormatErrorMessage(string.Join(",", AllowedValues)) 24 | ); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Chapter_02/Exercises/Program.cs: -------------------------------------------------------------------------------- 1 | var builder = WebApplication.CreateBuilder(args); 2 | 3 | // Add services to the container. 4 | 5 | builder.Services.AddControllers(); 6 | // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle 7 | builder.Services.AddEndpointsApiExplorer(); 8 | builder.Services.AddSwaggerGen(); 9 | 10 | var app = builder.Build(); 11 | 12 | // Configure the HTTP request pipeline. 13 | if (app.Configuration.GetValue("UseSwagger")) 14 | { 15 | app.UseSwagger(); 16 | app.UseSwaggerUI(); 17 | } 18 | 19 | if (app.Configuration.GetValue("UseDeveloperExceptionPage")) 20 | app.UseDeveloperExceptionPage(); 21 | else 22 | app.UseExceptionHandler("/error"); 23 | 24 | app.UseHttpsRedirection(); 25 | 26 | app.UseAuthorization(); 27 | 28 | // Minimal API 29 | app.MapGet("/error", () => Results.Problem()); 30 | app.MapGet("/error/test", () => { throw new Exception("test"); }); 31 | 32 | // Controllers 33 | app.MapControllers(); 34 | 35 | app.Run(); 36 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/MyBGList.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | MyBGList 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/PasswordRequestFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Models; 2 | using Swashbuckle.AspNetCore.SwaggerGen; 3 | 4 | namespace MyBGList.Swagger 5 | { 6 | internal class PasswordRequestFilter : IRequestBodyFilter 7 | { 8 | public void Apply( 9 | OpenApiRequestBody requestBody, 10 | RequestBodyFilterContext context) 11 | { 12 | var fieldName = "password"; 13 | 14 | if (context.BodyParameterDescription.Name 15 | .Equals(fieldName, 16 | StringComparison.OrdinalIgnoreCase) 17 | || context.BodyParameterDescription.Type 18 | .GetProperties().Any(p => p.Name 19 | .Equals(fieldName, 20 | StringComparison.OrdinalIgnoreCase))) 21 | { 22 | requestBody.Description = 23 | "IMPORTANT: be sure to always use a strong password " + 24 | "and store it in a secure location!"; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/PasswordRequestFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Models; 2 | using Swashbuckle.AspNetCore.SwaggerGen; 3 | 4 | namespace MyBGList.Swagger 5 | { 6 | internal class PasswordRequestFilter : IRequestBodyFilter 7 | { 8 | public void Apply( 9 | OpenApiRequestBody requestBody, 10 | RequestBodyFilterContext context) 11 | { 12 | var fieldName = "password"; 13 | 14 | if (context.BodyParameterDescription.Name 15 | .Equals(fieldName, 16 | StringComparison.OrdinalIgnoreCase) 17 | || context.BodyParameterDescription.Type 18 | .GetProperties().Any(p => p.Name 19 | .Equals(fieldName, 20 | StringComparison.OrdinalIgnoreCase))) 21 | { 22 | requestBody.Description = 23 | "IMPORTANT: be sure to always use a strong password " + 24 | "and store it in a secure location!"; 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Attributes/SortColumnValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace MyBGList.Attributes 4 | { 5 | public class SortColumnValidatorAttribute : ValidationAttribute 6 | { 7 | public Type EntityType { get; set; } 8 | 9 | public SortColumnValidatorAttribute(Type entityType) 10 | : base("Value must match an existing column.") 11 | { 12 | EntityType = entityType; 13 | } 14 | 15 | protected override ValidationResult? IsValid( 16 | object? value, 17 | ValidationContext validationContext) 18 | { 19 | if (EntityType != null) 20 | { 21 | var strValue = value as string; 22 | if (!string.IsNullOrEmpty(strValue) 23 | && EntityType.GetProperties() 24 | .Any(p => p.Name == strValue)) 25 | return ValidationResult.Success; 26 | } 27 | 28 | return new ValidationResult(ErrorMessage); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Chapter_11/Exercises/UsernameRequestFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Models; 2 | using Swashbuckle.AspNetCore.SwaggerGen; 3 | 4 | namespace MyBGList.Swagger 5 | { 6 | // Exercise 11.4.4 7 | internal class UsernameRequestFilter : IRequestBodyFilter 8 | { 9 | public void Apply( 10 | OpenApiRequestBody requestBody, 11 | RequestBodyFilterContext context) 12 | { 13 | var fieldName = "username"; 14 | 15 | if (context.BodyParameterDescription.Name 16 | .Equals(fieldName, 17 | StringComparison.OrdinalIgnoreCase) 18 | || context.BodyParameterDescription.Type 19 | .GetProperties().Any(p => p.Name 20 | .Equals(fieldName, 21 | StringComparison.OrdinalIgnoreCase))) 22 | { 23 | requestBody.Description = 24 | "IMPORTANT: Be sure to remember your username, " + 25 | "as you will need it to perform the login!"; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/MyBGList.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | MyBGList 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/MyBGList.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | enable 6 | enable 7 | MyBGList 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | all 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Chapter_06/Exercises/Attributes/LettersOnlyValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace MyBGList.Attributes 5 | { 6 | public class LettersOnlyValidatorAttribute : ValidationAttribute 7 | { 8 | public bool UseRegex { get; set; } = false; 9 | 10 | public LettersOnlyValidatorAttribute() 11 | : base("Value must contain only letters (no spaces, digits, or other chars)") { } 12 | 13 | protected override ValidationResult? IsValid( 14 | object? value, 15 | ValidationContext validationContext) 16 | { 17 | var strValue = value as string; 18 | if (!string.IsNullOrEmpty(strValue) 19 | && ( 20 | 21 | // using Regular Expressions 22 | (UseRegex && Regex.IsMatch(strValue, "^[A-Za-z]+$")) 23 | 24 | // using string manipulation methods 25 | || strValue.All(Char.IsLetter) 26 | 27 | )) 28 | return ValidationResult.Success; 29 | 30 | return new ValidationResult(ErrorMessage); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Extensions/DistributedCacheExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Caching.Distributed; 2 | using System.Text; 3 | using System.Text.Json; 4 | 5 | namespace MyBGList.Extensions 6 | { 7 | public static class DistributedCacheExtensions 8 | { 9 | public static bool TryGetValue( 10 | this IDistributedCache cache, 11 | string key, 12 | out T? value) 13 | { 14 | value = default; 15 | var val = cache.Get(key); 16 | if (val == null) return false; 17 | value = JsonSerializer.Deserialize(val); 18 | return true; 19 | } 20 | 21 | public static void Set( 22 | this IDistributedCache cache, 23 | string key, 24 | T value, 25 | TimeSpan absoluteExpirationRelativeToNow) 26 | { 27 | var bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value)); 28 | cache.Set(key, bytes, new DistributedCacheEntryOptions() 29 | { 30 | AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Extensions/DistributedCacheExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Caching.Distributed; 2 | using System.Text; 3 | using System.Text.Json; 4 | 5 | namespace MyBGList.Extensions 6 | { 7 | public static class DistributedCacheExtensions 8 | { 9 | public static bool TryGetValue( 10 | this IDistributedCache cache, 11 | string key, 12 | out T? value) 13 | { 14 | value = default; 15 | var val = cache.Get(key); 16 | if (val == null) return false; 17 | value = JsonSerializer.Deserialize(val); 18 | return true; 19 | } 20 | 21 | public static void Set( 22 | this IDistributedCache cache, 23 | string key, 24 | T value, 25 | TimeSpan absoluteExpirationRelativeToNow) 26 | { 27 | var bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value)); 28 | cache.Set(key, bytes, new DistributedCacheEntryOptions() 29 | { 30 | AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Extensions/DistributedCacheExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Caching.Distributed; 2 | using System.Text; 3 | using System.Text.Json; 4 | 5 | namespace MyBGList.Extensions 6 | { 7 | public static class DistributedCacheExtensions 8 | { 9 | public static bool TryGetValue( 10 | this IDistributedCache cache, 11 | string key, 12 | out T? value) 13 | { 14 | value = default; 15 | var val = cache.Get(key); 16 | if (val == null) return false; 17 | value = JsonSerializer.Deserialize(val); 18 | return true; 19 | } 20 | 21 | public static void Set( 22 | this IDistributedCache cache, 23 | string key, 24 | T value, 25 | TimeSpan absoluteExpirationRelativeToNow) 26 | { 27 | var bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value)); 28 | cache.Set(key, bytes, new DistributedCacheEntryOptions() 29 | { 30 | AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Extensions/DistributedCacheExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Caching.Distributed; 2 | using System.Text; 3 | using System.Text.Json; 4 | 5 | namespace MyBGList.Extensions 6 | { 7 | public static class DistributedCacheExtensions 8 | { 9 | public static bool TryGetValue( 10 | this IDistributedCache cache, 11 | string key, 12 | out T? value) 13 | { 14 | value = default; 15 | var val = cache.Get(key); 16 | if (val == null) return false; 17 | value = JsonSerializer.Deserialize(val); 18 | return true; 19 | } 20 | 21 | public static void Set( 22 | this IDistributedCache cache, 23 | string key, 24 | T value, 25 | TimeSpan absoluteExpirationRelativeToNow) 26 | { 27 | var bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value)); 28 | cache.Set(key, bytes, new DistributedCacheEntryOptions() 29 | { 30 | AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Extensions/DistributedCacheExtensions.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Extensions.Caching.Distributed; 2 | using System.Text; 3 | using System.Text.Json; 4 | 5 | namespace MyBGList.Extensions 6 | { 7 | public static class DistributedCacheExtensions 8 | { 9 | public static bool TryGetValue( 10 | this IDistributedCache cache, 11 | string key, 12 | out T? value) 13 | { 14 | value = default; 15 | var val = cache.Get(key); 16 | if (val == null) return false; 17 | value = JsonSerializer.Deserialize(val); 18 | return true; 19 | } 20 | 21 | public static void Set( 22 | this IDistributedCache cache, 23 | string key, 24 | T value, 25 | TimeSpan absoluteExpirationRelativeToNow) 26 | { 27 | var bytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(value)); 28 | cache.Set(key, bytes, new DistributedCacheEntryOptions() 29 | { 30 | AbsoluteExpirationRelativeToNow = absoluteExpirationRelativeToNow 31 | }); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Chapter_02/MyBGList/Controllers/BoardGamesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace MyBGList.Controllers 4 | { 5 | [Route("[controller]")] 6 | [ApiController] 7 | public class BoardGamesController : ControllerBase 8 | { 9 | private readonly ILogger _logger; 10 | 11 | public BoardGamesController(ILogger logger) 12 | { 13 | _logger = logger; 14 | } 15 | 16 | [HttpGet(Name = "GetBoardGames")] 17 | public IEnumerable Get() 18 | { 19 | return new[] { 20 | new BoardGame() { 21 | Id = 1, 22 | Name = "Axis & Allies", 23 | Year = 1981 24 | }, 25 | new BoardGame() { 26 | Id = 2, 27 | Name = "Citadels", 28 | Year = 2000 29 | }, 30 | new BoardGame() { 31 | Id = 3, 32 | Name = "Terraforming Mars", 33 | Year = 2016 34 | } 35 | }; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_12.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31829.152 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_12\MyBGList\MyBGList.csproj", "{382515AA-2454-4E46-B018-17D661C298AB}" 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 | {382515AA-2454-4E46-B018-17D661C298AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {382515AA-2454-4E46-B018-17D661C298AB}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {382515AA-2454-4E46-B018-17D661C298AB}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {382515AA-2454-4E46-B018-17D661C298AB}.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 = {58E128FF-6460-4A49-9E95-9D8E08D888FC} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Chapter_03/Exercises/Controllers/v3/CodeOnDemandController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Cors; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace MyBGList.Controllers.v3 5 | { 6 | [Route("v{version:apiVersion}/[controller]/[action]")] 7 | [ApiController] 8 | [ApiVersion("3.0")] 9 | public class CodeOnDemandController : ControllerBase 10 | { 11 | [HttpGet(Name = "Test2")] 12 | [EnableCors("AnyOrigin")] 13 | [ResponseCache(NoStore = true)] 14 | public ContentResult Test2(int? minutesToAdd = null) 15 | { 16 | var dateTime = DateTime.UtcNow; 17 | if (minutesToAdd.HasValue) 18 | dateTime = dateTime.AddMinutes(minutesToAdd.Value); 19 | 20 | return Content("" + 27 | "", 28 | "text/html"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new [] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new [] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new [] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel; 3 | using System.ComponentModel.DataAnnotations; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new [] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel.DataAnnotations; 3 | using DefaultValueAttribute = System.ComponentModel.DefaultValueAttribute; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new[] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel.DataAnnotations; 3 | using DefaultValueAttribute = System.ComponentModel.DefaultValueAttribute; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new[] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/DTO/RequestDTO.cs: -------------------------------------------------------------------------------- 1 | using MyBGList.Attributes; 2 | using System.ComponentModel.DataAnnotations; 3 | using DefaultValueAttribute = System.ComponentModel.DefaultValueAttribute; 4 | 5 | namespace MyBGList.DTO 6 | { 7 | public class RequestDTO : IValidatableObject 8 | { 9 | [DefaultValue(0)] 10 | public int PageIndex { get; set; } = 0; 11 | 12 | [DefaultValue(10)] 13 | [Range(1, 100)] 14 | public int PageSize { get; set; } = 10; 15 | 16 | [DefaultValue("Name")] 17 | public string? SortColumn { get; set; } = "Name"; 18 | 19 | [SortOrderValidator] 20 | [DefaultValue("ASC")] 21 | public string? SortOrder { get; set; } = "ASC"; 22 | 23 | [DefaultValue(null)] 24 | public string? FilterQuery { get; set; } = null; 25 | 26 | public IEnumerable Validate( 27 | ValidationContext validationContext) 28 | { 29 | var validator = new SortColumnValidatorAttribute(typeof(T)); 30 | var result = validator 31 | .GetValidationResult(SortColumn, validationContext); 32 | return (result != null) 33 | ? new[] { result } 34 | : new ValidationResult[0]; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/SortOrderFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortOrderFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | parameter.Schema.Extensions.Add( 28 | "pattern", 29 | new OpenApiString(string.Join("|", attribute.AllowedValues.Select(v => $"^{v}$"))) 30 | ); 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Chapter_05/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Models/Csv/BggRecord.cs: -------------------------------------------------------------------------------- 1 | using CsvHelper.Configuration.Attributes; 2 | 3 | namespace MyBGList.Models.Csv 4 | { 5 | public class BggRecord 6 | { 7 | [Name("ID")] 8 | public int? ID { get; set; } 9 | 10 | public string? Name { get; set; } 11 | 12 | [Name("Year Published")] 13 | public int? YearPublished { get; set; } 14 | 15 | [Name("Min Players")] 16 | public int? MinPlayers { get; set; } 17 | 18 | [Name("Max Players")] 19 | public int? MaxPlayers { get; set; } 20 | 21 | [Name("Play Time")] 22 | public int? PlayTime { get; set; } 23 | 24 | [Name("Min Age")] 25 | public int? MinAge { get; set; } 26 | 27 | [Name("Users Rated")] 28 | public int? UsersRated { get; set; } 29 | 30 | [Name("Rating Average")] 31 | public decimal? RatingAverage { get; set; } 32 | 33 | [Name("BGG Rank")] 34 | public int? BGGRank { get; set; } 35 | 36 | [Name("Complexity Average")] 37 | public decimal? ComplexityAverage { get; set; } 38 | 39 | [Name("Owned Users")] 40 | public int? OwnedUsers { get; set; } 41 | 42 | public string? Mechanics { get; set; } 43 | 44 | public string? Domains { get; set; } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Chapter_10/Exercises/grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option csharp_namespace = "MyBGList.gRPC"; 4 | 5 | package Grpc; 6 | 7 | service Grpc { 8 | rpc GetBoardGame (BoardGameRequest) returns (BoardGameResponse); 9 | rpc UpdateBoardGame (UpdateBoardGameRequest) returns (BoardGameResponse); 10 | rpc GetDomain (DomainRequest) returns (DomainResponse); 11 | rpc UpdateDomain (UpdateDomainRequest) returns (DomainResponse); 12 | rpc GetMechanic (MechanicRequest) returns (MechanicResponse); 13 | rpc UpdateMechanic (UpdateMechanicRequest) returns (MechanicResponse); 14 | } 15 | 16 | message BoardGameRequest { 17 | int32 id = 1; 18 | } 19 | 20 | message UpdateBoardGameRequest { 21 | int32 id = 1; 22 | string name = 2; 23 | } 24 | 25 | message BoardGameResponse { 26 | int32 id = 1; 27 | string name = 2; 28 | int32 year = 3; 29 | } 30 | 31 | message DomainRequest { 32 | int32 id = 1; 33 | } 34 | 35 | message UpdateDomainRequest { 36 | int32 id = 1; 37 | string name = 2; 38 | } 39 | 40 | message DomainResponse { 41 | int32 id = 1; 42 | string name = 2; 43 | } 44 | 45 | message MechanicRequest { 46 | int32 id = 1; 47 | } 48 | 49 | message UpdateMechanicRequest { 50 | int32 id = 1; 51 | string name = 2; 52 | } 53 | 54 | message MechanicResponse { 55 | int32 id = 1; 56 | string name = 2; 57 | } -------------------------------------------------------------------------------- /Chapter_02/Exercises/BoardGamesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | 3 | namespace MyBGList.Controllers 4 | { 5 | [Route("[controller]")] 6 | [ApiController] 7 | public class BoardGamesController : ControllerBase 8 | { 9 | private readonly ILogger _logger; 10 | 11 | public BoardGamesController(ILogger logger) 12 | { 13 | _logger = logger; 14 | } 15 | 16 | [HttpGet(Name = "GetBoardGames")] 17 | public IEnumerable Get() 18 | { 19 | return new[] { 20 | new BoardGame() { 21 | Id = 1, 22 | Name = "Axis & Allies", 23 | Year = 1981, 24 | MinPlayers = 2, 25 | MaxPlayers = 5 26 | }, 27 | new BoardGame() { 28 | Id = 2, 29 | Name = "Citadels", 30 | Year = 2000, 31 | MinPlayers = 2, 32 | MaxPlayers = 8 33 | }, 34 | new BoardGame() { 35 | Id = 3, 36 | Name = "Terraforming Mars", 37 | Year = 2016, 38 | MinPlayers = 1, 39 | MaxPlayers = 5 40 | } 41 | }; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Chapter_06/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_07/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_08/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_09/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/SortColumnFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.OpenApi.Any; 2 | using Microsoft.OpenApi.Models; 3 | using MyBGList.Attributes; 4 | using Swashbuckle.AspNetCore.SwaggerGen; 5 | 6 | namespace MyBGList.Swagger 7 | { 8 | public class SortColumnFilter : IParameterFilter 9 | { 10 | public void Apply( 11 | OpenApiParameter parameter, 12 | ParameterFilterContext context) 13 | { 14 | var attributes = context.ParameterInfo? 15 | .GetCustomAttributes(true) 16 | .Union( 17 | context.ParameterInfo.ParameterType.GetProperties() 18 | .Where(p => p.Name == parameter.Name) 19 | .SelectMany(p => p.GetCustomAttributes(true)) 20 | ) 21 | .OfType(); 22 | 23 | if (attributes != null) 24 | { 25 | foreach (var attribute in attributes) 26 | { 27 | var pattern = attribute.EntityType 28 | .GetProperties() 29 | .Select(p => p.Name); 30 | parameter.Schema.Extensions.Add( 31 | "pattern", 32 | new OpenApiString(string.Join("|", pattern.Select(v => $"^{v}$"))) 33 | ); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Swagger/AuthRequirementFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | 5 | namespace MyBGList.Swagger 6 | { 7 | internal class AuthRequirementFilter : IOperationFilter 8 | { 9 | public void Apply( 10 | OpenApiOperation operation, 11 | OperationFilterContext context) 12 | { 13 | if (!context.ApiDescription 14 | .ActionDescriptor 15 | .EndpointMetadata 16 | .OfType() 17 | .Any()) 18 | return; 19 | 20 | operation.Security = new List 21 | { 22 | new OpenApiSecurityRequirement 23 | { 24 | { 25 | new OpenApiSecurityScheme 26 | { 27 | Name = "Bearer", 28 | In = ParameterLocation.Header, 29 | Reference = new OpenApiReference 30 | { 31 | Type=ReferenceType.SecurityScheme, 32 | Id="Bearer" 33 | } 34 | }, 35 | Array.Empty() 36 | } 37 | } 38 | }; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Chapter_12/MyBGList/Swagger/AuthRequirementFilter.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Authorization; 2 | using Microsoft.OpenApi.Models; 3 | using Swashbuckle.AspNetCore.SwaggerGen; 4 | 5 | namespace MyBGList.Swagger 6 | { 7 | internal class AuthRequirementFilter : IOperationFilter 8 | { 9 | public void Apply( 10 | OpenApiOperation operation, 11 | OperationFilterContext context) 12 | { 13 | if (!context.ApiDescription 14 | .ActionDescriptor 15 | .EndpointMetadata 16 | .OfType() 17 | .Any()) 18 | return; 19 | 20 | operation.Security = new List 21 | { 22 | new OpenApiSecurityRequirement 23 | { 24 | { 25 | new OpenApiSecurityScheme 26 | { 27 | Name = "Bearer", 28 | In = ParameterLocation.Header, 29 | Reference = new OpenApiReference 30 | { 31 | Type=ReferenceType.SecurityScheme, 32 | Id="Bearer" 33 | } 34 | }, 35 | Array.Empty() 36 | } 37 | } 38 | }; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Chapter_07.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31829.152 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{6773746C-CAC2-4114-81DE-B3418FB485C5}" 7 | ProjectSection(SolutionItems) = preProject 8 | Chapter_07\Exercises\Program.cs = Chapter_07\Exercises\Program.cs 9 | EndProjectSection 10 | EndProject 11 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_07\MyBGList\MyBGList.csproj", "{D1B19A99-7980-4A5C-B289-E28BA6211927}" 12 | EndProject 13 | Global 14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 15 | Debug|Any CPU = Debug|Any CPU 16 | Release|Any CPU = Release|Any CPU 17 | EndGlobalSection 18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 19 | {D1B19A99-7980-4A5C-B289-E28BA6211927}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 20 | {D1B19A99-7980-4A5C-B289-E28BA6211927}.Debug|Any CPU.Build.0 = Debug|Any CPU 21 | {D1B19A99-7980-4A5C-B289-E28BA6211927}.Release|Any CPU.ActiveCfg = Release|Any CPU 22 | {D1B19A99-7980-4A5C-B289-E28BA6211927}.Release|Any CPU.Build.0 = Release|Any CPU 23 | EndGlobalSection 24 | GlobalSection(SolutionProperties) = preSolution 25 | HideSolutionNode = FALSE 26 | EndGlobalSection 27 | GlobalSection(ExtensibilityGlobals) = postSolution 28 | SolutionGuid = {58E128FF-6460-4A49-9E95-9D8E08D888FC} 29 | EndGlobalSection 30 | EndGlobal 31 | -------------------------------------------------------------------------------- /Chapter_03/MyBGList/Controllers/BoardGamesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using MyBGList.DTO; 3 | 4 | namespace MyBGList.Controllers 5 | { 6 | [Route("[controller]")] 7 | [ApiController] 8 | public class BoardGamesController : ControllerBase 9 | { 10 | private readonly ILogger _logger; 11 | 12 | public BoardGamesController(ILogger logger) 13 | { 14 | _logger = logger; 15 | } 16 | 17 | [HttpGet(Name = "GetBoardGames")] 18 | [ResponseCache(Location = ResponseCacheLocation.Any, Duration = 60)] 19 | public RestDTO Get() 20 | { 21 | return new RestDTO() 22 | { 23 | Data = new [] { 24 | new BoardGame() { 25 | Id = 1, 26 | Name = "Axis & Allies", 27 | Year = 1981 28 | }, 29 | new BoardGame() { 30 | Id = 2, 31 | Name = "Citadels", 32 | Year = 2000 33 | }, 34 | new BoardGame() { 35 | Id = 3, 36 | Name = "Terraforming Mars", 37 | Year = 2016 38 | } 39 | }, 40 | Links = new List { 41 | new LinkDTO( 42 | Url.Action(null, "BoardGames", null, Request.Scheme)!, 43 | "self", 44 | "GET"), 45 | } 46 | }; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /Chapter_04/MyBGList/Controllers/BoardGamesController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using MyBGList.DTO; 3 | using MyBGList.Models; 4 | 5 | namespace MyBGList.Controllers 6 | { 7 | [Route("[controller]")] 8 | [ApiController] 9 | public class BoardGamesController : ControllerBase 10 | { 11 | private readonly ILogger _logger; 12 | 13 | public BoardGamesController(ILogger logger) 14 | { 15 | _logger = logger; 16 | } 17 | 18 | [HttpGet(Name = "GetBoardGames")] 19 | [ResponseCache(Location = ResponseCacheLocation.Any, Duration = 60)] 20 | public RestDTO Get() 21 | { 22 | return new RestDTO() 23 | { 24 | Data = new [] { 25 | new BoardGame() { 26 | Id = 1, 27 | Name = "Axis & Allies", 28 | Year = 1981 29 | }, 30 | new BoardGame() { 31 | Id = 2, 32 | Name = "Citadels", 33 | Year = 2000 34 | }, 35 | new BoardGame() { 36 | Id = 3, 37 | Name = "Terraforming Mars", 38 | Year = 2016 39 | } 40 | }, 41 | Links = new List { 42 | new LinkDTO( 43 | Url.Action(null, "BoardGames", null, Request.Scheme)!, 44 | "self", 45 | "GET"), 46 | } 47 | }; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /Chapter_09.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31829.152 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{6773746C-CAC2-4114-81DE-B3418FB485C5}" 7 | ProjectSection(SolutionItems) = preProject 8 | Chapter_09\Exercises\Program.cs = Chapter_09\Exercises\Program.cs 9 | Chapter_09\Exercises\RoleNames.cs = Chapter_09\Exercises\RoleNames.cs 10 | Chapter_09\Exercises\SeedController.cs = Chapter_09\Exercises\SeedController.cs 11 | EndProjectSection 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_09\MyBGList\MyBGList.csproj", "{54620274-E479-498C-B770-10243F2520BA}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {54620274-E479-498C-B770-10243F2520BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {54620274-E479-498C-B770-10243F2520BA}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {54620274-E479-498C-B770-10243F2520BA}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {54620274-E479-498C-B770-10243F2520BA}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {58E128FF-6460-4A49-9E95-9D8E08D888FC} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /Chapter_08.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.31829.152 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Exercises", "Exercises", "{6773746C-CAC2-4114-81DE-B3418FB485C5}" 7 | ProjectSection(SolutionItems) = preProject 8 | Chapter_08\Exercises\BoardGamesController.cs = Chapter_08\Exercises\BoardGamesController.cs 9 | Chapter_08\Exercises\MechanicsController.cs = Chapter_08\Exercises\MechanicsController.cs 10 | Chapter_08\Exercises\Program.cs = Chapter_08\Exercises\Program.cs 11 | EndProjectSection 12 | EndProject 13 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyBGList", "Chapter_08\MyBGList\MyBGList.csproj", "{A1B5653A-C25C-4C4B-B16C-6473D19464A9}" 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {A1B5653A-C25C-4C4B-B16C-6473D19464A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {A1B5653A-C25C-4C4B-B16C-6473D19464A9}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {A1B5653A-C25C-4C4B-B16C-6473D19464A9}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {A1B5653A-C25C-4C4B-B16C-6473D19464A9}.Release|Any CPU.Build.0 = Release|Any CPU 25 | EndGlobalSection 26 | GlobalSection(SolutionProperties) = preSolution 27 | HideSolutionNode = FALSE 28 | EndGlobalSection 29 | GlobalSection(ExtensibilityGlobals) = postSolution 30 | SolutionGuid = {58E128FF-6460-4A49-9E95-9D8E08D888FC} 31 | EndGlobalSection 32 | EndGlobal 33 | -------------------------------------------------------------------------------- /Chapter_10/MyBGList/Controllers/GrpcController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Grpc.Net.Client; 3 | using MyBGList.gRPC; 4 | using Grpc.Core; 5 | 6 | namespace MyBGList.Controllers 7 | { 8 | [Route("[controller]/[action]")] 9 | [ApiController] 10 | public class GrpcController : ControllerBase 11 | { 12 | [HttpGet("{id}")] 13 | public async Task GetBoardGame(int id) 14 | { 15 | using var channel = GrpcChannel 16 | .ForAddress("https://localhost:40443"); 17 | var client = new gRPC.Grpc.GrpcClient(channel); 18 | var response = await client.GetBoardGameAsync( 19 | new BoardGameRequest { Id = id }); 20 | return response; 21 | } 22 | 23 | [HttpPost] 24 | public async Task UpdateBoardGame( 25 | string token, 26 | int id, 27 | string name) 28 | { 29 | var headers = new Metadata(); 30 | headers.Add("Authorization", $"Bearer {token}"); 31 | 32 | using var channel = GrpcChannel 33 | .ForAddress("https://localhost:40443"); 34 | var client = new gRPC.Grpc.GrpcClient(channel); 35 | var response = await client.UpdateBoardGameAsync( 36 | new UpdateBoardGameRequest 37 | { 38 | Id = id, 39 | Name = name 40 | }, 41 | headers); 42 | return response; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Chapter_11/MyBGList/Controllers/GrpcController.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc; 2 | using Grpc.Net.Client; 3 | using MyBGList.gRPC; 4 | using Grpc.Core; 5 | 6 | namespace MyBGList.Controllers 7 | { 8 | [Route("[controller]/[action]")] 9 | [ApiController] 10 | public class GrpcController : ControllerBase 11 | { 12 | [HttpGet("{id}")] 13 | public async Task GetBoardGame(int id) 14 | { 15 | using var channel = GrpcChannel 16 | .ForAddress("https://localhost:40443"); 17 | var client = new gRPC.Grpc.GrpcClient(channel); 18 | var response = await client.GetBoardGameAsync( 19 | new BoardGameRequest { Id = id }); 20 | return response; 21 | } 22 | 23 | [HttpPost] 24 | public async Task UpdateBoardGame( 25 | string token, 26 | int id, 27 | string name) 28 | { 29 | var headers = new Metadata(); 30 | headers.Add("Authorization", $"Bearer {token}"); 31 | 32 | using var channel = GrpcChannel 33 | .ForAddress("https://localhost:40443"); 34 | var client = new gRPC.Grpc.GrpcClient(channel); 35 | var response = await client.UpdateBoardGameAsync( 36 | new UpdateBoardGameRequest 37 | { 38 | Id = id, 39 | Name = name 40 | }, 41 | headers); 42 | return response; 43 | } 44 | } 45 | } 46 | --------------------------------------------------------------------------------