├── README.md
├── HotelBookingSystem.Presentation
├── Program.cs
├── HotelBookingSystem.Presentation.csproj
└── SpectreUI
│ ├── AdminPanel
│ ├── AdminLogin.cs
│ ├── AdminMenu.cs
│ └── Actions
│ │ └── AdminActions.cs
│ ├── CustomerPanel
│ ├── CustomerLogin.cs
│ ├── CustomerRegister.cs
│ ├── CustomerMenu.cs
│ └── Actions
│ │ └── CustomerActions.cs
│ └── MainMenu.cs
├── HotelBookingSystem.Domain
├── Enums
│ └── ApartmentType.cs
├── Entities
│ ├── Admin.cs
│ ├── Commons
│ │ └── Auditable.cs
│ ├── Apartment.cs
│ └── Customer.cs
└── HotelBookingSystem.Domain.csproj
├── HotelBookingSystem.DataAccess
├── Data
│ ├── Administration.json
│ ├── Apartments.json
│ └── Customers.json
└── HotelBookingSystem.DataAccess.csproj
├── HotelBookingSystem.Service
├── Configurations
│ └── Constants.cs
├── HotelBookingSystem.Services.csproj
├── Helpers
│ ├── FileIO.cs
│ └── PasswordHashing.cs
├── Interfaces
│ ├── IAdminService.cs
│ ├── IApartmentService.cs
│ └── ICustomerService.cs
├── Extensions
│ ├── CollectionExtension.cs
│ └── MapperExtension.cs
└── Services
│ ├── AdminService.cs
│ ├── ApartmentService.cs
│ └── CustomerService.cs
├── HotelBookingSystem.DTOs
├── HotelBookingSystem.DTOs.csproj
├── ApartmentModels
│ └── ApartmentCreateModel.cs
└── CustomerModels
│ ├── CustomerUpdateModel.cs
│ ├── CustomerCreateModel.cs
│ └── CustomerViewModel.cs
├── .gitattributes
├── HotelBookingSystem.sln
└── .gitignore
/README.md:
--------------------------------------------------------------------------------
1 | # HotelBookingSystem
2 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Presentation/Program.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Presentation.SpectreUI;
2 |
3 | MainMenu mainMenu = new();
4 | await mainMenu.RunAsync();
5 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/Enums/ApartmentType.cs:
--------------------------------------------------------------------------------
1 | namespace HotelBookingSystem.Domain.Enums;
2 |
3 | public enum ApartmentType
4 | {
5 | Econo,
6 | Normal,
7 | Premium
8 | }
9 |
--------------------------------------------------------------------------------
/HotelBookingSystem.DataAccess/Data/Administration.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "password": "0c1a7baa31b36a885df2839a329abb299427ec5131829ed05b6269c0d7cb88cd",
4 | "hotel_balance_info": 100000.0
5 | }
6 | ]
--------------------------------------------------------------------------------
/HotelBookingSystem.DataAccess/HotelBookingSystem.DataAccess.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | disable
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/Entities/Admin.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace HotelBookingSystem.Domain.Entities;
4 |
5 | public class Admin
6 | {
7 | [JsonProperty("password")]
8 | public string Password { get; set; }
9 | [JsonProperty("hotel_balance_info")]
10 | public double HotelBalanceInfo { get; set; }
11 | }
12 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/HotelBookingSystem.Domain.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | disable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Configurations/Constants.cs:
--------------------------------------------------------------------------------
1 | namespace HotelBookingSystem.Services.Configurations;
2 |
3 | public class Constants
4 | {
5 | public const string CUSTOMERSPATH = @"..\..\..\..\HotelBookingSystem.DataAccess\Data\Customers.json";
6 | public const string APARTMENTSPATH = @"..\..\..\..\HotelBookingSystem.DataAccess\Data\Apartments.json";
7 | public const string ADMINISTRATIONINFO = @"..\..\..\..\HotelBookingSystem.DataAccess\Data\Administration.json";
8 | }
9 |
--------------------------------------------------------------------------------
/HotelBookingSystem.DTOs/HotelBookingSystem.DTOs.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | disable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/HotelBookingSystem.DTOs/ApartmentModels/ApartmentCreateModel.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 | using HotelBookingSystem.Domain.Enums;
3 | using Newtonsoft.Json;
4 |
5 | namespace HotelBookingSystem.DTOs.ApartmentModels;
6 |
7 | public class ApartmentCreateModel : Auditable
8 | {
9 | [JsonProperty("price")]
10 | public double Price { get; set; }
11 | [JsonProperty("count_of_rooms")]
12 | public int CountOfRooms { get; set; }
13 | [JsonProperty("RoomType")]
14 | public ApartmentType ApartmentType { get; set; }
15 | }
16 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/Entities/Commons/Auditable.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace HotelBookingSystem.Domain.Entities.Commons;
4 | public class Auditable
5 | {
6 | [JsonProperty("id")]
7 | public int Id { get; set; }
8 | [JsonProperty("created_at")]
9 | public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
10 | [JsonProperty("updated_at")]
11 | public DateTime UpdatedAt { get; set; }
12 | [JsonProperty("deleted_at")]
13 | public DateTime DeletedAt { get; set; }
14 | [JsonProperty("is_deleted")]
15 | public bool IsDeleted { get; set; }
16 | }
17 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/Entities/Apartment.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 | using HotelBookingSystem.Domain.Enums;
3 | using Newtonsoft.Json;
4 |
5 | namespace HotelBookingSystem.Domain.Entities;
6 |
7 | public class Apartment : Auditable
8 | {
9 | [JsonProperty("price")]
10 | public double Price { get; set; }
11 | [JsonProperty("count_of_rooms")]
12 | public int CountOfRooms { get; set; }
13 | [JsonProperty("room_type")]
14 | public ApartmentType ApartmentType { get; set; }
15 | [JsonProperty("ordered_customer_id")]
16 | public int OrderedCustomerId { get; set; }
17 | }
18 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/HotelBookingSystem.Services.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | disable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/HotelBookingSystem.DTOs/CustomerModels/CustomerUpdateModel.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 | using Newtonsoft.Json;
3 |
4 | namespace HotelBookingSystem.DTOs.CustomerModels;
5 |
6 | public class CustomerUpdateModel : Auditable
7 | {
8 | [JsonProperty("username")]
9 | public string Username { get; set; }
10 | [JsonProperty("password")]
11 | public string Password { get; set; }
12 | [JsonProperty("email")]
13 | public string Email { get; set; }
14 | [JsonProperty("firstname")]
15 | public string Firstname { get; set; }
16 | [JsonProperty("lastname")]
17 | public string Lastname { get; set; }
18 | }
--------------------------------------------------------------------------------
/HotelBookingSystem.DTOs/CustomerModels/CustomerCreateModel.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 | using Newtonsoft.Json;
3 |
4 | namespace HotelBookingSystem.DTOs.CustomerModels;
5 |
6 | public class CustomerCreateModel : Auditable
7 | {
8 | [JsonProperty("username")]
9 | public string Username { get; set; }
10 | [JsonProperty("password")]
11 | public string Password { get; set; }
12 | [JsonProperty("email")]
13 | public string Email { get; set; }
14 | [JsonProperty("firstname")]
15 | public string Firstname { get; set; }
16 | [JsonProperty("lastname")]
17 | public string Lastname { get; set; }
18 | }
19 |
--------------------------------------------------------------------------------
/HotelBookingSystem.DataAccess/Data/Apartments.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "price": 50000.0,
4 | "count_of_rooms": 3,
5 | "room_type": 1,
6 | "ordered_customer_id": 1,
7 | "id": 1,
8 | "created_at": "2024-03-03T20:49:26.9736149Z",
9 | "updated_at": "0001-01-01T00:00:00",
10 | "deleted_at": "0001-01-01T00:00:00",
11 | "is_deleted": false
12 | },
13 | {
14 | "price": 50000.0,
15 | "count_of_rooms": 10,
16 | "room_type": 2,
17 | "ordered_customer_id": 3,
18 | "id": 2,
19 | "created_at": "2024-03-12T05:40:04.2628377Z",
20 | "updated_at": "0001-01-01T00:00:00",
21 | "deleted_at": "0001-01-01T00:00:00",
22 | "is_deleted": false
23 | }
24 | ]
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Helpers/FileIO.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace HotelBookingSystem.Services.Helpers;
4 |
5 | public static class FileIO
6 | {
7 | public static async ValueTask> ReadAsync(string path)
8 | {
9 | var content = await File.ReadAllTextAsync(path);
10 | if (content is null || !content.Any())
11 | return [];
12 |
13 | return JsonConvert.DeserializeObject>(content);
14 | }
15 |
16 | public static async ValueTask WriteAsync(string path, List values)
17 | {
18 | var json = JsonConvert.SerializeObject(values, Formatting.Indented);
19 | await File.WriteAllTextAsync(path, json);
20 | }
21 | }
--------------------------------------------------------------------------------
/HotelBookingSystem.DTOs/CustomerModels/CustomerViewModel.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 |
3 | namespace HotelBookingSystem.DTOs.CustomerModels;
4 |
5 | public class CustomerViewModel
6 | {
7 | [JsonProperty("id")]
8 | public int Id { get; set; }
9 | [JsonProperty("username")]
10 | public string Username { get; set; }
11 | [JsonProperty("balance")]
12 | public double Balance { get; set; }
13 | [JsonProperty("email")]
14 | public string Email { get; set; }
15 | [JsonProperty("firstname")]
16 | public string Firstname { get; set; }
17 | [JsonProperty("lastname")]
18 | public string Lastname { get; set; }
19 | [JsonProperty("apartment_id")]
20 | public int ApartmentId { get; set; }
21 | }
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Interfaces/IAdminService.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities;
2 | using HotelBookingSystem.DTOs.ApartmentModels;
3 |
4 | namespace HotelBookingSystem.Services.Interfaces;
5 |
6 | public interface IAdminService
7 | {
8 | public ValueTask AddNewApartmentAsync(ApartmentCreateModel newApartment);
9 | public ValueTask GetApartmentByIdAsync(int id);
10 | public ValueTask> GetAllApartmentsAsync();
11 | public ValueTask> GetAllCustomersAsync();
12 | public ValueTask UpdatePasswordAsync(Admin newAdmin);
13 | public ValueTask LoginAsAdminAsync(string password);
14 | public ValueTask HotelBalanceInfoAsync();
15 | }
--------------------------------------------------------------------------------
/HotelBookingSystem.Domain/Entities/Customer.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 | using Newtonsoft.Json;
3 |
4 | namespace HotelBookingSystem.Domain.Entities;
5 |
6 | public class Customer : Auditable
7 | {
8 | [JsonProperty("username")]
9 | public string Username { get; set; }
10 | [JsonProperty("password")]
11 | public string Password { get; set; }
12 | [JsonProperty("email")]
13 | public string Email { get; set; }
14 | [JsonProperty("firstname")]
15 | public string Firstname { get; set; }
16 | [JsonProperty("lastname")]
17 | public string Lastname { get; set; }
18 | [JsonProperty("balance")]
19 | public double Balance { get; set; }
20 | [JsonProperty("room_id")]
21 | public int ApartmentId { get; set; }
22 | }
23 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Helpers/PasswordHashing.cs:
--------------------------------------------------------------------------------
1 | using System.Security.Cryptography;
2 | using System.Text;
3 |
4 | namespace HotelBookingSystem.Services.Helpers;
5 |
6 | public static class PasswordHashing
7 | {
8 | public static string Hashing(string password)
9 | {
10 | using (SHA256 hash = SHA256.Create())
11 | {
12 | byte[] hashedBytes = hash.ComputeHash(Encoding.UTF8.GetBytes(password));
13 | return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
14 | }
15 | }
16 | public static bool VerifyPassword(string actualHashedPassword, string enteredPassword)
17 | {
18 | string enteredHashedPassword = Hashing(enteredPassword);
19 | return actualHashedPassword == enteredHashedPassword;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Extensions/CollectionExtension.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities.Commons;
2 |
3 | namespace HotelBookingSystem.Services.Extensions;
4 |
5 | public static class CollectionExtension
6 | {
7 | public static T Create(this List values, T model) where T : Auditable
8 | {
9 | var lastId = values.Count == 0 ? 1 : values.Last().Id + 1;
10 | model.Id = lastId;
11 | values.Add(model);
12 | return values.Last();
13 | }
14 | public static List BulkCreate(this List values, List models) where T : Auditable
15 | {
16 | var lastId = values.Count == 0 ? 1 : values.Last().Id + 1;
17 | models.ForEach(t => t.Id = lastId++);
18 | values.AddRange(models);
19 | return values;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Presentation/HotelBookingSystem.Presentation.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 | enable
6 | disable
7 | Exe
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Interfaces/IApartmentService.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities;
2 | using HotelBookingSystem.DTOs.ApartmentModels;
3 |
4 | namespace HotelBookingSystem.Services.Interfaces;
5 |
6 | internal interface IApartmentService
7 | {
8 | public ValueTask CreateAsync(ApartmentCreateModel apartment);
9 | public ValueTask DeleteAsync(int id);
10 | public ValueTask GetAsync(int id);
11 | public ValueTask> GetAllAsync();
12 | public ValueTask SetOrderedAsync(int apartmentId, int customerId);
13 | public ValueTask SetUnorderedAsync(int apartmentId, int customerId);
14 | public ValueTask> BookedApartmentsAsync();
15 | public ValueTask> NotBookedApartmentsAsync();
16 | public ValueTask> GetAllPremiumAsync();
17 | public ValueTask> GetAllNormalAsync();
18 | public ValueTask> GetAllPreminumAsync();
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Interfaces/ICustomerService.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Domain.Entities;
2 | using HotelBookingSystem.DTOs.CustomerModels;
3 |
4 | namespace HotelBookingSystem.Services.Interfaces;
5 |
6 | public interface ICustomerService
7 | {
8 | public ValueTask CreateAsync(CustomerCreateModel customer);
9 | public ValueTask UpdateAsync(int customerId, CustomerUpdateModel customer);
10 | public ValueTask DeleteAsync(int customerId);
11 | public ValueTask ViewCustomerAsync(int customerId);
12 | public ValueTask GetCustomerAsync(int customerId);
13 | public ValueTask GetToLoginAsync(string username, string password);
14 | public ValueTask> GetAllAsync();
15 | public ValueTask BookApartmentAsync(int apartmentId, int customerId);
16 | public ValueTask DeleteBookingApartmentAsync(int apartmentId, int customerId);
17 | public ValueTask DepositAsync(int customerId, double amount);
18 | }
--------------------------------------------------------------------------------
/HotelBookingSystem.DataAccess/Data/Customers.json:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "username": "hotelmotel",
4 | "password": "f023f4d618fc27434bcfd740bc91204b891bc2d2aa538d85f948c5bfde986d1c",
5 | "email": "aa@aa.aa",
6 | "firstname": "hotel",
7 | "lastname": "motel",
8 | "balance": 10000000050000.0,
9 | "room_id": 1,
10 | "id": 1,
11 | "created_at": "2024-03-03T14:54:53.3053757Z",
12 | "updated_at": "2024-03-07T19:00:21.5976019Z",
13 | "deleted_at": "0001-01-01T00:00:00",
14 | "is_deleted": false
15 | },
16 | {
17 | "username": "yasub",
18 | "password": "0264aa715a9c29538ee3930b366295f6598becfbc91ac4de1af5910ccb511919",
19 | "email": "yasub@gmail.com",
20 | "firstname": "Ali",
21 | "lastname": "Yasuf",
22 | "balance": 1000000.0,
23 | "room_id": 0,
24 | "id": 2,
25 | "created_at": "2024-03-04T16:07:57.362052Z",
26 | "updated_at": "0001-01-01T00:00:00",
27 | "deleted_at": "0001-01-01T00:00:00",
28 | "is_deleted": false
29 | },
30 | {
31 | "username": "davik23",
32 | "password": "36ca5b5469ef74abf5bf4cc8533a4f591bf8fd30f19e50baf2b6910ef4c3389d",
33 | "email": "aa@a1.aa",
34 | "firstname": "Davikk",
35 | "lastname": "davik",
36 | "balance": 123073123.0,
37 | "room_id": 2,
38 | "id": 3,
39 | "created_at": "2024-03-12T05:38:41.5902508Z",
40 | "updated_at": "0001-01-01T00:00:00",
41 | "deleted_at": "0001-01-01T00:00:00",
42 | "is_deleted": false
43 | }
44 | ]
--------------------------------------------------------------------------------
/HotelBookingSystem.Presentation/SpectreUI/AdminPanel/AdminLogin.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Services.Services;
2 | using Spectre.Console;
3 |
4 | namespace HotelBookingSystem.Presentation.SpectreUI.AdminPanel;
5 |
6 | public class AdminLogin
7 | {
8 | private AdminService adminService;
9 | private ApartmentService apartmentService;
10 | private AdminMenu adminMenu;
11 |
12 | public AdminLogin(AdminService adminService, ApartmentService apartmentService)
13 | {
14 | this.adminService = adminService;
15 | this.apartmentService = apartmentService;
16 | }
17 |
18 | #region Login
19 | public async Task LoginAsync()
20 | {
21 | AnsiConsole.Clear();
22 | while (true)
23 | {
24 | var password = AnsiConsole.Prompt(
25 | new TextPrompt("Enter [green]password[/]:")
26 | .PromptStyle("yellow")
27 | .Secret());
28 |
29 | try
30 | {
31 | var getAdmin = await adminService.LoginAsAdminAsync(password);
32 |
33 | adminMenu = new AdminMenu(getAdmin, adminService, apartmentService);
34 | await adminMenu.MenuAsync();
35 | return;
36 | }
37 | catch (Exception ex)
38 | {
39 | Console.Clear();
40 | Console.WriteLine(ex.Message);
41 | AnsiConsole.WriteLine("Press any key to exit and try again.");
42 | Console.ReadLine();
43 | AnsiConsole.Clear();
44 | return;
45 | }
46 | }
47 | }
48 | #endregion
49 | }
50 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Presentation/SpectreUI/CustomerPanel/CustomerLogin.cs:
--------------------------------------------------------------------------------
1 | using HotelBookingSystem.Services.Services;
2 | using Spectre.Console;
3 |
4 | namespace HotelBookingSystem.Presentation.SpectreUI.CustomerPanel;
5 |
6 | public class CustomerLogin
7 | {
8 |
9 | private CustomerService customerService;
10 | private ApartmentService apartmentService;
11 | private CustomerMenu customerMenu;
12 |
13 | public CustomerLogin(CustomerService customerService, ApartmentService apartmentService)
14 | {
15 | this.customerService = customerService;
16 | this.apartmentService = apartmentService;
17 | }
18 |
19 | #region Login
20 | public async Task LoginAsync()
21 | {
22 | AnsiConsole.Clear();
23 | while (true)
24 | {
25 | var username = AnsiConsole.Ask("Enter your [green]username[/]:");
26 | var password = AnsiConsole.Prompt(
27 | new TextPrompt("Enter your [green]password[/]:")
28 | .PromptStyle("yellow")
29 | .Secret());
30 |
31 | try
32 | {
33 | var getCustomer = await customerService.GetToLoginAsync(username, password);
34 |
35 | customerMenu = new CustomerMenu(getCustomer, customerService, apartmentService);
36 | await customerMenu.MenuAsync();
37 | return;
38 | }
39 | catch (Exception ex)
40 | {
41 | Console.Clear();
42 | Console.WriteLine(ex.Message);
43 | AnsiConsole.WriteLine("Press any key to exit and try again.");
44 | Console.ReadLine();
45 | AnsiConsole.Clear();
46 | return;
47 | }
48 | }
49 | }
50 | #endregion
51 | }
52 |
--------------------------------------------------------------------------------
/HotelBookingSystem.Service/Extensions/MapperExtension.cs:
--------------------------------------------------------------------------------
1 | namespace HotelBookingSystem.Services.Extensions;
2 |
3 | public static class MapperExtension
4 | {
5 | public static T MapTo(this object obj) where T : class, new()
6 | {
7 | var objType = obj.GetType();
8 | var objProperties = objType.GetProperties();
9 |
10 | var dto = new T();
11 | var dtoType = dto.GetType();
12 | var dtoProperties = dtoType.GetProperties();
13 |
14 | foreach (var objProperty in objProperties)
15 | {
16 | if (dtoProperties.Any(p => p.Name == objProperty.Name))
17 | {
18 | var dtoProperty = dtoType.GetProperty(objProperty.Name);
19 | var value = objProperty.GetValue(obj);
20 | dtoProperty.SetValue(dto, value);
21 | }
22 | }
23 | return dto;
24 | }
25 |
26 | public static List MapTo(this IEnumerable