├── HotelListing ├── Properties │ ├── serviceDependencies.json │ ├── serviceDependencies.HotelListing20210123141020 - Web Deploy.json │ ├── launchSettings.json │ └── ServiceDependencies │ │ └── HotelListing20210123141020 - Web Deploy │ │ ├── mssql1.arm.json │ │ └── profile.arm.json ├── .config │ └── dotnet-tools.json ├── appsettings.Development.json ├── Data │ ├── ApiUser.cs │ ├── Country.cs │ ├── Hotel.cs │ └── DatabaseContext.cs ├── Services │ ├── IAuthManager.cs │ ├── AuthManager.cs │ └── ServiceExtensions.cs ├── Models │ ├── Error.cs │ ├── LoginUserDTO.cs │ ├── UserDTO.cs │ ├── RequestParams.cs │ ├── CountryDTO.cs │ └── HotelDTO.cs ├── IRepository │ ├── IUnitOfWork.cs │ └── IGenericRepository.cs ├── appsettings.json ├── Configurations │ ├── MapperInitilizer.cs │ └── Entities │ │ ├── RoleConfiguration.cs │ │ ├── CountryConfiguration.cs │ │ └── HotelConfiguration.cs ├── Controllers │ ├── CountryV2Controller.cs │ ├── AccountController.cs │ ├── HotelController.cs │ └── CountryController.cs ├── Repository │ ├── UnitOfWork.cs │ └── GenericRepository.cs ├── logs │ ├── log-20210123.txt │ └── log-20210524.txt ├── Program.cs ├── HotelListing.csproj ├── Startup.cs └── Migrations │ ├── 20210524131541_init.cs │ ├── DatabaseContextModelSnapshot.cs │ └── 20210524131541_init.Designer.cs ├── README.md ├── HotelListing.sln ├── .gitattributes └── .gitignore /HotelListing/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "type": "mssql", 5 | "connectionId": "sqlConnection" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /HotelListing/.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "dotnet-ef": { 6 | "version": "5.0.2", 7 | "commands": [ 8 | "dotnet-ef" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /HotelListing/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /HotelListing/Data/ApiUser.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | 3 | namespace HotelListing.Data 4 | { 5 | public class ApiUser : IdentityUser 6 | { 7 | public string FirstName { get; set; } 8 | public string LastName { get; set; } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /HotelListing/Services/IAuthManager.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Models; 2 | using System.Threading.Tasks; 3 | 4 | namespace HotelListing.Services 5 | { 6 | public interface IAuthManager 7 | { 8 | Task ValidateUser(LoginUserDTO userDTO); 9 | Task CreateToken(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /HotelListing/Models/Error.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | 3 | namespace HotelListing.Models 4 | { 5 | public class Error 6 | { 7 | public int StatusCode { get; set; } 8 | public string Message { get; set; } 9 | public override string ToString() => JsonConvert.SerializeObject(this); 10 | } 11 | 12 | } 13 | 14 | -------------------------------------------------------------------------------- /HotelListing/Data/Country.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace HotelListing.Data 4 | { 5 | public class Country 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set; } 9 | public string ShortName { get; set; } 10 | public virtual IList Hotels { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /HotelListing/IRepository/IUnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using System; 3 | using System.Threading.Tasks; 4 | 5 | namespace HotelListing.IRepository 6 | { 7 | public interface IUnitOfWork : IDisposable 8 | { 9 | IGenericRepository Countries { get; } 10 | IGenericRepository Hotels { get; } 11 | Task Save(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /HotelListing/Properties/serviceDependencies.HotelListing20210123141020 - Web Deploy.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "mssql1": { 4 | "resourceId": "/subscriptions/[parameters('subscriptionId')]/resourcegroups/[parameters('resourceGroupName')]/providers/Microsoft.Sql/servers/hotellistingdbserver/databases/HotelListing_db", 5 | "type": "mssql.azure", 6 | "connectionId": "sqlConnection", 7 | "secretStore": "AzureAppSettings" 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /HotelListing/Data/Hotel.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations.Schema; 2 | 3 | namespace HotelListing.Data 4 | { 5 | public class Hotel 6 | { 7 | public int Id { get; set; } 8 | public string Name { get; set; } 9 | public string Address { get; set; } 10 | public double Rating { get; set; } 11 | 12 | [ForeignKey(nameof(Country))] 13 | public int CountryId { get; set; } 14 | public Country Country { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /HotelListing/Models/LoginUserDTO.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel.DataAnnotations; 2 | 3 | namespace HotelListing.Models 4 | { 5 | public class LoginUserDTO 6 | { 7 | [Required] 8 | [DataType(DataType.EmailAddress)] 9 | public string Email { get; set; } 10 | 11 | [Required] 12 | [StringLength(15, ErrorMessage = "Your Password is limited to {2} to {1} characters", MinimumLength = 8)] 13 | public string Password { get; set; } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /HotelListing/Models/UserDTO.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace HotelListing.Models 5 | { 6 | 7 | public class UserDTO : LoginUserDTO 8 | { 9 | public string FirstName { get; set; } 10 | public string LastName { get; set; } 11 | 12 | [DataType(DataType.PhoneNumber)] 13 | public string PhoneNumber { get; set; } 14 | public ICollection Roles { get; set; } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /HotelListing/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft": "Warning", 6 | "Microsoft.Hosting.Lifetime": "Information" 7 | } 8 | }, 9 | "ConnectionStrings": { 10 | "DevConnection": "server=DESKTOP-02RK9HN\\QUADRATESQL; database=Hotellisting_db; integrated security=true; MultipleActiveResultSets=True" 11 | }, 12 | "Jwt": { 13 | "Issuer": "HotelListingAPI", 14 | "lifetime": 15 15 | }, 16 | "AllowedHosts": "*" 17 | } 18 | -------------------------------------------------------------------------------- /HotelListing/Models/RequestParams.cs: -------------------------------------------------------------------------------- 1 | namespace HotelListing.Models 2 | { 3 | public class RequestParams 4 | { 5 | const int maxPageSize = 50; 6 | public int PageNumber { get; set; } = 1; 7 | private int _pageSize = 10; 8 | 9 | public int PageSize 10 | { 11 | get 12 | { 13 | return _pageSize; 14 | } 15 | set 16 | { 17 | _pageSize = (value > maxPageSize) ? maxPageSize : value; 18 | } 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /HotelListing/Configurations/MapperInitilizer.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using HotelListing.Data; 3 | using HotelListing.Models; 4 | 5 | namespace HotelListing.Configurations 6 | { 7 | public class MapperInitilizer : Profile 8 | { 9 | public MapperInitilizer() 10 | { 11 | CreateMap().ReverseMap(); 12 | CreateMap().ReverseMap(); 13 | CreateMap().ReverseMap(); 14 | CreateMap().ReverseMap(); 15 | CreateMap().ReverseMap(); 16 | CreateMap().ReverseMap(); 17 | CreateMap().ReverseMap(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HotelListing 2 | .NET Core 5 Hotel Listing Web API 3 | 4 | - Build a fully data driven REST Web API using cutting edge technology 5 | - Create a database using Entity Framework Core 6 | - Unit Of Work and Generic Repository Pattern 7 | - Dependency Injection 8 | - Setup Logging using SeriLog 9 | - Setup API documentation using SwaggerUI 10 | - Understand the REST design principles 11 | - Understand C# 9 and .Net Core Web Syntax 12 | - Understand user Authentication using JWT (JSON Web Tokens) 13 | - Understand how to use Data Transfer Objects (DTOs) and AutoMapper 14 | - Manage Packages with NuGet Manager 15 | - Understand .NET 5 workflows, tools and application development 16 | - Setup GitHub for Source Control 17 | - Deploy Applications and Database to Microsoft Azure 18 | 19 | Contact me for .NET Trainings https://nirzaf.github.io -------------------------------------------------------------------------------- /HotelListing/Configurations/Entities/RoleConfiguration.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Identity; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | 5 | namespace HotelListing.Configurations.Entities 6 | { 7 | public class RoleConfiguration : IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasData( 12 | new IdentityRole 13 | { 14 | Name = "User", 15 | NormalizedName = "USER" 16 | }, 17 | new IdentityRole 18 | { 19 | Name = "Administrator", 20 | NormalizedName = "ADMINISTRATOR" 21 | } 22 | ); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /HotelListing/Models/CountryDTO.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace HotelListing.Models 5 | { 6 | 7 | public class CreateCountryDTO 8 | { 9 | [Required] 10 | [StringLength(maximumLength: 50, ErrorMessage = "Country Name Is Too Long")] 11 | public string Name { get; set; } 12 | 13 | [Required] 14 | [StringLength(maximumLength: 2, ErrorMessage = "Short Country Name Is Too Long")] 15 | public string ShortName { get; set; } 16 | } 17 | public class UpdateCountryDTO : CreateCountryDTO 18 | { 19 | public IList Hotels { get; set; } 20 | } 21 | 22 | public class CountryDTO : CreateCountryDTO 23 | { 24 | public int Id { get; set; } 25 | public IList Hotels { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /HotelListing/Data/DatabaseContext.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Configurations.Entities; 2 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace HotelListing.Data 6 | { 7 | public class DatabaseContext : IdentityDbContext 8 | { 9 | public DatabaseContext(DbContextOptions options) : base(options) 10 | { } 11 | public DbSet Countries { get; set; } 12 | public DbSet Hotels { get; set; } 13 | protected override void OnModelCreating(ModelBuilder builder) 14 | { 15 | base.OnModelCreating(builder); 16 | builder.ApplyConfiguration(new CountryConfiguration()); 17 | builder.ApplyConfiguration(new HotelConfiguration()); 18 | builder.ApplyConfiguration(new RoleConfiguration()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /HotelListing/Controllers/CountryV2Controller.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using Microsoft.AspNetCore.Http; 3 | using Microsoft.AspNetCore.Mvc; 4 | using System.Threading.Tasks; 5 | 6 | namespace HotelListing.Controllers 7 | { 8 | [ApiVersion("2.0", Deprecated = true)] 9 | [Route("api/country")] 10 | [ApiController] 11 | public class CountryV2Controller : ControllerBase 12 | { 13 | private DatabaseContext _context; 14 | 15 | public CountryV2Controller(DatabaseContext context) 16 | { 17 | _context = context; 18 | } 19 | 20 | [HttpGet] 21 | [ProducesResponseType(StatusCodes.Status200OK)] 22 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 23 | public async Task GetCountries() 24 | { 25 | return Ok(_context.Countries); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /HotelListing/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:60542", 7 | "sslPort": 44379 8 | } 9 | }, 10 | "$schema": "http://json.schemastore.org/launchsettings.json", 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "swagger", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "HotelListing": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "swagger", 24 | "environmentVariables": { 25 | "ASPNETCORE_ENVIRONMENT": "Development" 26 | }, 27 | "dotnetRunMessages": "true", 28 | "applicationUrl": "https://localhost:5001;http://localhost:5000" 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /HotelListing/Models/HotelDTO.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel.DataAnnotations; 3 | 4 | namespace HotelListing.Models 5 | { 6 | public class CreateHotelDTO 7 | { 8 | [Required] 9 | [StringLength(maximumLength: 150, ErrorMessage = "Hotel Name Is Too Long")] 10 | public string Name { get; set; } 11 | 12 | [Required] 13 | [StringLength(maximumLength: 250, ErrorMessage = "Address Name Is Too Long")] 14 | public string Address { get; set; } 15 | 16 | [Required] 17 | [Range(1, 5)] 18 | public double Rating { get; set; } 19 | 20 | //////[Required] 21 | public int CountryId { get; set; } 22 | } 23 | 24 | public class UpdateHotelDTO : CreateHotelDTO 25 | { 26 | 27 | } 28 | 29 | public class HotelDTO : CreateHotelDTO 30 | { 31 | public int Id { get; set; } 32 | public CountryDTO Country { get; set; } 33 | } 34 | 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /HotelListing/Repository/UnitOfWork.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using HotelListing.IRepository; 3 | using System; 4 | using System.Threading.Tasks; 5 | 6 | namespace HotelListing.Repository 7 | { 8 | public class UnitOfWork : IUnitOfWork 9 | { 10 | private readonly DatabaseContext _context; 11 | private IGenericRepository _countries; 12 | private IGenericRepository _hotels; 13 | 14 | public UnitOfWork(DatabaseContext context) 15 | { 16 | _context = context; 17 | } 18 | public IGenericRepository Countries => _countries ??= new GenericRepository(_context); 19 | public IGenericRepository Hotels => _hotels ??= new GenericRepository(_context); 20 | 21 | public void Dispose() 22 | { 23 | _context.Dispose(); 24 | GC.SuppressFinalize(this); 25 | } 26 | 27 | public async Task Save() 28 | { 29 | await _context.SaveChangesAsync(); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /HotelListing/IRepository/IGenericRepository.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Models; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Linq.Expressions; 6 | using System.Threading.Tasks; 7 | using X.PagedList; 8 | 9 | namespace HotelListing.IRepository 10 | { 11 | public interface IGenericRepository where T : class 12 | { 13 | Task> GetAll( 14 | Expression> expression = null, 15 | Func, IOrderedQueryable> orderBy = null, 16 | List includes = null 17 | ); 18 | Task> GetPagedList( 19 | RequestParams requestParams, 20 | List includes = null 21 | ); 22 | 23 | Task Get(Expression> expression, List includes = null); 24 | Task Insert(T entity); 25 | Task InsertRange(IEnumerable entities); 26 | Task Delete(int id); 27 | void DeleteRange(IEnumerable entities); 28 | void Update(T entity); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /HotelListing/Configurations/Entities/CountryConfiguration.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | 5 | namespace HotelListing.Configurations.Entities 6 | { 7 | public class CountryConfiguration : IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasData( 12 | new Country 13 | { 14 | Id = 1, 15 | Name = "Jamaica", 16 | ShortName = "JM" 17 | }, 18 | new Country 19 | { 20 | Id = 2, 21 | Name = "Bahamas", 22 | ShortName = "BS" 23 | }, 24 | new Country 25 | { 26 | Id = 3, 27 | Name = "Cayman Island", 28 | ShortName = "CI" 29 | } 30 | ); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /HotelListing/logs/log-20210123.txt: -------------------------------------------------------------------------------- 1 | 2021-01-23 14:06:14.742 -05:00 [INF] Application Is Starting 2 | 2021-01-23 14:06:16.933 -05:00 [INF] User profile is available. Using 'C:\Users\Trevoir\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. 3 | 2021-01-23 14:06:17.534 -05:00 [INF] Application started. Press Ctrl+C to shut down. 4 | 2021-01-23 14:06:17.534 -05:00 [INF] Hosting environment: Development 5 | 2021-01-23 14:06:17.534 -05:00 [INF] Content root path: C:\Users\Trevoir\source\repos\HotelListing\HotelListing 6 | 2021-01-23 14:06:17.580 -05:00 [INF] Request starting HTTP/2 GET https://localhost:44379/swagger/index.html - - 7 | 2021-01-23 14:06:17.751 -05:00 [INF] Request finished HTTP/2 GET https://localhost:44379/swagger/index.html - - - 200 - text/html;charset=utf-8 173.3644ms 8 | 2021-01-23 14:06:17.938 -05:00 [INF] Request starting HTTP/2 GET https://localhost:44379/swagger/v1/swagger.json - - 9 | 2021-01-23 14:06:18.170 -05:00 [INF] Request finished HTTP/2 GET https://localhost:44379/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 230.8497ms 10 | -------------------------------------------------------------------------------- /HotelListing.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30804.86 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelListing", "HotelListing\HotelListing.csproj", "{6FD680A8-D3EA-490F-8A89-F7B7789A09D9}" 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 | {6FD680A8-D3EA-490F-8A89-F7B7789A09D9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {6FD680A8-D3EA-490F-8A89-F7B7789A09D9}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {6FD680A8-D3EA-490F-8A89-F7B7789A09D9}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {6FD680A8-D3EA-490F-8A89-F7B7789A09D9}.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 = {E01E48CA-1BD9-410D-BBBC-C4CC97604F65} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /HotelListing/Configurations/Entities/HotelConfiguration.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using Microsoft.EntityFrameworkCore; 3 | using Microsoft.EntityFrameworkCore.Metadata.Builders; 4 | 5 | namespace HotelListing.Configurations.Entities 6 | { 7 | public class HotelConfiguration : IEntityTypeConfiguration 8 | { 9 | public void Configure(EntityTypeBuilder builder) 10 | { 11 | builder.HasData( 12 | new Hotel 13 | { 14 | Id = 1, 15 | Name = "Sandals Resort and Spa", 16 | Address = "Negril", 17 | CountryId = 1, 18 | Rating = 4.5 19 | }, 20 | new Hotel 21 | { 22 | Id = 2, 23 | Name = "Comfort Suites", 24 | Address = "George Town", 25 | CountryId = 3, 26 | Rating = 4.3 27 | }, 28 | new Hotel 29 | { 30 | Id = 3, 31 | Name = "Grand Palldium", 32 | Address = "Nassua", 33 | CountryId = 2, 34 | Rating = 4 35 | } 36 | ); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /HotelListing/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Hosting; 3 | using Serilog; 4 | using Serilog.Events; 5 | using System; 6 | 7 | namespace HotelListing 8 | { 9 | public class Program 10 | { 11 | public static void Main(string[] args) 12 | { 13 | Log.Logger = new LoggerConfiguration() 14 | .WriteTo.File( 15 | path: "logs\\log-.txt", 16 | outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}", 17 | rollingInterval: RollingInterval.Day, 18 | restrictedToMinimumLevel: LogEventLevel.Information 19 | ).CreateLogger(); 20 | try 21 | { 22 | Log.Information("Application Is Starting"); 23 | CreateHostBuilder(args).Build().Run(); 24 | } 25 | catch (Exception ex) 26 | { 27 | Log.Fatal(ex, "Application Failed to start"); 28 | } 29 | finally 30 | { 31 | Log.CloseAndFlush(); 32 | } 33 | 34 | } 35 | 36 | public static IHostBuilder CreateHostBuilder(string[] args) => 37 | Host.CreateDefaultBuilder(args) 38 | .UseSerilog() 39 | .ConfigureWebHostDefaults(webBuilder => 40 | { 41 | webBuilder.UseStartup(); 42 | }); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /HotelListing/HotelListing.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net5.0 5 | cd3d17eb-4bf8-42e4-98e9-d7a0096180fd 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | all 22 | runtime; build; native; contentfiles; analyzers; buildtransitive 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /HotelListing/Controllers/AccountController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using HotelListing.Data; 3 | using HotelListing.Models; 4 | using HotelListing.Services; 5 | using Microsoft.AspNetCore.Http; 6 | using Microsoft.AspNetCore.Identity; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Logging; 9 | using System.Threading.Tasks; 10 | 11 | namespace HotelListing.Controllers 12 | { 13 | [Route("api/[controller]")] 14 | [ApiController] 15 | public class AccountController : ControllerBase 16 | { 17 | private readonly UserManager _userManager; 18 | private readonly ILogger _logger; 19 | private readonly IMapper _mapper; 20 | private readonly IAuthManager _authManager; 21 | 22 | public AccountController(UserManager userManager, 23 | ILogger logger, 24 | IMapper mapper, 25 | IAuthManager authManager) 26 | { 27 | _userManager = userManager; 28 | _logger = logger; 29 | _mapper = mapper; 30 | _authManager = authManager; 31 | } 32 | 33 | [HttpPost] 34 | [Route("register")] 35 | [ProducesResponseType(StatusCodes.Status202Accepted)] 36 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 37 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 38 | public async Task Register([FromBody] UserDTO userDTO) 39 | { 40 | _logger.LogInformation($"Registration Attempt for {userDTO.Email} "); 41 | if (!ModelState.IsValid) 42 | { 43 | return BadRequest(ModelState); 44 | } 45 | 46 | 47 | var user = _mapper.Map(userDTO); 48 | user.UserName = userDTO.Email; 49 | var result = await _userManager.CreateAsync(user, userDTO.Password); 50 | 51 | if (!result.Succeeded) 52 | { 53 | foreach (var error in result.Errors) 54 | { 55 | ModelState.AddModelError(error.Code, error.Description); 56 | } 57 | return BadRequest(ModelState); 58 | } 59 | await _userManager.AddToRolesAsync(user, userDTO.Roles); 60 | return Accepted(); 61 | } 62 | 63 | [HttpPost] 64 | [Route("login")] 65 | public async Task Login([FromBody] LoginUserDTO userDTO) 66 | { 67 | _logger.LogInformation($"Login Attempt for {userDTO.Email} "); 68 | if (!ModelState.IsValid) 69 | { 70 | return BadRequest(ModelState); 71 | } 72 | 73 | if (!await _authManager.ValidateUser(userDTO)) 74 | { 75 | return Unauthorized(); 76 | } 77 | 78 | return Accepted(new { Token = await _authManager.CreateToken() }); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /HotelListing/Services/AuthManager.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using HotelListing.Models; 3 | using Microsoft.AspNetCore.Identity; 4 | using Microsoft.Extensions.Configuration; 5 | using Microsoft.IdentityModel.Tokens; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.IdentityModel.Tokens.Jwt; 9 | using System.Security.Claims; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace HotelListing.Services 14 | { 15 | public class AuthManager : IAuthManager 16 | { 17 | private readonly UserManager _userManager; 18 | private readonly IConfiguration _configuration; 19 | private ApiUser _user; 20 | public AuthManager(UserManager userManager, 21 | IConfiguration configuration) 22 | { 23 | _userManager = userManager; 24 | _configuration = configuration; 25 | } 26 | 27 | public async Task CreateToken() 28 | { 29 | var signingCredentials = GetSigningCredentials(); 30 | var claims = await GetClaims(); 31 | var token = GenerateTokenOptions(signingCredentials, claims); 32 | 33 | return new JwtSecurityTokenHandler().WriteToken(token); 34 | } 35 | 36 | private JwtSecurityToken GenerateTokenOptions(SigningCredentials signingCredentials, List claims) 37 | { 38 | var jwtSettings = _configuration.GetSection("Jwt"); 39 | var expiration = DateTime.Now.AddMinutes(Convert.ToDouble( 40 | jwtSettings.GetSection("lifetime").Value)); 41 | 42 | var token = new JwtSecurityToken( 43 | issuer: jwtSettings.GetSection("Issuer").Value, 44 | claims: claims, 45 | expires: expiration, 46 | signingCredentials: signingCredentials 47 | ); 48 | 49 | return token; 50 | } 51 | 52 | private async Task> GetClaims() 53 | { 54 | var claims = new List 55 | { 56 | new Claim(ClaimTypes.Name, _user.UserName) 57 | }; 58 | 59 | var roles = await _userManager.GetRolesAsync(_user); 60 | 61 | foreach (var role in roles) 62 | { 63 | claims.Add(new Claim(ClaimTypes.Role, role)); 64 | } 65 | 66 | return claims; 67 | } 68 | 69 | private SigningCredentials GetSigningCredentials() 70 | { 71 | var key = Environment.GetEnvironmentVariable("KEY"); 72 | var secret = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)); 73 | 74 | return new SigningCredentials(secret, SecurityAlgorithms.HmacSha256); 75 | } 76 | 77 | public async Task ValidateUser(LoginUserDTO userDTO) 78 | { 79 | _user = await _userManager.FindByNameAsync(userDTO.Email); 80 | var validPassword = await _userManager.CheckPasswordAsync(_user, userDTO.Password); 81 | return (_user != null && validPassword); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /HotelListing/Properties/ServiceDependencies/HotelListing20210123141020 - Web Deploy/mssql1.arm.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "parameters": { 5 | "resourceGroupName": { 6 | "type": "string", 7 | "defaultValue": "hotel_listing_api", 8 | "metadata": { 9 | "_parameterType": "resourceGroup", 10 | "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." 11 | } 12 | }, 13 | "resourceGroupLocation": { 14 | "type": "string", 15 | "defaultValue": "eastus2", 16 | "metadata": { 17 | "_parameterType": "location", 18 | "description": "Location of the resource group. Resource groups could have different location than resources." 19 | } 20 | }, 21 | "resourceLocation": { 22 | "type": "string", 23 | "defaultValue": "[parameters('resourceGroupLocation')]", 24 | "metadata": { 25 | "_parameterType": "location", 26 | "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." 27 | } 28 | } 29 | }, 30 | "resources": [ 31 | { 32 | "type": "Microsoft.Resources/resourceGroups", 33 | "name": "[parameters('resourceGroupName')]", 34 | "location": "[parameters('resourceGroupLocation')]", 35 | "apiVersion": "2019-10-01" 36 | }, 37 | { 38 | "type": "Microsoft.Resources/deployments", 39 | "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('HotelListing_db', subscription().subscriptionId)))]", 40 | "resourceGroup": "[parameters('resourceGroupName')]", 41 | "apiVersion": "2019-10-01", 42 | "dependsOn": [ 43 | "[parameters('resourceGroupName')]" 44 | ], 45 | "properties": { 46 | "mode": "Incremental", 47 | "template": { 48 | "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 49 | "contentVersion": "1.0.0.0", 50 | "resources": [ 51 | { 52 | "kind": "v12.0", 53 | "location": "[parameters('resourceLocation')]", 54 | "name": "hotellistingdbserver", 55 | "type": "Microsoft.Sql/servers", 56 | "apiVersion": "2017-10-01-preview" 57 | }, 58 | { 59 | "sku": { 60 | "name": "Standard", 61 | "tier": "Standard", 62 | "capacity": 10 63 | }, 64 | "kind": "v12.0,user", 65 | "location": "[parameters('resourceLocation')]", 66 | "name": "hotellistingdbserver/HotelListing_db", 67 | "type": "Microsoft.Sql/servers/databases", 68 | "apiVersion": "2017-10-01-preview", 69 | "dependsOn": [ 70 | "hotellistingdbserver" 71 | ] 72 | } 73 | ] 74 | } 75 | } 76 | } 77 | ], 78 | "metadata": { 79 | "_dependencyType": "mssql.azure" 80 | } 81 | } -------------------------------------------------------------------------------- /HotelListing/Repository/GenericRepository.cs: -------------------------------------------------------------------------------- 1 | using HotelListing.Data; 2 | using HotelListing.IRepository; 3 | using HotelListing.Models; 4 | using Microsoft.EntityFrameworkCore; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Linq.Expressions; 9 | using System.Threading.Tasks; 10 | using X.PagedList; 11 | 12 | namespace HotelListing.Repository 13 | { 14 | public class GenericRepository : IGenericRepository where T : class 15 | { 16 | private readonly DatabaseContext _context; 17 | private readonly DbSet _db; 18 | 19 | public GenericRepository(DatabaseContext context) 20 | { 21 | _context = context; 22 | _db = _context.Set(); 23 | } 24 | 25 | public async Task Delete(int id) 26 | { 27 | var entity = await _db.FindAsync(id); 28 | _db.Remove(entity); 29 | } 30 | 31 | public void DeleteRange(IEnumerable entities) 32 | { 33 | _db.RemoveRange(entities); 34 | } 35 | 36 | public async Task Get(Expression> expression, List includes = null) 37 | { 38 | IQueryable query = _db; 39 | if (includes != null) 40 | { 41 | foreach (var includePropery in includes) 42 | { 43 | query = query.Include(includePropery); 44 | } 45 | } 46 | 47 | return await query.AsNoTracking().FirstOrDefaultAsync(expression); 48 | } 49 | 50 | public async Task> GetAll(Expression> expression = null, Func, IOrderedQueryable> orderBy = null, List includes = null) 51 | { 52 | IQueryable query = _db; 53 | 54 | if (expression != null) 55 | { 56 | query = query.Where(expression); 57 | } 58 | 59 | if (includes != null) 60 | { 61 | foreach (var includePropery in includes) 62 | { 63 | query = query.Include(includePropery); 64 | } 65 | } 66 | 67 | if (orderBy != null) 68 | { 69 | query = orderBy(query); 70 | } 71 | 72 | return await query.AsNoTracking().ToListAsync(); 73 | } 74 | 75 | public async Task> GetPagedList(RequestParams requestParams, List includes = null) 76 | { 77 | IQueryable query = _db; 78 | 79 | 80 | if (includes != null) 81 | { 82 | foreach (var includePropery in includes) 83 | { 84 | query = query.Include(includePropery); 85 | } 86 | } 87 | 88 | return await query.AsNoTracking() 89 | .ToPagedListAsync(requestParams.PageNumber, requestParams.PageSize); 90 | } 91 | 92 | public async Task Insert(T entity) 93 | { 94 | await _db.AddAsync(entity); 95 | } 96 | 97 | public async Task InsertRange(IEnumerable entities) 98 | { 99 | await _db.AddRangeAsync(entities); 100 | } 101 | 102 | public void Update(T entity) 103 | { 104 | _db.Attach(entity); 105 | _context.Entry(entity).State = EntityState.Modified; 106 | } 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /HotelListing/Startup.cs: -------------------------------------------------------------------------------- 1 | using AspNetCoreRateLimit; 2 | using AutoMapper; 3 | using HotelListing.Configurations; 4 | using HotelListing.Data; 5 | using HotelListing.IRepository; 6 | using HotelListing.Repository; 7 | using HotelListing.Services; 8 | using Microsoft.AspNetCore.Builder; 9 | using Microsoft.AspNetCore.Hosting; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.EntityFrameworkCore; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using Microsoft.Extensions.Hosting; 15 | using Microsoft.OpenApi.Models; 16 | 17 | namespace HotelListing 18 | { 19 | public class Startup 20 | { 21 | public Startup(IConfiguration configuration) 22 | { 23 | Configuration = configuration; 24 | } 25 | 26 | public IConfiguration Configuration { get; } 27 | 28 | // This method gets called by the runtime. Use this method to add services to the container. 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | services.AddDbContext(options => 32 | options.UseSqlServer(Configuration.GetConnectionString("DevConnection")) 33 | ); 34 | 35 | services.AddMemoryCache(); 36 | services.ConfigureRateLimiting(); 37 | services.AddHttpContextAccessor(); 38 | services.ConfigureHttpCacheHeaders(); 39 | services.AddAuthentication(); 40 | services.ConfigureIdentity(); 41 | services.ConfigureJWT(Configuration); 42 | 43 | services.AddCors(o => 44 | { 45 | o.AddPolicy("AllowAll", builder => 46 | builder.AllowAnyOrigin() 47 | .AllowAnyMethod() 48 | .AllowAnyHeader()); 49 | }); 50 | 51 | services.AddAutoMapper(typeof(MapperInitilizer)); 52 | 53 | services.AddTransient(); 54 | services.AddScoped(); 55 | 56 | services.AddSwaggerGen(c => 57 | { 58 | c.SwaggerDoc("v1", new OpenApiInfo { Title = "HotelListing", Version = "v1" }); 59 | }); 60 | 61 | services.AddControllers(config => 62 | { 63 | config.CacheProfiles.Add("120SecondsDuration", new CacheProfile 64 | { 65 | Duration = 120 66 | 67 | }); 68 | }).AddNewtonsoftJson(op => 69 | op.SerializerSettings.ReferenceLoopHandling = 70 | Newtonsoft.Json.ReferenceLoopHandling.Ignore); 71 | 72 | services.ConfigureVersioning(); 73 | } 74 | 75 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 76 | public void Configure(IApplicationBuilder app, IWebHostEnvironment env) 77 | { 78 | if (env.IsDevelopment()) 79 | { 80 | app.UseDeveloperExceptionPage(); 81 | } 82 | 83 | app.UseSwagger(); 84 | app.UseSwaggerUI(c => 85 | { 86 | string swaggerJsonBasePath = string.IsNullOrWhiteSpace(c.RoutePrefix) ? "." : ".."; 87 | c.SwaggerEndpoint($"{swaggerJsonBasePath}/swagger/v1/swagger.json", "Hotel Listing API"); 88 | }); 89 | 90 | app.ConfigureExceptionHandler(); 91 | app.UseHttpsRedirection(); 92 | app.UseCors("AllowAll"); 93 | app.UseResponseCaching(); 94 | app.UseHttpCacheHeaders(); 95 | app.UseIpRateLimiting(); 96 | app.UseRouting(); 97 | app.UseAuthentication(); 98 | app.UseAuthorization(); 99 | 100 | app.UseEndpoints(endpoints => 101 | { 102 | endpoints.MapControllers(); 103 | }); 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /HotelListing/Properties/ServiceDependencies/HotelListing20210123141020 - Web Deploy/profile.arm.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#", 3 | "contentVersion": "1.0.0.0", 4 | "metadata": { 5 | "_dependencyType": "appService.windows" 6 | }, 7 | "parameters": { 8 | "resourceGroupName": { 9 | "type": "string", 10 | "defaultValue": "hotel_listing_api", 11 | "metadata": { 12 | "description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking." 13 | } 14 | }, 15 | "resourceGroupLocation": { 16 | "type": "string", 17 | "defaultValue": "eastus2", 18 | "metadata": { 19 | "description": "Location of the resource group. Resource groups could have different location than resources, however by default we use API versions from latest hybrid profile which support all locations for resource types we support." 20 | } 21 | }, 22 | "resourceName": { 23 | "type": "string", 24 | "defaultValue": "HotelListing20210123141020", 25 | "metadata": { 26 | "description": "Name of the main resource to be created by this template." 27 | } 28 | }, 29 | "resourceLocation": { 30 | "type": "string", 31 | "defaultValue": "[parameters('resourceGroupLocation')]", 32 | "metadata": { 33 | "description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there." 34 | } 35 | } 36 | }, 37 | "variables": { 38 | "appServicePlan_name": "[concat('Plan', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", 39 | "appServicePlan_ResourceId": "[concat('/subscriptions/', subscription().subscriptionId, '/resourceGroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/serverFarms/', variables('appServicePlan_name'))]" 40 | }, 41 | "resources": [ 42 | { 43 | "type": "Microsoft.Resources/resourceGroups", 44 | "name": "[parameters('resourceGroupName')]", 45 | "location": "[parameters('resourceGroupLocation')]", 46 | "apiVersion": "2019-10-01" 47 | }, 48 | { 49 | "type": "Microsoft.Resources/deployments", 50 | "name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat(parameters('resourceName'), subscription().subscriptionId)))]", 51 | "resourceGroup": "[parameters('resourceGroupName')]", 52 | "apiVersion": "2019-10-01", 53 | "dependsOn": [ 54 | "[parameters('resourceGroupName')]" 55 | ], 56 | "properties": { 57 | "mode": "Incremental", 58 | "template": { 59 | "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 60 | "contentVersion": "1.0.0.0", 61 | "resources": [ 62 | { 63 | "location": "[parameters('resourceLocation')]", 64 | "name": "[parameters('resourceName')]", 65 | "type": "Microsoft.Web/sites", 66 | "apiVersion": "2015-08-01", 67 | "tags": { 68 | "[concat('hidden-related:', variables('appServicePlan_ResourceId'))]": "empty" 69 | }, 70 | "dependsOn": [ 71 | "[variables('appServicePlan_ResourceId')]" 72 | ], 73 | "kind": "app", 74 | "properties": { 75 | "name": "[parameters('resourceName')]", 76 | "kind": "app", 77 | "httpsOnly": true, 78 | "reserved": false, 79 | "serverFarmId": "[variables('appServicePlan_ResourceId')]", 80 | "siteConfig": { 81 | "metadata": [ 82 | { 83 | "name": "CURRENT_STACK", 84 | "value": "dotnetcore" 85 | } 86 | ] 87 | } 88 | }, 89 | "identity": { 90 | "type": "SystemAssigned" 91 | } 92 | }, 93 | { 94 | "location": "[parameters('resourceLocation')]", 95 | "name": "[variables('appServicePlan_name')]", 96 | "type": "Microsoft.Web/serverFarms", 97 | "apiVersion": "2015-08-01", 98 | "sku": { 99 | "name": "S1", 100 | "tier": "Standard", 101 | "family": "S", 102 | "size": "S1" 103 | }, 104 | "properties": { 105 | "name": "[variables('appServicePlan_name')]" 106 | } 107 | } 108 | ] 109 | } 110 | } 111 | } 112 | ] 113 | } -------------------------------------------------------------------------------- /HotelListing/Controllers/HotelController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using HotelListing.Data; 3 | using HotelListing.IRepository; 4 | using HotelListing.Models; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Logging; 9 | using System.Collections.Generic; 10 | using System.Threading.Tasks; 11 | 12 | namespace HotelListing.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class HotelController : ControllerBase 17 | { 18 | private readonly IUnitOfWork _unitOfWork; 19 | private readonly ILogger _logger; 20 | private readonly IMapper _mapper; 21 | 22 | public HotelController(IUnitOfWork unitOfWork, ILogger logger, 23 | IMapper mapper) 24 | { 25 | _unitOfWork = unitOfWork; 26 | _logger = logger; 27 | _mapper = mapper; 28 | } 29 | 30 | [HttpGet] 31 | [ProducesResponseType(StatusCodes.Status200OK)] 32 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 33 | public async Task GetHotels([FromQuery] RequestParams requestParams) 34 | { 35 | var hotels = await _unitOfWork.Hotels.GetPagedList(requestParams); 36 | var results = _mapper.Map>(hotels); 37 | return Ok(results); 38 | } 39 | 40 | [HttpGet("{id:int}", Name = "GetHotel")] 41 | [ProducesResponseType(StatusCodes.Status200OK)] 42 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 43 | public async Task GetHotel(int id) 44 | { 45 | var hotel = await _unitOfWork.Hotels.Get(q => q.Id == id, new List { "Country" }); 46 | var result = _mapper.Map(hotel); 47 | return Ok(result); 48 | } 49 | 50 | //Role based Authorization 51 | [Authorize(Roles = "Administrator")] 52 | [HttpPost] 53 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 54 | [ProducesResponseType(StatusCodes.Status201Created)] 55 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 56 | public async Task CreateHotel([FromBody] CreateHotelDTO hotelDTO) 57 | { 58 | if (!ModelState.IsValid) 59 | { 60 | _logger.LogError($"Invalid POST attempt in {nameof(CreateHotel)}"); 61 | return BadRequest(ModelState); 62 | } 63 | 64 | // Mapping the Model with Data Transfer Object DTO 65 | var hotel = _mapper.Map(hotelDTO); 66 | // Inserting Hotel Object into Unit of work object 67 | await _unitOfWork.Hotels.Insert(hotel); 68 | // Save the data into the database 69 | await _unitOfWork.Save(); 70 | // Riderect to GetHotel controller with Hotel Id and hotel Object 71 | return CreatedAtRoute("GetHotel", new { id = hotel.Id }, hotel); 72 | } 73 | 74 | [Authorize] 75 | [HttpPut("{id:int}")] 76 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 77 | [ProducesResponseType(StatusCodes.Status200OK)] 78 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 79 | public async Task UpdateHotel(int id, [FromBody] UpdateHotelDTO hotelDTO) 80 | { 81 | if (!ModelState.IsValid || id < 1) 82 | { 83 | _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateHotel)}"); 84 | return BadRequest(ModelState); 85 | } 86 | 87 | var hotel = await _unitOfWork.Hotels.Get(q => q.Id == id); 88 | if (hotel == null) 89 | { 90 | _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateHotel)}"); 91 | return BadRequest("Submitted data is invalid"); 92 | } 93 | 94 | _mapper.Map(hotelDTO, hotel); 95 | _unitOfWork.Hotels.Update(hotel); 96 | await _unitOfWork.Save(); 97 | return Ok(); 98 | 99 | } 100 | 101 | [Authorize] 102 | [HttpDelete("{id:int}")] 103 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 104 | [ProducesResponseType(StatusCodes.Status204NoContent)] 105 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 106 | public async Task DeleteHotel(int id) 107 | { 108 | if (id < 1) 109 | { 110 | _logger.LogError($"Invalid DELETE attempt in {nameof(DeleteHotel)}"); 111 | return BadRequest(); 112 | } 113 | 114 | var hotel = await _unitOfWork.Hotels.Get(q => q.Id == id); 115 | if (hotel == null) 116 | { 117 | _logger.LogError($"Invalid DELETE attempt in {nameof(DeleteHotel)}"); 118 | return BadRequest("Submitted data is invalid"); 119 | } 120 | 121 | await _unitOfWork.Hotels.Delete(id); 122 | await _unitOfWork.Save(); 123 | return NoContent(); 124 | } 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /HotelListing/Services/ServiceExtensions.cs: -------------------------------------------------------------------------------- 1 | using AspNetCoreRateLimit; 2 | using HotelListing.Data; 3 | using HotelListing.Models; 4 | using Marvin.Cache.Headers; 5 | using Microsoft.AspNetCore.Authentication.JwtBearer; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.AspNetCore.Diagnostics; 8 | using Microsoft.AspNetCore.Http; 9 | using Microsoft.AspNetCore.Identity; 10 | using Microsoft.AspNetCore.Mvc; 11 | using Microsoft.AspNetCore.Mvc.Versioning; 12 | using Microsoft.Extensions.Configuration; 13 | using Microsoft.Extensions.DependencyInjection; 14 | using Microsoft.IdentityModel.Tokens; 15 | using Serilog; 16 | using System; 17 | using System.Collections.Generic; 18 | using System.Text; 19 | 20 | namespace HotelListing 21 | { 22 | public static class ServiceExtensions 23 | { 24 | public static void ConfigureIdentity(this IServiceCollection services) 25 | { 26 | var builder = services.AddIdentityCore(q => { q.User.RequireUniqueEmail = true; }); 27 | 28 | builder = new IdentityBuilder(builder.UserType, typeof(IdentityRole), services); 29 | builder.AddEntityFrameworkStores().AddDefaultTokenProviders(); 30 | } 31 | 32 | public static void ConfigureJWT(this IServiceCollection services, IConfiguration Configuration) 33 | { 34 | var jwtSettings = Configuration.GetSection("Jwt"); 35 | var key = Environment.GetEnvironmentVariable("KEY"); 36 | 37 | services.AddAuthentication(o => 38 | { 39 | o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; 40 | o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; 41 | }) 42 | .AddJwtBearer(o => 43 | { 44 | o.TokenValidationParameters = new TokenValidationParameters 45 | { 46 | ValidateIssuer = true, 47 | ValidateAudience = false, 48 | ValidateLifetime = true, 49 | ValidateIssuerSigningKey = true, 50 | ValidIssuer = jwtSettings.GetSection("Issuer").Value, 51 | IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(key)), 52 | }; 53 | }); 54 | } 55 | 56 | public static void ConfigureExceptionHandler(this IApplicationBuilder app) 57 | { 58 | app.UseExceptionHandler(error => 59 | { 60 | error.Run(async context => 61 | { 62 | context.Response.StatusCode = StatusCodes.Status500InternalServerError; 63 | context.Response.ContentType = "application/json"; 64 | var contextFeature = context.Features.Get(); 65 | if (contextFeature != null) 66 | { 67 | Log.Error($"Something Went Wrong in the {contextFeature.Error}"); 68 | 69 | await context.Response.WriteAsync(new Error 70 | { 71 | StatusCode = context.Response.StatusCode, 72 | Message = "Internal Server Error. Please Try Again Later." 73 | }.ToString()); 74 | } 75 | }); 76 | }); 77 | } 78 | 79 | public static void ConfigureVersioning(this IServiceCollection services) 80 | { 81 | services.AddApiVersioning(opt => 82 | { 83 | opt.ReportApiVersions = true; 84 | opt.AssumeDefaultVersionWhenUnspecified = true; 85 | opt.DefaultApiVersion = new ApiVersion(1, 0); 86 | opt.ApiVersionReader = new HeaderApiVersionReader("api-version"); 87 | }); 88 | } 89 | 90 | public static void ConfigureHttpCacheHeaders(this IServiceCollection services) 91 | { 92 | services.AddResponseCaching(); 93 | services.AddHttpCacheHeaders( 94 | (expirationOpt) => 95 | { 96 | expirationOpt.MaxAge = 120; 97 | expirationOpt.CacheLocation = CacheLocation.Private; 98 | }, 99 | (validationOpt) => 100 | { 101 | validationOpt.MustRevalidate = true; 102 | } 103 | ); 104 | } 105 | 106 | public static void ConfigureRateLimiting(this IServiceCollection services) 107 | { 108 | var rateLimitRules = new List 109 | { 110 | new RateLimitRule 111 | { 112 | Endpoint = "*", 113 | Limit= 1, 114 | Period = "5s" 115 | } 116 | }; 117 | services.Configure(opt => 118 | { 119 | opt.GeneralRules = rateLimitRules; 120 | }); 121 | services.AddSingleton(); 122 | services.AddSingleton(); 123 | services.AddSingleton(); 124 | } 125 | 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /HotelListing/Controllers/CountryController.cs: -------------------------------------------------------------------------------- 1 | using AutoMapper; 2 | using HotelListing.Data; 3 | using HotelListing.IRepository; 4 | using HotelListing.Models; 5 | using Microsoft.AspNetCore.Authorization; 6 | using Microsoft.AspNetCore.Http; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Logging; 9 | using System.Collections.Generic; 10 | using System.Threading.Tasks; 11 | 12 | namespace HotelListing.Controllers 13 | { 14 | [Route("api/[controller]")] 15 | [ApiController] 16 | public class CountryController : ControllerBase 17 | { 18 | private readonly IUnitOfWork _unitOfWork; 19 | private readonly ILogger _logger; 20 | private readonly IMapper _mapper; 21 | 22 | public CountryController(IUnitOfWork unitOfWork, ILogger logger, 23 | IMapper mapper) 24 | { 25 | _unitOfWork = unitOfWork; 26 | _logger = logger; 27 | _mapper = mapper; 28 | } 29 | 30 | [HttpGet] 31 | // Can be used to override global caching on a particular endpoint at any point. 32 | ////[HttpCacheExpiration(CacheLocation = CacheLocation.Public, MaxAge = 60)] 33 | ////[HttpCacheValidation(MustRevalidate = false)] 34 | [ProducesResponseType(StatusCodes.Status200OK)] 35 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 36 | public async Task GetCountries([FromQuery] RequestParams requestParams) 37 | { 38 | var countries = await _unitOfWork.Countries.GetPagedList(requestParams); 39 | var results = _mapper.Map>(countries); 40 | return Ok(results); 41 | } 42 | 43 | [HttpGet("{id:int}", Name = "GetCountry")] 44 | [ResponseCache(CacheProfileName = "120SecondsDuration")] 45 | [ProducesResponseType(StatusCodes.Status200OK)] 46 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 47 | public async Task GetCountry(int id) 48 | { 49 | var country = await _unitOfWork.Countries.Get(q => q.Id == id, new List { "Hotels" }); 50 | var result = _mapper.Map(country); 51 | return Ok(result); 52 | } 53 | 54 | [Authorize(Roles = "Administrator")] 55 | [HttpPost] 56 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 57 | [ProducesResponseType(StatusCodes.Status201Created)] 58 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 59 | public async Task CreateCountry([FromBody] CreateCountryDTO countryDTO) 60 | { 61 | if (!ModelState.IsValid) 62 | { 63 | _logger.LogError($"Invalid POST attempt in {nameof(CreateCountry)}"); 64 | return BadRequest(ModelState); 65 | } 66 | 67 | var country = _mapper.Map(countryDTO); 68 | await _unitOfWork.Countries.Insert(country); 69 | await _unitOfWork.Save(); 70 | 71 | return CreatedAtRoute("GetCountry", new { id = country.Id }, country); 72 | 73 | } 74 | 75 | [Authorize] 76 | [HttpPut("{id:int}")] 77 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 78 | [ProducesResponseType(StatusCodes.Status204NoContent)] 79 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 80 | public async Task UpdateCountry(int id, [FromBody] UpdateCountryDTO countryDTO) 81 | { 82 | if (!ModelState.IsValid || id < 1) 83 | { 84 | _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCountry)}"); 85 | return BadRequest(ModelState); 86 | } 87 | 88 | var country = await _unitOfWork.Countries.Get(q => q.Id == id); 89 | if (country == null) 90 | { 91 | _logger.LogError($"Invalid UPDATE attempt in {nameof(UpdateCountry)}"); 92 | return BadRequest("Submitted data is invalid"); 93 | } 94 | 95 | _mapper.Map(countryDTO, country); 96 | _unitOfWork.Countries.Update(country); 97 | await _unitOfWork.Save(); 98 | 99 | return NoContent(); 100 | 101 | } 102 | 103 | [Authorize] 104 | [HttpDelete("{id:int}")] 105 | [ProducesResponseType(StatusCodes.Status400BadRequest)] 106 | [ProducesResponseType(StatusCodes.Status204NoContent)] 107 | [ProducesResponseType(StatusCodes.Status500InternalServerError)] 108 | public async Task DeleteCountry(int id) 109 | { 110 | if (id < 1) 111 | { 112 | _logger.LogError($"Invalid DELETE attempt in {nameof(DeleteCountry)}"); 113 | return BadRequest(); 114 | } 115 | 116 | var country = await _unitOfWork.Countries.Get(q => q.Id == id); 117 | if (country == null) 118 | { 119 | _logger.LogError($"Invalid DELETE attempt in {nameof(DeleteCountry)}"); 120 | return BadRequest("Submitted data is invalid"); 121 | } 122 | 123 | await _unitOfWork.Countries.Delete(id); 124 | await _unitOfWork.Save(); 125 | 126 | return NoContent(); 127 | 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | [Aa][Rr][Mm]/ 24 | [Aa][Rr][Mm]64/ 25 | bld/ 26 | [Bb]in/ 27 | [Oo]bj/ 28 | [Ll]og/ 29 | 30 | # Visual Studio 2015/2017 cache/options directory 31 | .vs/ 32 | # Uncomment if you have tasks that create the project's static files in wwwroot 33 | #wwwroot/ 34 | 35 | # Visual Studio 2017 auto generated files 36 | Generated\ Files/ 37 | 38 | # MSTest test Results 39 | [Tt]est[Rr]esult*/ 40 | [Bb]uild[Ll]og.* 41 | 42 | # NUNIT 43 | *.VisualState.xml 44 | TestResult.xml 45 | 46 | # Build Results of an ATL Project 47 | [Dd]ebugPS/ 48 | [Rr]eleasePS/ 49 | dlldata.c 50 | 51 | # Benchmark Results 52 | BenchmarkDotNet.Artifacts/ 53 | 54 | # .NET Core 55 | project.lock.json 56 | project.fragment.lock.json 57 | artifacts/ 58 | 59 | # StyleCop 60 | StyleCopReport.xml 61 | 62 | # Files built by Visual Studio 63 | *_i.c 64 | *_p.c 65 | *_h.h 66 | *.ilk 67 | *.meta 68 | *.obj 69 | *.iobj 70 | *.pch 71 | *.pdb 72 | *.ipdb 73 | *.pgc 74 | *.pgd 75 | *.rsp 76 | *.sbr 77 | *.tlb 78 | *.tli 79 | *.tlh 80 | *.tmp 81 | *.tmp_proj 82 | *_wpftmp.csproj 83 | *.log 84 | *.vspscc 85 | *.vssscc 86 | .builds 87 | *.pidb 88 | *.svclog 89 | *.scc 90 | 91 | # Chutzpah Test files 92 | _Chutzpah* 93 | 94 | # Visual C++ cache files 95 | ipch/ 96 | *.aps 97 | *.ncb 98 | *.opendb 99 | *.opensdf 100 | *.sdf 101 | *.cachefile 102 | *.VC.db 103 | *.VC.VC.opendb 104 | 105 | # Visual Studio profiler 106 | *.psess 107 | *.vsp 108 | *.vspx 109 | *.sap 110 | 111 | # Visual Studio Trace Files 112 | *.e2e 113 | 114 | # TFS 2012 Local Workspace 115 | $tf/ 116 | 117 | # Guidance Automation Toolkit 118 | *.gpState 119 | 120 | # ReSharper is a .NET coding add-in 121 | _ReSharper*/ 122 | *.[Rr]e[Ss]harper 123 | *.DotSettings.user 124 | 125 | # JustCode is a .NET coding add-in 126 | .JustCode 127 | 128 | # TeamCity is a build add-in 129 | _TeamCity* 130 | 131 | # DotCover is a Code Coverage Tool 132 | *.dotCover 133 | 134 | # AxoCover is a Code Coverage Tool 135 | .axoCover/* 136 | !.axoCover/settings.json 137 | 138 | # Visual Studio code coverage results 139 | *.coverage 140 | *.coveragexml 141 | 142 | # NCrunch 143 | _NCrunch_* 144 | .*crunch*.local.xml 145 | nCrunchTemp_* 146 | 147 | # MightyMoose 148 | *.mm.* 149 | AutoTest.Net/ 150 | 151 | # Web workbench (sass) 152 | .sass-cache/ 153 | 154 | # Installshield output folder 155 | [Ee]xpress/ 156 | 157 | # DocProject is a documentation generator add-in 158 | DocProject/buildhelp/ 159 | DocProject/Help/*.HxT 160 | DocProject/Help/*.HxC 161 | DocProject/Help/*.hhc 162 | DocProject/Help/*.hhk 163 | DocProject/Help/*.hhp 164 | DocProject/Help/Html2 165 | DocProject/Help/html 166 | 167 | # Click-Once directory 168 | publish/ 169 | 170 | # Publish Web Output 171 | *.[Pp]ublish.xml 172 | *.azurePubxml 173 | # Note: Comment the next line if you want to checkin your web deploy settings, 174 | # but database connection strings (with potential passwords) will be unencrypted 175 | *.pubxml 176 | *.publishproj 177 | 178 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 179 | # checkin your Azure Web App publish settings, but sensitive information contained 180 | # in these scripts will be unencrypted 181 | PublishScripts/ 182 | 183 | # NuGet Packages 184 | *.nupkg 185 | # The packages folder can be ignored because of Package Restore 186 | **/[Pp]ackages/* 187 | # except build/, which is used as an MSBuild target. 188 | !**/[Pp]ackages/build/ 189 | # Uncomment if necessary however generally it will be regenerated when needed 190 | #!**/[Pp]ackages/repositories.config 191 | # NuGet v3's project.json files produces more ignorable files 192 | *.nuget.props 193 | *.nuget.targets 194 | 195 | # Microsoft Azure Build Output 196 | csx/ 197 | *.build.csdef 198 | 199 | # Microsoft Azure Emulator 200 | ecf/ 201 | rcf/ 202 | 203 | # Windows Store app package directories and files 204 | AppPackages/ 205 | BundleArtifacts/ 206 | Package.StoreAssociation.xml 207 | _pkginfo.txt 208 | *.appx 209 | 210 | # Visual Studio cache files 211 | # files ending in .cache can be ignored 212 | *.[Cc]ache 213 | # but keep track of directories ending in .cache 214 | !?*.[Cc]ache/ 215 | 216 | # Others 217 | ClientBin/ 218 | ~$* 219 | *~ 220 | *.dbmdl 221 | *.dbproj.schemaview 222 | *.jfm 223 | *.pfx 224 | *.publishsettings 225 | orleans.codegen.cs 226 | 227 | # Including strong name files can present a security risk 228 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 229 | #*.snk 230 | 231 | # Since there are multiple workflows, uncomment next line to ignore bower_components 232 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 233 | #bower_components/ 234 | 235 | # RIA/Silverlight projects 236 | Generated_Code/ 237 | 238 | # Backup & report files from converting an old project file 239 | # to a newer Visual Studio version. Backup files are not needed, 240 | # because we have git ;-) 241 | _UpgradeReport_Files/ 242 | Backup*/ 243 | UpgradeLog*.XML 244 | UpgradeLog*.htm 245 | ServiceFabricBackup/ 246 | *.rptproj.bak 247 | 248 | # SQL Server files 249 | *.mdf 250 | *.ldf 251 | *.ndf 252 | 253 | # Business Intelligence projects 254 | *.rdl.data 255 | *.bim.layout 256 | *.bim_*.settings 257 | *.rptproj.rsuser 258 | *- Backup*.rdl 259 | 260 | # Microsoft Fakes 261 | FakesAssemblies/ 262 | 263 | # GhostDoc plugin setting file 264 | *.GhostDoc.xml 265 | 266 | # Node.js Tools for Visual Studio 267 | .ntvs_analysis.dat 268 | node_modules/ 269 | 270 | # Visual Studio 6 build log 271 | *.plg 272 | 273 | # Visual Studio 6 workspace options file 274 | *.opt 275 | 276 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 277 | *.vbw 278 | 279 | # Visual Studio LightSwitch build output 280 | **/*.HTMLClient/GeneratedArtifacts 281 | **/*.DesktopClient/GeneratedArtifacts 282 | **/*.DesktopClient/ModelManifest.xml 283 | **/*.Server/GeneratedArtifacts 284 | **/*.Server/ModelManifest.xml 285 | _Pvt_Extensions 286 | 287 | # Paket dependency manager 288 | .paket/paket.exe 289 | paket-files/ 290 | 291 | # FAKE - F# Make 292 | .fake/ 293 | 294 | # JetBrains Rider 295 | .idea/ 296 | *.sln.iml 297 | 298 | # CodeRush personal settings 299 | .cr/personal 300 | 301 | # Python Tools for Visual Studio (PTVS) 302 | __pycache__/ 303 | *.pyc 304 | 305 | # Cake - Uncomment if you are using it 306 | # tools/** 307 | # !tools/packages.config 308 | 309 | # Tabs Studio 310 | *.tss 311 | 312 | # Telerik's JustMock configuration file 313 | *.jmconfig 314 | 315 | # BizTalk build output 316 | *.btp.cs 317 | *.btm.cs 318 | *.odx.cs 319 | *.xsd.cs 320 | 321 | # OpenCover UI analysis results 322 | OpenCover/ 323 | 324 | # Azure Stream Analytics local run output 325 | ASALocalRun/ 326 | 327 | # MSBuild Binary and Structured Log 328 | *.binlog 329 | 330 | # NVidia Nsight GPU debugger configuration file 331 | *.nvuser 332 | 333 | # MFractors (Xamarin productivity tool) working folder 334 | .mfractor/ 335 | 336 | # Local History for Visual Studio 337 | .localhistory/ 338 | 339 | # BeatPulse healthcheck temp database 340 | healthchecksdb -------------------------------------------------------------------------------- /HotelListing/logs/log-20210524.txt: -------------------------------------------------------------------------------- 1 | 2021-05-24 19:43:02.531 +05:30 [INF] Application Is Starting 2 | 2021-05-24 19:43:54.254 +05:30 [INF] Application Is Starting 3 | 2021-05-24 19:44:38.101 +05:30 [INF] User profile is available. Using 'C:\Users\admin\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest. 4 | 2021-05-24 19:44:54.783 +05:30 [INF] Now listening on: https://localhost:5001 5 | 2021-05-24 19:44:54.783 +05:30 [INF] Now listening on: http://localhost:5000 6 | 2021-05-24 19:44:54.783 +05:30 [INF] Application started. Press Ctrl+C to shut down. 7 | 2021-05-24 19:44:54.783 +05:30 [INF] Hosting environment: Development 8 | 2021-05-24 19:44:54.783 +05:30 [INF] Content root path: E:\Source\Repos\HotelListing-API-dotnet5-master\HotelListing 9 | 2021-05-24 19:44:55.400 +05:30 [INF] Request starting HTTP/2 GET https://localhost:5001/swagger/index.html - - 10 | 2021-05-24 19:44:55.547 +05:30 [INF] Request finished HTTP/2 GET https://localhost:5001/swagger/index.html - - - 200 - text/html;charset=utf-8 148.1943ms 11 | 2021-05-24 19:44:56.064 +05:30 [INF] Request starting HTTP/2 GET https://localhost:5001/swagger/v1/swagger.json - - 12 | 2021-05-24 19:44:56.156 +05:30 [INF] Request finished HTTP/2 GET https://localhost:5001/swagger/v1/swagger.json - - - 200 - application/json;charset=utf-8 91.9359ms 13 | 2021-05-24 19:45:19.807 +05:30 [INF] Request starting HTTP/2 GET https://localhost:5001/api/Country - - 14 | 2021-05-24 19:45:19.816 +05:30 [INF] No cached response available for this request. 15 | 2021-05-24 19:45:21.771 +05:30 [INF] Checking for conditional GET/HEAD. 16 | 2021-05-24 19:45:21.776 +05:30 [INF] Not valid - no If-None-Match or If-Modified-Since headers. 17 | 2021-05-24 19:45:21.776 +05:30 [INF] Don't generate 304 - Not Modified. Continue. 18 | 2021-05-24 19:45:21.778 +05:30 [INF] Checking for conditional PUT/PATCH. 19 | 2021-05-24 19:45:21.778 +05:30 [INF] Not valid - method isn't PUT or PATCH. 20 | 2021-05-24 19:45:21.778 +05:30 [INF] Don't generate 412 - Precondition Failed. Continue. 21 | 2021-05-24 19:45:22.236 +05:30 [ERR] An unhandled exception has occurred while executing the request. 22 | System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') 23 | at System.Text.Encoding.GetBytes(String s) 24 | at System.Text.UTF8Encoding.UTF8EncodingSealed.GetBytes(String s) 25 | at HotelListing.ServiceExtensions.<>c__DisplayClass1_0.b__1(JwtBearerOptions o) in E:\Source\Repos\HotelListing-API-dotnet5-master\HotelListing\Services\ServiceExtensions.cs:line 46 26 | at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options) 27 | at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name) 28 | at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.b__0() 29 | at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) 30 | at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) 31 | at System.Lazy`1.CreateValue() 32 | at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name) 33 | at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context) 34 | at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme) 35 | at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme) 36 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) 37 | at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) 38 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.HandleResponse(HttpContext httpContext) 39 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator) 40 | at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext) 41 | at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) 42 | 2021-05-24 19:45:25.275 +05:30 [ERR] Something Went Wrong in the System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') 43 | at System.Text.Encoding.GetBytes(String s) 44 | at System.Text.UTF8Encoding.UTF8EncodingSealed.GetBytes(String s) 45 | at HotelListing.ServiceExtensions.<>c__DisplayClass1_0.b__1(JwtBearerOptions o) in E:\Source\Repos\HotelListing-API-dotnet5-master\HotelListing\Services\ServiceExtensions.cs:line 46 46 | at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options) 47 | at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name) 48 | at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.b__0() 49 | at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) 50 | at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) 51 | at System.Lazy`1.CreateValue() 52 | at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name) 53 | at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context) 54 | at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme) 55 | at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme) 56 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) 57 | at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) 58 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.HandleResponse(HttpContext httpContext) 59 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator) 60 | at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext) 61 | at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) 62 | 2021-05-24 19:45:25.436 +05:30 [INF] Request finished HTTP/2 GET https://localhost:5001/api/Country - - - 500 - application/json 5629.2245ms 63 | 2021-05-24 19:45:56.596 +05:30 [INF] Request starting HTTP/2 GET https://localhost:5001/api/country - - 64 | 2021-05-24 19:45:56.597 +05:30 [INF] No cached response available for this request. 65 | 2021-05-24 19:45:56.599 +05:30 [INF] Checking for conditional GET/HEAD. 66 | 2021-05-24 19:45:56.599 +05:30 [INF] Not valid - no If-None-Match or If-Modified-Since headers. 67 | 2021-05-24 19:45:56.599 +05:30 [INF] Don't generate 304 - Not Modified. Continue. 68 | 2021-05-24 19:45:56.599 +05:30 [INF] Checking for conditional PUT/PATCH. 69 | 2021-05-24 19:45:56.599 +05:30 [INF] Not valid - method isn't PUT or PATCH. 70 | 2021-05-24 19:45:56.600 +05:30 [INF] Don't generate 412 - Precondition Failed. Continue. 71 | 2021-05-24 19:45:56.740 +05:30 [ERR] An unhandled exception has occurred while executing the request. 72 | System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') 73 | at System.Text.Encoding.GetBytes(String s) 74 | at System.Text.UTF8Encoding.UTF8EncodingSealed.GetBytes(String s) 75 | at HotelListing.ServiceExtensions.<>c__DisplayClass1_0.b__1(JwtBearerOptions o) in E:\Source\Repos\HotelListing-API-dotnet5-master\HotelListing\Services\ServiceExtensions.cs:line 46 76 | at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options) 77 | at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name) 78 | at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.b__0() 79 | at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) 80 | --- End of stack trace from previous location --- 81 | at System.Lazy`1.CreateValue() 82 | at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name) 83 | at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context) 84 | at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme) 85 | at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme) 86 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) 87 | at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) 88 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.HandleResponse(HttpContext httpContext) 89 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator) 90 | at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext) 91 | at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) 92 | 2021-05-24 19:45:56.741 +05:30 [ERR] Something Went Wrong in the System.ArgumentNullException: String reference not set to an instance of a String. (Parameter 's') 93 | at System.Text.Encoding.GetBytes(String s) 94 | at System.Text.UTF8Encoding.UTF8EncodingSealed.GetBytes(String s) 95 | at HotelListing.ServiceExtensions.<>c__DisplayClass1_0.b__1(JwtBearerOptions o) in E:\Source\Repos\HotelListing-API-dotnet5-master\HotelListing\Services\ServiceExtensions.cs:line 46 96 | at Microsoft.Extensions.Options.ConfigureNamedOptions`1.Configure(String name, TOptions options) 97 | at Microsoft.Extensions.Options.OptionsFactory`1.Create(String name) 98 | at Microsoft.Extensions.Options.OptionsMonitor`1.<>c__DisplayClass11_0.b__0() 99 | at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode) 100 | --- End of stack trace from previous location --- 101 | at System.Lazy`1.CreateValue() 102 | at Microsoft.Extensions.Options.OptionsMonitor`1.Get(String name) 103 | at Microsoft.AspNetCore.Authentication.AuthenticationHandler`1.InitializeAsync(AuthenticationScheme scheme, HttpContext context) 104 | at Microsoft.AspNetCore.Authentication.AuthenticationHandlerProvider.GetHandlerAsync(HttpContext context, String authenticationScheme) 105 | at Microsoft.AspNetCore.Authentication.AuthenticationService.AuthenticateAsync(HttpContext context, String scheme) 106 | at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) 107 | at AspNetCoreRateLimit.RateLimitMiddleware`1.Invoke(HttpContext context) 108 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.HandleResponse(HttpContext httpContext) 109 | at Marvin.Cache.Headers.HttpCacheHeadersMiddleware.Invoke(HttpContext httpContext, IValidatorValueInvalidator validatorValueInvalidator) 110 | at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext) 111 | at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task) 112 | 2021-05-24 19:45:56.742 +05:30 [INF] Request finished HTTP/2 GET https://localhost:5001/api/country - - - 500 - application/json 146.1760ms 113 | -------------------------------------------------------------------------------- /HotelListing/Migrations/20210524131541_init.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | using System; 3 | 4 | namespace HotelListing.Migrations 5 | { 6 | public partial class init : Migration 7 | { 8 | protected override void Up(MigrationBuilder migrationBuilder) 9 | { 10 | migrationBuilder.CreateTable( 11 | name: "AspNetRoles", 12 | columns: table => new 13 | { 14 | Id = table.Column(type: "nvarchar(450)", nullable: false), 15 | Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 16 | NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 17 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) 18 | }, 19 | constraints: table => 20 | { 21 | table.PrimaryKey("PK_AspNetRoles", x => x.Id); 22 | }); 23 | 24 | migrationBuilder.CreateTable( 25 | name: "AspNetUsers", 26 | columns: table => new 27 | { 28 | Id = table.Column(type: "nvarchar(450)", nullable: false), 29 | FirstName = table.Column(type: "nvarchar(max)", nullable: true), 30 | LastName = table.Column(type: "nvarchar(max)", nullable: true), 31 | UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 32 | NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 33 | Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 34 | NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), 35 | EmailConfirmed = table.Column(type: "bit", nullable: false), 36 | PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), 37 | SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), 38 | ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), 39 | PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), 40 | PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), 41 | TwoFactorEnabled = table.Column(type: "bit", nullable: false), 42 | LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), 43 | LockoutEnabled = table.Column(type: "bit", nullable: false), 44 | AccessFailedCount = table.Column(type: "int", nullable: false) 45 | }, 46 | constraints: table => 47 | { 48 | table.PrimaryKey("PK_AspNetUsers", x => x.Id); 49 | }); 50 | 51 | migrationBuilder.CreateTable( 52 | name: "Countries", 53 | columns: table => new 54 | { 55 | Id = table.Column(type: "int", nullable: false) 56 | .Annotation("SqlServer:Identity", "1, 1"), 57 | Name = table.Column(type: "nvarchar(max)", nullable: true), 58 | ShortName = table.Column(type: "nvarchar(max)", nullable: true) 59 | }, 60 | constraints: table => 61 | { 62 | table.PrimaryKey("PK_Countries", x => x.Id); 63 | }); 64 | 65 | migrationBuilder.CreateTable( 66 | name: "AspNetRoleClaims", 67 | columns: table => new 68 | { 69 | Id = table.Column(type: "int", nullable: false) 70 | .Annotation("SqlServer:Identity", "1, 1"), 71 | RoleId = table.Column(type: "nvarchar(450)", nullable: false), 72 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 73 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 74 | }, 75 | constraints: table => 76 | { 77 | table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); 78 | table.ForeignKey( 79 | name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", 80 | column: x => x.RoleId, 81 | principalTable: "AspNetRoles", 82 | principalColumn: "Id", 83 | onDelete: ReferentialAction.Cascade); 84 | }); 85 | 86 | migrationBuilder.CreateTable( 87 | name: "AspNetUserClaims", 88 | columns: table => new 89 | { 90 | Id = table.Column(type: "int", nullable: false) 91 | .Annotation("SqlServer:Identity", "1, 1"), 92 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 93 | ClaimType = table.Column(type: "nvarchar(max)", nullable: true), 94 | ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) 95 | }, 96 | constraints: table => 97 | { 98 | table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); 99 | table.ForeignKey( 100 | name: "FK_AspNetUserClaims_AspNetUsers_UserId", 101 | column: x => x.UserId, 102 | principalTable: "AspNetUsers", 103 | principalColumn: "Id", 104 | onDelete: ReferentialAction.Cascade); 105 | }); 106 | 107 | migrationBuilder.CreateTable( 108 | name: "AspNetUserLogins", 109 | columns: table => new 110 | { 111 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 112 | ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), 113 | ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), 114 | UserId = table.Column(type: "nvarchar(450)", nullable: false) 115 | }, 116 | constraints: table => 117 | { 118 | table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); 119 | table.ForeignKey( 120 | name: "FK_AspNetUserLogins_AspNetUsers_UserId", 121 | column: x => x.UserId, 122 | principalTable: "AspNetUsers", 123 | principalColumn: "Id", 124 | onDelete: ReferentialAction.Cascade); 125 | }); 126 | 127 | migrationBuilder.CreateTable( 128 | name: "AspNetUserRoles", 129 | columns: table => new 130 | { 131 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 132 | RoleId = table.Column(type: "nvarchar(450)", nullable: false) 133 | }, 134 | constraints: table => 135 | { 136 | table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); 137 | table.ForeignKey( 138 | name: "FK_AspNetUserRoles_AspNetRoles_RoleId", 139 | column: x => x.RoleId, 140 | principalTable: "AspNetRoles", 141 | principalColumn: "Id", 142 | onDelete: ReferentialAction.Cascade); 143 | table.ForeignKey( 144 | name: "FK_AspNetUserRoles_AspNetUsers_UserId", 145 | column: x => x.UserId, 146 | principalTable: "AspNetUsers", 147 | principalColumn: "Id", 148 | onDelete: ReferentialAction.Cascade); 149 | }); 150 | 151 | migrationBuilder.CreateTable( 152 | name: "AspNetUserTokens", 153 | columns: table => new 154 | { 155 | UserId = table.Column(type: "nvarchar(450)", nullable: false), 156 | LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), 157 | Name = table.Column(type: "nvarchar(450)", nullable: false), 158 | Value = table.Column(type: "nvarchar(max)", nullable: true) 159 | }, 160 | constraints: table => 161 | { 162 | table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); 163 | table.ForeignKey( 164 | name: "FK_AspNetUserTokens_AspNetUsers_UserId", 165 | column: x => x.UserId, 166 | principalTable: "AspNetUsers", 167 | principalColumn: "Id", 168 | onDelete: ReferentialAction.Cascade); 169 | }); 170 | 171 | migrationBuilder.CreateTable( 172 | name: "Hotels", 173 | columns: table => new 174 | { 175 | Id = table.Column(type: "int", nullable: false) 176 | .Annotation("SqlServer:Identity", "1, 1"), 177 | Name = table.Column(type: "nvarchar(max)", nullable: true), 178 | Address = table.Column(type: "nvarchar(max)", nullable: true), 179 | Rating = table.Column(type: "float", nullable: false), 180 | CountryId = table.Column(type: "int", nullable: false) 181 | }, 182 | constraints: table => 183 | { 184 | table.PrimaryKey("PK_Hotels", x => x.Id); 185 | table.ForeignKey( 186 | name: "FK_Hotels_Countries_CountryId", 187 | column: x => x.CountryId, 188 | principalTable: "Countries", 189 | principalColumn: "Id", 190 | onDelete: ReferentialAction.Cascade); 191 | }); 192 | 193 | migrationBuilder.InsertData( 194 | table: "AspNetRoles", 195 | columns: new[] { "Id", "ConcurrencyStamp", "Name", "NormalizedName" }, 196 | values: new object[,] 197 | { 198 | { "22c7bc03-704d-43e9-9cd6-2d7d80c7fac0", "7f365b4e-2d91-4488-895f-a6c923f10a26", "User", "USER" }, 199 | { "93b1c95b-c9ed-4085-a784-a18dadccf7f7", "5d248937-c3f9-42e2-be31-a963508681a9", "Administrator", "ADMINISTRATOR" } 200 | }); 201 | 202 | migrationBuilder.InsertData( 203 | table: "Countries", 204 | columns: new[] { "Id", "Name", "ShortName" }, 205 | values: new object[,] 206 | { 207 | { 1, "Jamaica", "JM" }, 208 | { 2, "Bahamas", "BS" }, 209 | { 3, "Cayman Island", "CI" } 210 | }); 211 | 212 | migrationBuilder.InsertData( 213 | table: "Hotels", 214 | columns: new[] { "Id", "Address", "CountryId", "Name", "Rating" }, 215 | values: new object[] { 1, "Negril", 1, "Sandals Resort and Spa", 4.5 }); 216 | 217 | migrationBuilder.InsertData( 218 | table: "Hotels", 219 | columns: new[] { "Id", "Address", "CountryId", "Name", "Rating" }, 220 | values: new object[] { 3, "Nassua", 2, "Grand Palldium", 4.0 }); 221 | 222 | migrationBuilder.InsertData( 223 | table: "Hotels", 224 | columns: new[] { "Id", "Address", "CountryId", "Name", "Rating" }, 225 | values: new object[] { 2, "George Town", 3, "Comfort Suites", 4.2999999999999998 }); 226 | 227 | migrationBuilder.CreateIndex( 228 | name: "IX_AspNetRoleClaims_RoleId", 229 | table: "AspNetRoleClaims", 230 | column: "RoleId"); 231 | 232 | migrationBuilder.CreateIndex( 233 | name: "RoleNameIndex", 234 | table: "AspNetRoles", 235 | column: "NormalizedName", 236 | unique: true, 237 | filter: "[NormalizedName] IS NOT NULL"); 238 | 239 | migrationBuilder.CreateIndex( 240 | name: "IX_AspNetUserClaims_UserId", 241 | table: "AspNetUserClaims", 242 | column: "UserId"); 243 | 244 | migrationBuilder.CreateIndex( 245 | name: "IX_AspNetUserLogins_UserId", 246 | table: "AspNetUserLogins", 247 | column: "UserId"); 248 | 249 | migrationBuilder.CreateIndex( 250 | name: "IX_AspNetUserRoles_RoleId", 251 | table: "AspNetUserRoles", 252 | column: "RoleId"); 253 | 254 | migrationBuilder.CreateIndex( 255 | name: "EmailIndex", 256 | table: "AspNetUsers", 257 | column: "NormalizedEmail"); 258 | 259 | migrationBuilder.CreateIndex( 260 | name: "UserNameIndex", 261 | table: "AspNetUsers", 262 | column: "NormalizedUserName", 263 | unique: true, 264 | filter: "[NormalizedUserName] IS NOT NULL"); 265 | 266 | migrationBuilder.CreateIndex( 267 | name: "IX_Hotels_CountryId", 268 | table: "Hotels", 269 | column: "CountryId"); 270 | } 271 | 272 | protected override void Down(MigrationBuilder migrationBuilder) 273 | { 274 | migrationBuilder.DropTable( 275 | name: "AspNetRoleClaims"); 276 | 277 | migrationBuilder.DropTable( 278 | name: "AspNetUserClaims"); 279 | 280 | migrationBuilder.DropTable( 281 | name: "AspNetUserLogins"); 282 | 283 | migrationBuilder.DropTable( 284 | name: "AspNetUserRoles"); 285 | 286 | migrationBuilder.DropTable( 287 | name: "AspNetUserTokens"); 288 | 289 | migrationBuilder.DropTable( 290 | name: "Hotels"); 291 | 292 | migrationBuilder.DropTable( 293 | name: "AspNetRoles"); 294 | 295 | migrationBuilder.DropTable( 296 | name: "AspNetUsers"); 297 | 298 | migrationBuilder.DropTable( 299 | name: "Countries"); 300 | } 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /HotelListing/Migrations/DatabaseContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using HotelListing.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | namespace HotelListing.Migrations 10 | { 11 | [DbContext(typeof(DatabaseContext))] 12 | partial class DatabaseContextModelSnapshot : ModelSnapshot 13 | { 14 | protected override void BuildModel(ModelBuilder modelBuilder) 15 | { 16 | #pragma warning disable 612, 618 17 | modelBuilder 18 | .UseIdentityColumns() 19 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 20 | .HasAnnotation("ProductVersion", "5.0.2"); 21 | 22 | modelBuilder.Entity("HotelListing.Data.ApiUser", b => 23 | { 24 | b.Property("Id") 25 | .HasColumnType("nvarchar(450)"); 26 | 27 | b.Property("AccessFailedCount") 28 | .HasColumnType("int"); 29 | 30 | b.Property("ConcurrencyStamp") 31 | .IsConcurrencyToken() 32 | .HasColumnType("nvarchar(max)"); 33 | 34 | b.Property("Email") 35 | .HasMaxLength(256) 36 | .HasColumnType("nvarchar(256)"); 37 | 38 | b.Property("EmailConfirmed") 39 | .HasColumnType("bit"); 40 | 41 | b.Property("FirstName") 42 | .HasColumnType("nvarchar(max)"); 43 | 44 | b.Property("LastName") 45 | .HasColumnType("nvarchar(max)"); 46 | 47 | b.Property("LockoutEnabled") 48 | .HasColumnType("bit"); 49 | 50 | b.Property("LockoutEnd") 51 | .HasColumnType("datetimeoffset"); 52 | 53 | b.Property("NormalizedEmail") 54 | .HasMaxLength(256) 55 | .HasColumnType("nvarchar(256)"); 56 | 57 | b.Property("NormalizedUserName") 58 | .HasMaxLength(256) 59 | .HasColumnType("nvarchar(256)"); 60 | 61 | b.Property("PasswordHash") 62 | .HasColumnType("nvarchar(max)"); 63 | 64 | b.Property("PhoneNumber") 65 | .HasColumnType("nvarchar(max)"); 66 | 67 | b.Property("PhoneNumberConfirmed") 68 | .HasColumnType("bit"); 69 | 70 | b.Property("SecurityStamp") 71 | .HasColumnType("nvarchar(max)"); 72 | 73 | b.Property("TwoFactorEnabled") 74 | .HasColumnType("bit"); 75 | 76 | b.Property("UserName") 77 | .HasMaxLength(256) 78 | .HasColumnType("nvarchar(256)"); 79 | 80 | b.HasKey("Id"); 81 | 82 | b.HasIndex("NormalizedEmail") 83 | .HasDatabaseName("EmailIndex"); 84 | 85 | b.HasIndex("NormalizedUserName") 86 | .IsUnique() 87 | .HasDatabaseName("UserNameIndex") 88 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 89 | 90 | b.ToTable("AspNetUsers"); 91 | }); 92 | 93 | modelBuilder.Entity("HotelListing.Data.Country", b => 94 | { 95 | b.Property("Id") 96 | .ValueGeneratedOnAdd() 97 | .HasColumnType("int") 98 | .UseIdentityColumn(); 99 | 100 | b.Property("Name") 101 | .HasColumnType("nvarchar(max)"); 102 | 103 | b.Property("ShortName") 104 | .HasColumnType("nvarchar(max)"); 105 | 106 | b.HasKey("Id"); 107 | 108 | b.ToTable("Countries"); 109 | 110 | b.HasData( 111 | new 112 | { 113 | Id = 1, 114 | Name = "Jamaica", 115 | ShortName = "JM" 116 | }, 117 | new 118 | { 119 | Id = 2, 120 | Name = "Bahamas", 121 | ShortName = "BS" 122 | }, 123 | new 124 | { 125 | Id = 3, 126 | Name = "Cayman Island", 127 | ShortName = "CI" 128 | }); 129 | }); 130 | 131 | modelBuilder.Entity("HotelListing.Data.Hotel", b => 132 | { 133 | b.Property("Id") 134 | .ValueGeneratedOnAdd() 135 | .HasColumnType("int") 136 | .UseIdentityColumn(); 137 | 138 | b.Property("Address") 139 | .HasColumnType("nvarchar(max)"); 140 | 141 | b.Property("CountryId") 142 | .HasColumnType("int"); 143 | 144 | b.Property("Name") 145 | .HasColumnType("nvarchar(max)"); 146 | 147 | b.Property("Rating") 148 | .HasColumnType("float"); 149 | 150 | b.HasKey("Id"); 151 | 152 | b.HasIndex("CountryId"); 153 | 154 | b.ToTable("Hotels"); 155 | 156 | b.HasData( 157 | new 158 | { 159 | Id = 1, 160 | Address = "Negril", 161 | CountryId = 1, 162 | Name = "Sandals Resort and Spa", 163 | Rating = 4.5 164 | }, 165 | new 166 | { 167 | Id = 2, 168 | Address = "George Town", 169 | CountryId = 3, 170 | Name = "Comfort Suites", 171 | Rating = 4.2999999999999998 172 | }, 173 | new 174 | { 175 | Id = 3, 176 | Address = "Nassua", 177 | CountryId = 2, 178 | Name = "Grand Palldium", 179 | Rating = 4.0 180 | }); 181 | }); 182 | 183 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 184 | { 185 | b.Property("Id") 186 | .HasColumnType("nvarchar(450)"); 187 | 188 | b.Property("ConcurrencyStamp") 189 | .IsConcurrencyToken() 190 | .HasColumnType("nvarchar(max)"); 191 | 192 | b.Property("Name") 193 | .HasMaxLength(256) 194 | .HasColumnType("nvarchar(256)"); 195 | 196 | b.Property("NormalizedName") 197 | .HasMaxLength(256) 198 | .HasColumnType("nvarchar(256)"); 199 | 200 | b.HasKey("Id"); 201 | 202 | b.HasIndex("NormalizedName") 203 | .IsUnique() 204 | .HasDatabaseName("RoleNameIndex") 205 | .HasFilter("[NormalizedName] IS NOT NULL"); 206 | 207 | b.ToTable("AspNetRoles"); 208 | 209 | b.HasData( 210 | new 211 | { 212 | Id = "22c7bc03-704d-43e9-9cd6-2d7d80c7fac0", 213 | ConcurrencyStamp = "7f365b4e-2d91-4488-895f-a6c923f10a26", 214 | Name = "User", 215 | NormalizedName = "USER" 216 | }, 217 | new 218 | { 219 | Id = "93b1c95b-c9ed-4085-a784-a18dadccf7f7", 220 | ConcurrencyStamp = "5d248937-c3f9-42e2-be31-a963508681a9", 221 | Name = "Administrator", 222 | NormalizedName = "ADMINISTRATOR" 223 | }); 224 | }); 225 | 226 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 227 | { 228 | b.Property("Id") 229 | .ValueGeneratedOnAdd() 230 | .HasColumnType("int") 231 | .UseIdentityColumn(); 232 | 233 | b.Property("ClaimType") 234 | .HasColumnType("nvarchar(max)"); 235 | 236 | b.Property("ClaimValue") 237 | .HasColumnType("nvarchar(max)"); 238 | 239 | b.Property("RoleId") 240 | .IsRequired() 241 | .HasColumnType("nvarchar(450)"); 242 | 243 | b.HasKey("Id"); 244 | 245 | b.HasIndex("RoleId"); 246 | 247 | b.ToTable("AspNetRoleClaims"); 248 | }); 249 | 250 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 251 | { 252 | b.Property("Id") 253 | .ValueGeneratedOnAdd() 254 | .HasColumnType("int") 255 | .UseIdentityColumn(); 256 | 257 | b.Property("ClaimType") 258 | .HasColumnType("nvarchar(max)"); 259 | 260 | b.Property("ClaimValue") 261 | .HasColumnType("nvarchar(max)"); 262 | 263 | b.Property("UserId") 264 | .IsRequired() 265 | .HasColumnType("nvarchar(450)"); 266 | 267 | b.HasKey("Id"); 268 | 269 | b.HasIndex("UserId"); 270 | 271 | b.ToTable("AspNetUserClaims"); 272 | }); 273 | 274 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 275 | { 276 | b.Property("LoginProvider") 277 | .HasColumnType("nvarchar(450)"); 278 | 279 | b.Property("ProviderKey") 280 | .HasColumnType("nvarchar(450)"); 281 | 282 | b.Property("ProviderDisplayName") 283 | .HasColumnType("nvarchar(max)"); 284 | 285 | b.Property("UserId") 286 | .IsRequired() 287 | .HasColumnType("nvarchar(450)"); 288 | 289 | b.HasKey("LoginProvider", "ProviderKey"); 290 | 291 | b.HasIndex("UserId"); 292 | 293 | b.ToTable("AspNetUserLogins"); 294 | }); 295 | 296 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 297 | { 298 | b.Property("UserId") 299 | .HasColumnType("nvarchar(450)"); 300 | 301 | b.Property("RoleId") 302 | .HasColumnType("nvarchar(450)"); 303 | 304 | b.HasKey("UserId", "RoleId"); 305 | 306 | b.HasIndex("RoleId"); 307 | 308 | b.ToTable("AspNetUserRoles"); 309 | }); 310 | 311 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 312 | { 313 | b.Property("UserId") 314 | .HasColumnType("nvarchar(450)"); 315 | 316 | b.Property("LoginProvider") 317 | .HasColumnType("nvarchar(450)"); 318 | 319 | b.Property("Name") 320 | .HasColumnType("nvarchar(450)"); 321 | 322 | b.Property("Value") 323 | .HasColumnType("nvarchar(max)"); 324 | 325 | b.HasKey("UserId", "LoginProvider", "Name"); 326 | 327 | b.ToTable("AspNetUserTokens"); 328 | }); 329 | 330 | modelBuilder.Entity("HotelListing.Data.Hotel", b => 331 | { 332 | b.HasOne("HotelListing.Data.Country", "Country") 333 | .WithMany("Hotels") 334 | .HasForeignKey("CountryId") 335 | .OnDelete(DeleteBehavior.Cascade) 336 | .IsRequired(); 337 | 338 | b.Navigation("Country"); 339 | }); 340 | 341 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 342 | { 343 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 344 | .WithMany() 345 | .HasForeignKey("RoleId") 346 | .OnDelete(DeleteBehavior.Cascade) 347 | .IsRequired(); 348 | }); 349 | 350 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 351 | { 352 | b.HasOne("HotelListing.Data.ApiUser", null) 353 | .WithMany() 354 | .HasForeignKey("UserId") 355 | .OnDelete(DeleteBehavior.Cascade) 356 | .IsRequired(); 357 | }); 358 | 359 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 360 | { 361 | b.HasOne("HotelListing.Data.ApiUser", null) 362 | .WithMany() 363 | .HasForeignKey("UserId") 364 | .OnDelete(DeleteBehavior.Cascade) 365 | .IsRequired(); 366 | }); 367 | 368 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 369 | { 370 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 371 | .WithMany() 372 | .HasForeignKey("RoleId") 373 | .OnDelete(DeleteBehavior.Cascade) 374 | .IsRequired(); 375 | 376 | b.HasOne("HotelListing.Data.ApiUser", null) 377 | .WithMany() 378 | .HasForeignKey("UserId") 379 | .OnDelete(DeleteBehavior.Cascade) 380 | .IsRequired(); 381 | }); 382 | 383 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 384 | { 385 | b.HasOne("HotelListing.Data.ApiUser", null) 386 | .WithMany() 387 | .HasForeignKey("UserId") 388 | .OnDelete(DeleteBehavior.Cascade) 389 | .IsRequired(); 390 | }); 391 | 392 | modelBuilder.Entity("HotelListing.Data.Country", b => 393 | { 394 | b.Navigation("Hotels"); 395 | }); 396 | #pragma warning restore 612, 618 397 | } 398 | } 399 | } 400 | -------------------------------------------------------------------------------- /HotelListing/Migrations/20210524131541_init.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using HotelListing.Data; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Metadata; 7 | using Microsoft.EntityFrameworkCore.Migrations; 8 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 9 | 10 | namespace HotelListing.Migrations 11 | { 12 | [DbContext(typeof(DatabaseContext))] 13 | [Migration("20210524131541_init")] 14 | partial class init 15 | { 16 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 17 | { 18 | #pragma warning disable 612, 618 19 | modelBuilder 20 | .UseIdentityColumns() 21 | .HasAnnotation("Relational:MaxIdentifierLength", 128) 22 | .HasAnnotation("ProductVersion", "5.0.2"); 23 | 24 | modelBuilder.Entity("HotelListing.Data.ApiUser", b => 25 | { 26 | b.Property("Id") 27 | .HasColumnType("nvarchar(450)"); 28 | 29 | b.Property("AccessFailedCount") 30 | .HasColumnType("int"); 31 | 32 | b.Property("ConcurrencyStamp") 33 | .IsConcurrencyToken() 34 | .HasColumnType("nvarchar(max)"); 35 | 36 | b.Property("Email") 37 | .HasMaxLength(256) 38 | .HasColumnType("nvarchar(256)"); 39 | 40 | b.Property("EmailConfirmed") 41 | .HasColumnType("bit"); 42 | 43 | b.Property("FirstName") 44 | .HasColumnType("nvarchar(max)"); 45 | 46 | b.Property("LastName") 47 | .HasColumnType("nvarchar(max)"); 48 | 49 | b.Property("LockoutEnabled") 50 | .HasColumnType("bit"); 51 | 52 | b.Property("LockoutEnd") 53 | .HasColumnType("datetimeoffset"); 54 | 55 | b.Property("NormalizedEmail") 56 | .HasMaxLength(256) 57 | .HasColumnType("nvarchar(256)"); 58 | 59 | b.Property("NormalizedUserName") 60 | .HasMaxLength(256) 61 | .HasColumnType("nvarchar(256)"); 62 | 63 | b.Property("PasswordHash") 64 | .HasColumnType("nvarchar(max)"); 65 | 66 | b.Property("PhoneNumber") 67 | .HasColumnType("nvarchar(max)"); 68 | 69 | b.Property("PhoneNumberConfirmed") 70 | .HasColumnType("bit"); 71 | 72 | b.Property("SecurityStamp") 73 | .HasColumnType("nvarchar(max)"); 74 | 75 | b.Property("TwoFactorEnabled") 76 | .HasColumnType("bit"); 77 | 78 | b.Property("UserName") 79 | .HasMaxLength(256) 80 | .HasColumnType("nvarchar(256)"); 81 | 82 | b.HasKey("Id"); 83 | 84 | b.HasIndex("NormalizedEmail") 85 | .HasDatabaseName("EmailIndex"); 86 | 87 | b.HasIndex("NormalizedUserName") 88 | .IsUnique() 89 | .HasDatabaseName("UserNameIndex") 90 | .HasFilter("[NormalizedUserName] IS NOT NULL"); 91 | 92 | b.ToTable("AspNetUsers"); 93 | }); 94 | 95 | modelBuilder.Entity("HotelListing.Data.Country", b => 96 | { 97 | b.Property("Id") 98 | .ValueGeneratedOnAdd() 99 | .HasColumnType("int") 100 | .UseIdentityColumn(); 101 | 102 | b.Property("Name") 103 | .HasColumnType("nvarchar(max)"); 104 | 105 | b.Property("ShortName") 106 | .HasColumnType("nvarchar(max)"); 107 | 108 | b.HasKey("Id"); 109 | 110 | b.ToTable("Countries"); 111 | 112 | b.HasData( 113 | new 114 | { 115 | Id = 1, 116 | Name = "Jamaica", 117 | ShortName = "JM" 118 | }, 119 | new 120 | { 121 | Id = 2, 122 | Name = "Bahamas", 123 | ShortName = "BS" 124 | }, 125 | new 126 | { 127 | Id = 3, 128 | Name = "Cayman Island", 129 | ShortName = "CI" 130 | }); 131 | }); 132 | 133 | modelBuilder.Entity("HotelListing.Data.Hotel", b => 134 | { 135 | b.Property("Id") 136 | .ValueGeneratedOnAdd() 137 | .HasColumnType("int") 138 | .UseIdentityColumn(); 139 | 140 | b.Property("Address") 141 | .HasColumnType("nvarchar(max)"); 142 | 143 | b.Property("CountryId") 144 | .HasColumnType("int"); 145 | 146 | b.Property("Name") 147 | .HasColumnType("nvarchar(max)"); 148 | 149 | b.Property("Rating") 150 | .HasColumnType("float"); 151 | 152 | b.HasKey("Id"); 153 | 154 | b.HasIndex("CountryId"); 155 | 156 | b.ToTable("Hotels"); 157 | 158 | b.HasData( 159 | new 160 | { 161 | Id = 1, 162 | Address = "Negril", 163 | CountryId = 1, 164 | Name = "Sandals Resort and Spa", 165 | Rating = 4.5 166 | }, 167 | new 168 | { 169 | Id = 2, 170 | Address = "George Town", 171 | CountryId = 3, 172 | Name = "Comfort Suites", 173 | Rating = 4.2999999999999998 174 | }, 175 | new 176 | { 177 | Id = 3, 178 | Address = "Nassua", 179 | CountryId = 2, 180 | Name = "Grand Palldium", 181 | Rating = 4.0 182 | }); 183 | }); 184 | 185 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => 186 | { 187 | b.Property("Id") 188 | .HasColumnType("nvarchar(450)"); 189 | 190 | b.Property("ConcurrencyStamp") 191 | .IsConcurrencyToken() 192 | .HasColumnType("nvarchar(max)"); 193 | 194 | b.Property("Name") 195 | .HasMaxLength(256) 196 | .HasColumnType("nvarchar(256)"); 197 | 198 | b.Property("NormalizedName") 199 | .HasMaxLength(256) 200 | .HasColumnType("nvarchar(256)"); 201 | 202 | b.HasKey("Id"); 203 | 204 | b.HasIndex("NormalizedName") 205 | .IsUnique() 206 | .HasDatabaseName("RoleNameIndex") 207 | .HasFilter("[NormalizedName] IS NOT NULL"); 208 | 209 | b.ToTable("AspNetRoles"); 210 | 211 | b.HasData( 212 | new 213 | { 214 | Id = "22c7bc03-704d-43e9-9cd6-2d7d80c7fac0", 215 | ConcurrencyStamp = "7f365b4e-2d91-4488-895f-a6c923f10a26", 216 | Name = "User", 217 | NormalizedName = "USER" 218 | }, 219 | new 220 | { 221 | Id = "93b1c95b-c9ed-4085-a784-a18dadccf7f7", 222 | ConcurrencyStamp = "5d248937-c3f9-42e2-be31-a963508681a9", 223 | Name = "Administrator", 224 | NormalizedName = "ADMINISTRATOR" 225 | }); 226 | }); 227 | 228 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 229 | { 230 | b.Property("Id") 231 | .ValueGeneratedOnAdd() 232 | .HasColumnType("int") 233 | .UseIdentityColumn(); 234 | 235 | b.Property("ClaimType") 236 | .HasColumnType("nvarchar(max)"); 237 | 238 | b.Property("ClaimValue") 239 | .HasColumnType("nvarchar(max)"); 240 | 241 | b.Property("RoleId") 242 | .IsRequired() 243 | .HasColumnType("nvarchar(450)"); 244 | 245 | b.HasKey("Id"); 246 | 247 | b.HasIndex("RoleId"); 248 | 249 | b.ToTable("AspNetRoleClaims"); 250 | }); 251 | 252 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 253 | { 254 | b.Property("Id") 255 | .ValueGeneratedOnAdd() 256 | .HasColumnType("int") 257 | .UseIdentityColumn(); 258 | 259 | b.Property("ClaimType") 260 | .HasColumnType("nvarchar(max)"); 261 | 262 | b.Property("ClaimValue") 263 | .HasColumnType("nvarchar(max)"); 264 | 265 | b.Property("UserId") 266 | .IsRequired() 267 | .HasColumnType("nvarchar(450)"); 268 | 269 | b.HasKey("Id"); 270 | 271 | b.HasIndex("UserId"); 272 | 273 | b.ToTable("AspNetUserClaims"); 274 | }); 275 | 276 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 277 | { 278 | b.Property("LoginProvider") 279 | .HasColumnType("nvarchar(450)"); 280 | 281 | b.Property("ProviderKey") 282 | .HasColumnType("nvarchar(450)"); 283 | 284 | b.Property("ProviderDisplayName") 285 | .HasColumnType("nvarchar(max)"); 286 | 287 | b.Property("UserId") 288 | .IsRequired() 289 | .HasColumnType("nvarchar(450)"); 290 | 291 | b.HasKey("LoginProvider", "ProviderKey"); 292 | 293 | b.HasIndex("UserId"); 294 | 295 | b.ToTable("AspNetUserLogins"); 296 | }); 297 | 298 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 299 | { 300 | b.Property("UserId") 301 | .HasColumnType("nvarchar(450)"); 302 | 303 | b.Property("RoleId") 304 | .HasColumnType("nvarchar(450)"); 305 | 306 | b.HasKey("UserId", "RoleId"); 307 | 308 | b.HasIndex("RoleId"); 309 | 310 | b.ToTable("AspNetUserRoles"); 311 | }); 312 | 313 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 314 | { 315 | b.Property("UserId") 316 | .HasColumnType("nvarchar(450)"); 317 | 318 | b.Property("LoginProvider") 319 | .HasColumnType("nvarchar(450)"); 320 | 321 | b.Property("Name") 322 | .HasColumnType("nvarchar(450)"); 323 | 324 | b.Property("Value") 325 | .HasColumnType("nvarchar(max)"); 326 | 327 | b.HasKey("UserId", "LoginProvider", "Name"); 328 | 329 | b.ToTable("AspNetUserTokens"); 330 | }); 331 | 332 | modelBuilder.Entity("HotelListing.Data.Hotel", b => 333 | { 334 | b.HasOne("HotelListing.Data.Country", "Country") 335 | .WithMany("Hotels") 336 | .HasForeignKey("CountryId") 337 | .OnDelete(DeleteBehavior.Cascade) 338 | .IsRequired(); 339 | 340 | b.Navigation("Country"); 341 | }); 342 | 343 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => 344 | { 345 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 346 | .WithMany() 347 | .HasForeignKey("RoleId") 348 | .OnDelete(DeleteBehavior.Cascade) 349 | .IsRequired(); 350 | }); 351 | 352 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => 353 | { 354 | b.HasOne("HotelListing.Data.ApiUser", null) 355 | .WithMany() 356 | .HasForeignKey("UserId") 357 | .OnDelete(DeleteBehavior.Cascade) 358 | .IsRequired(); 359 | }); 360 | 361 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => 362 | { 363 | b.HasOne("HotelListing.Data.ApiUser", null) 364 | .WithMany() 365 | .HasForeignKey("UserId") 366 | .OnDelete(DeleteBehavior.Cascade) 367 | .IsRequired(); 368 | }); 369 | 370 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => 371 | { 372 | b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) 373 | .WithMany() 374 | .HasForeignKey("RoleId") 375 | .OnDelete(DeleteBehavior.Cascade) 376 | .IsRequired(); 377 | 378 | b.HasOne("HotelListing.Data.ApiUser", null) 379 | .WithMany() 380 | .HasForeignKey("UserId") 381 | .OnDelete(DeleteBehavior.Cascade) 382 | .IsRequired(); 383 | }); 384 | 385 | modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => 386 | { 387 | b.HasOne("HotelListing.Data.ApiUser", null) 388 | .WithMany() 389 | .HasForeignKey("UserId") 390 | .OnDelete(DeleteBehavior.Cascade) 391 | .IsRequired(); 392 | }); 393 | 394 | modelBuilder.Entity("HotelListing.Data.Country", b => 395 | { 396 | b.Navigation("Hotels"); 397 | }); 398 | #pragma warning restore 612, 618 399 | } 400 | } 401 | } 402 | --------------------------------------------------------------------------------