├── 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 objs) where T : class, new() 27 | { 28 | var result = new List(); 29 | 30 | var dto = new T(); 31 | var dtoType = dto.GetType(); 32 | var dtoProperties = dtoType.GetProperties(); 33 | 34 | foreach (var obj in objs) 35 | { 36 | var objType = obj.GetType(); 37 | var objProperties = objType.GetProperties(); 38 | 39 | foreach (var objProperty in objProperties) 40 | { 41 | if (dtoProperties.Any(p => p.Name == objProperty.Name)) 42 | { 43 | var dtoProperty = dtoType.GetProperty(objProperty.Name); 44 | var value = objProperty.GetValue(obj); 45 | dtoProperty.SetValue(dto, value); 46 | } 47 | } 48 | result.Add(dto); 49 | } 50 | return result; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /HotelBookingSystem.Service/Services/AdminService.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.DTOs.ApartmentModels; 3 | using HotelBookingSystem.Services.Configurations; 4 | using HotelBookingSystem.Services.Helpers; 5 | using HotelBookingSystem.Services.Interfaces; 6 | 7 | namespace HotelBookingSystem.Services.Services; 8 | 9 | public class AdminService : IAdminService 10 | { 11 | public AdminService(ApartmentService apartmentService, CustomerService customerService) 12 | { 13 | this.apartmentService = apartmentService; 14 | this.customerService = customerService; 15 | } 16 | 17 | private List administration; 18 | private ApartmentService apartmentService; 19 | private CustomerService customerService; 20 | 21 | public async ValueTask AddNewApartmentAsync(ApartmentCreateModel newApartment) 22 | { 23 | return await apartmentService.CreateAsync(newApartment); 24 | } 25 | public async ValueTask> GetAllApartmentsAsync() 26 | { 27 | return await apartmentService.GetAllAsync(); 28 | } 29 | public async ValueTask> GetAllCustomersAsync() 30 | { 31 | return await customerService.GetAllAsync(); 32 | } 33 | public async ValueTask GetApartmentByIdAsync(int id) 34 | { 35 | return await apartmentService.GetAsync(id); 36 | } 37 | public async ValueTask LoginAsAdminAsync(string password) 38 | { 39 | administration = await FileIO.ReadAsync(Constants.ADMINISTRATIONINFO); 40 | 41 | var admin = administration.FirstOrDefault(a => PasswordHashing.VerifyPassword(a.Password, password)) 42 | ?? throw new Exception("Password is not match."); 43 | return admin; 44 | } 45 | public async ValueTask UpdatePasswordAsync(Admin newAdmin) 46 | { 47 | administration = await FileIO.ReadAsync(Constants.ADMINISTRATIONINFO); 48 | 49 | var admin = administration.FirstOrDefault() 50 | ?? throw new Exception("administration info corrupted."); 51 | 52 | admin.Password = PasswordHashing.Hashing(newAdmin.Password); 53 | 54 | await FileIO.WriteAsync(Constants.ADMINISTRATIONINFO, administration); 55 | return admin; 56 | } 57 | public async ValueTask HotelBalanceInfoAsync() 58 | { 59 | administration = await FileIO.ReadAsync(Constants.ADMINISTRATIONINFO); 60 | 61 | var admin = administration.FirstOrDefault() 62 | ?? throw new Exception("administration info corrupted."); 63 | return admin.HotelBalanceInfo; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/CustomerPanel/CustomerRegister.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.DTOs.CustomerModels; 2 | using HotelBookingSystem.Services.Helpers; 3 | using HotelBookingSystem.Services.Services; 4 | using Spectre.Console; 5 | using System.Text.RegularExpressions; 6 | 7 | namespace HotelBookingSystem.Presentation.SpectreUI.CustomerPanel; 8 | 9 | public class CustomerRegister 10 | { 11 | private CustomerService customerService; 12 | private ApartmentService apartmentService; 13 | private CustomerMenu customerMenu; 14 | public CustomerRegister(CustomerService customerService, ApartmentService apartmentService) 15 | { 16 | this.customerService = customerService; 17 | this.apartmentService = apartmentService; 18 | } 19 | 20 | #region Registration 21 | public async Task RegisterAsync() 22 | { 23 | AnsiConsole.Clear(); 24 | while (true) 25 | { 26 | var customerCreateModel = new CustomerCreateModel(); 27 | 28 | var username = AnsiConsole.Ask("Enter your [green]username[/]:"); 29 | reenterpassword: 30 | var password = AnsiConsole.Prompt( 31 | new TextPrompt("Enter your [green]password[/]:") 32 | .PromptStyle("yellow") 33 | .Secret()); 34 | while (password.Length < 8) 35 | { 36 | AnsiConsole.WriteLine("Password's length must be at least 8 characters"); 37 | goto reenterpassword; 38 | } 39 | string email = string.Empty; 40 | while (string.IsNullOrWhiteSpace(email = AnsiConsole.Ask("Enter your [green]email[/]")) || !Regex.IsMatch(email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")) 41 | { 42 | Console.WriteLine("Invalid email address!"); 43 | } 44 | string firstname = AnsiConsole.Ask("Enter your [green]Firstname[/]"); 45 | string lastname = AnsiConsole.Ask("Enter your [green]Lastname[/]"); 46 | 47 | var HashedPassword = PasswordHashing.Hashing(password); 48 | 49 | customerCreateModel.Username = username; 50 | customerCreateModel.Password = HashedPassword; 51 | customerCreateModel.Email = email; 52 | customerCreateModel.Firstname = firstname; 53 | customerCreateModel.Lastname = lastname; 54 | 55 | try 56 | { 57 | var createdCustomer = await customerService.CreateAsync(customerCreateModel); 58 | var getCustomer = await customerService.GetToLoginAsync(username, password); 59 | 60 | customerMenu = new CustomerMenu(getCustomer, customerService, apartmentService); 61 | await customerMenu.MenuAsync(); 62 | return; 63 | } 64 | catch (Exception ex) 65 | { 66 | Console.Clear(); 67 | Console.WriteLine(ex.Message); 68 | AnsiConsole.WriteLine("Press any key to exit and try again."); 69 | Console.ReadLine(); 70 | AnsiConsole.Clear(); 71 | return; 72 | } 73 | 74 | } 75 | } 76 | #endregion 77 | } 78 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/MainMenu.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Presentation.SpectreUI.AdminPanel; 2 | using HotelBookingSystem.Presentation.SpectreUI.CustomerPanel; 3 | using HotelBookingSystem.Services.Services; 4 | using Spectre.Console; 5 | 6 | namespace HotelBookingSystem.Presentation.SpectreUI; 7 | 8 | public class MainMenu 9 | { 10 | private CustomerService customerService; 11 | private ApartmentService apartmentService; 12 | private AdminService adminService; 13 | 14 | private AdminLogin adminLogin; 15 | 16 | private CustomerLogin customerLogin; 17 | private CustomerRegister customerRegister; 18 | 19 | public MainMenu() 20 | { 21 | apartmentService = new ApartmentService(); 22 | customerService = new CustomerService(apartmentService); 23 | adminService = new AdminService(apartmentService, customerService); 24 | 25 | adminLogin = new AdminLogin(adminService, apartmentService); 26 | customerLogin = new CustomerLogin(customerService, apartmentService); 27 | customerRegister = new CustomerRegister(customerService, apartmentService); 28 | } 29 | 30 | #region Run 31 | public async Task RunAsync() 32 | { 33 | while (true) 34 | { 35 | var choise = AnsiConsole.Prompt( 36 | new SelectionPrompt() 37 | .Title("Dream[green]House[/]") 38 | .PageSize(4) 39 | .AddChoices(new[] { 40 | "As Customer", 41 | "As Administrator\n", 42 | "[red]Exit[/]"})); 43 | 44 | switch (choise) 45 | { 46 | case "As Customer": 47 | AnsiConsole.Clear(); 48 | await CustomerAskAsync(); 49 | break; 50 | case "As Administrator\n": 51 | AnsiConsole.Clear(); 52 | await AdminAskAsync(); 53 | break; 54 | case "[red]Exit[/]": 55 | return; 56 | } 57 | } 58 | } 59 | #endregion 60 | 61 | #region Customer 62 | public async Task CustomerAskAsync() 63 | { 64 | while (true) 65 | { 66 | var c = AnsiConsole.Prompt( 67 | new SelectionPrompt() 68 | .Title("As Customer") 69 | .PageSize(4) 70 | .AddChoices(new[] { 71 | "Login", 72 | "Register\n", 73 | "[red]Go Back[/]"})); 74 | switch (c) 75 | { 76 | case "Login": 77 | await customerLogin.LoginAsync(); 78 | break; 79 | case "Register\n": 80 | await customerRegister.RegisterAsync(); 81 | break; 82 | case "[red]Go Back[/]": 83 | return; 84 | } 85 | } 86 | } 87 | #endregion 88 | 89 | #region Admin 90 | public async Task AdminAskAsync() 91 | { 92 | while (true) 93 | { 94 | var c = AnsiConsole.Prompt( 95 | new SelectionPrompt() 96 | .Title("As Administrator") 97 | .PageSize(4) 98 | .AddChoices(new[] { 99 | "Login\n", 100 | "[red]Go Back[/]"})); 101 | switch (c) 102 | { 103 | case "Login\n": 104 | await adminLogin.LoginAsync(); 105 | break; 106 | case "[red]Go Back[/]": 107 | return; 108 | } 109 | } 110 | } 111 | #endregion 112 | } 113 | -------------------------------------------------------------------------------- /HotelBookingSystem.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.8.34525.116 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBookingSystem.DataAccess", "HotelBookingSystem.DataAccess\HotelBookingSystem.DataAccess.csproj", "{F31C497E-99CC-4351-AF13-D3A193C9BFB1}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBookingSystem.Domain", "HotelBookingSystem.Domain\HotelBookingSystem.Domain.csproj", "{CDE2ADFA-4F70-4639-BADD-2890AA0D811D}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBookingSystem.DTOs", "HotelBookingSystem.DTOs\HotelBookingSystem.DTOs.csproj", "{797F013A-28CF-45B9-893C-BEF685A893E4}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBookingSystem.Services", "HotelBookingSystem.Service\HotelBookingSystem.Services.csproj", "{0CF67479-CBF8-4004-9DE5-5E011A4997FD}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBookingSystem.Presentation", "HotelBookingSystem.Presentation\HotelBookingSystem.Presentation.csproj", "{0C631573-77D4-4938-A9B7-CB25EF5A4FF5}" 15 | EndProject 16 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{E488FAA7-A7B4-447A-AE34-B3A67D91FB49}" 17 | EndProject 18 | Global 19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 20 | Debug|Any CPU = Debug|Any CPU 21 | Release|Any CPU = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {F31C497E-99CC-4351-AF13-D3A193C9BFB1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {F31C497E-99CC-4351-AF13-D3A193C9BFB1}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {F31C497E-99CC-4351-AF13-D3A193C9BFB1}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {F31C497E-99CC-4351-AF13-D3A193C9BFB1}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {CDE2ADFA-4F70-4639-BADD-2890AA0D811D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 29 | {CDE2ADFA-4F70-4639-BADD-2890AA0D811D}.Debug|Any CPU.Build.0 = Debug|Any CPU 30 | {CDE2ADFA-4F70-4639-BADD-2890AA0D811D}.Release|Any CPU.ActiveCfg = Release|Any CPU 31 | {CDE2ADFA-4F70-4639-BADD-2890AA0D811D}.Release|Any CPU.Build.0 = Release|Any CPU 32 | {797F013A-28CF-45B9-893C-BEF685A893E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {797F013A-28CF-45B9-893C-BEF685A893E4}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {797F013A-28CF-45B9-893C-BEF685A893E4}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {797F013A-28CF-45B9-893C-BEF685A893E4}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {0CF67479-CBF8-4004-9DE5-5E011A4997FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 37 | {0CF67479-CBF8-4004-9DE5-5E011A4997FD}.Debug|Any CPU.Build.0 = Debug|Any CPU 38 | {0CF67479-CBF8-4004-9DE5-5E011A4997FD}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {0CF67479-CBF8-4004-9DE5-5E011A4997FD}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {0C631573-77D4-4938-A9B7-CB25EF5A4FF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {0C631573-77D4-4938-A9B7-CB25EF5A4FF5}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {0C631573-77D4-4938-A9B7-CB25EF5A4FF5}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {0C631573-77D4-4938-A9B7-CB25EF5A4FF5}.Release|Any CPU.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(NestedProjects) = preSolution 49 | {F31C497E-99CC-4351-AF13-D3A193C9BFB1} = {E488FAA7-A7B4-447A-AE34-B3A67D91FB49} 50 | {CDE2ADFA-4F70-4639-BADD-2890AA0D811D} = {E488FAA7-A7B4-447A-AE34-B3A67D91FB49} 51 | {797F013A-28CF-45B9-893C-BEF685A893E4} = {E488FAA7-A7B4-447A-AE34-B3A67D91FB49} 52 | {0CF67479-CBF8-4004-9DE5-5E011A4997FD} = {E488FAA7-A7B4-447A-AE34-B3A67D91FB49} 53 | {0C631573-77D4-4938-A9B7-CB25EF5A4FF5} = {E488FAA7-A7B4-447A-AE34-B3A67D91FB49} 54 | EndGlobalSection 55 | GlobalSection(ExtensibilityGlobals) = postSolution 56 | SolutionGuid = {3EB070F3-FF76-4A97-8DCE-001672916C12} 57 | EndGlobalSection 58 | EndGlobal 59 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/CustomerPanel/CustomerMenu.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.Presentation.SpectreUI.CustomerPanel.Actions; 3 | using HotelBookingSystem.Services.Services; 4 | using Spectre.Console; 5 | 6 | namespace HotelBookingSystem.Presentation.SpectreUI.CustomerPanel; 7 | 8 | public class CustomerMenu 9 | { 10 | private Customer Customer; 11 | private CustomerActions customerActions; 12 | private CustomerService customerService; 13 | private ApartmentService apartmentService; 14 | public CustomerMenu(Customer customer, CustomerService customerService, ApartmentService apartmentService) 15 | { 16 | Customer = customer; 17 | this.customerService = customerService; 18 | this.apartmentService = apartmentService; 19 | customerActions = new CustomerActions(customer, customerService, apartmentService); 20 | } 21 | 22 | #region Menu 23 | public async Task MenuAsync() 24 | { 25 | while (true) 26 | { 27 | AnsiConsole.Clear(); 28 | var choise = AnsiConsole.Prompt( 29 | new SelectionPrompt() 30 | .Title("Dream[green]House[/][red]/[/]Customer") 31 | .PageSize(4) 32 | .AddChoices(new[] { 33 | "Deposit", 34 | "View Booked Apartments", 35 | "View not Booked Apartments", 36 | "View All Econo class Apartments", 37 | "View All Normal class Apartments", 38 | "View All Premium class Apartments", 39 | "Book new apartment", 40 | "Remove already booked apartment", 41 | "View Profile", 42 | "Update customer details", 43 | "Delete account\n", 44 | "[red]Sign out[/]"})); 45 | 46 | switch (choise) 47 | { 48 | case "Deposit": 49 | AnsiConsole.Clear(); 50 | await customerActions.DepositAsync(); 51 | break; 52 | case "View Booked Apartments": 53 | AnsiConsole.Clear(); 54 | await customerActions.BookedApartmentsAsync(); 55 | break; 56 | case "View not Booked Apartments": 57 | AnsiConsole.Clear(); 58 | await customerActions.NotBookedApartmentsAsync(); 59 | break; 60 | case "View All Econo class Apartments": 61 | AnsiConsole.Clear(); 62 | await customerActions.GetAllEconoApartmentsAsync(); 63 | break; 64 | case "View All Normal class Apartments": 65 | AnsiConsole.Clear(); 66 | await customerActions.GetAllNormalApartmentsAsync(); 67 | break; 68 | case "View All Premium class Apartments": 69 | AnsiConsole.Clear(); 70 | await customerActions.GetAllPremiumApartmentsAsync(); 71 | break; 72 | case "Book new apartment": 73 | AnsiConsole.Clear(); 74 | await customerActions.BookNewApartmentAsync(); 75 | break; 76 | case "Remove already booked apartment": 77 | AnsiConsole.Clear(); 78 | await customerActions.RemoveBookedApartmentAsync(); 79 | break; 80 | case "View Profile": 81 | AnsiConsole.Clear(); 82 | await customerActions.ViewProfileAsync(); 83 | break; 84 | case "Update customer details": 85 | AnsiConsole.Clear(); 86 | await customerActions.UpdateCustomerDetailsAsync(); 87 | break; 88 | case "Delete account\n": 89 | AnsiConsole.Clear(); 90 | await customerActions.DeleteAccountAsync(); 91 | return; 92 | case "[red]Sign out[/]": 93 | return; 94 | } 95 | } 96 | } 97 | #endregion 98 | } 99 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/AdminPanel/AdminMenu.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.Presentation.SpectreUI.AdminPanel.Actions; 3 | using HotelBookingSystem.Services.Services; 4 | using Spectre.Console; 5 | 6 | namespace HotelBookingSystem.Presentation.SpectreUI.AdminPanel; 7 | 8 | public class AdminMenu 9 | { 10 | private Admin admin; 11 | private AdminActions adminActions; 12 | private AdminService adminService; 13 | private ApartmentService apartmentService; 14 | public AdminMenu(Admin admin, AdminService adminService, ApartmentService apartmentService) 15 | { 16 | this.admin = admin; 17 | this.adminService = adminService; 18 | this.apartmentService = apartmentService; 19 | adminActions = new AdminActions(admin, adminService, apartmentService); 20 | } 21 | 22 | #region Menu 23 | public async Task MenuAsync() 24 | { 25 | while (true) 26 | { 27 | AnsiConsole.Clear(); 28 | var choise = AnsiConsole.Prompt( 29 | new SelectionPrompt() 30 | .Title("Dream[green]House[/][red]/[/]Admin") 31 | .PageSize(4) 32 | .AddChoices(new[] { 33 | "Add new apartment to the Hotel", 34 | "Delete apartment from the Hotel", 35 | "Get Apartment By ID", 36 | "Get All Apartments", 37 | "Get All Customers", 38 | "View Booked Apartments", 39 | "View not Booked Apartments", 40 | "View All Econo class Apartments", 41 | "View All Normal class Apartments", 42 | "View All Premium class Apartments", 43 | "View summary balance of Hotel", 44 | "Update admin password\n", 45 | "[red]Sign out[/]"})); 46 | 47 | switch (choise) 48 | { 49 | case "Add new apartment to the Hotel": 50 | AnsiConsole.Clear(); 51 | await adminActions.AddNewApartmentAsync(); 52 | break; 53 | case "Delete apartment from the Hotel": 54 | AnsiConsole.Clear(); 55 | await adminActions.DeleteApartmentAsync(); 56 | break; 57 | case "Get Apartment By ID": 58 | AnsiConsole.Clear(); 59 | await adminActions.GetApartmentByIdAsync(); 60 | break; 61 | case "Get All Apartments": 62 | AnsiConsole.Clear(); 63 | await adminActions.GetAllApartmentsAsync(); 64 | break; 65 | case "Get All Customers": 66 | AnsiConsole.Clear(); 67 | await adminActions.GetAllCustomersAsync(); 68 | break; 69 | case "View Booked Apartments": 70 | AnsiConsole.Clear(); 71 | await adminActions.BookedApartmentsAsync(); 72 | break; 73 | case "View not Booked Apartments": 74 | AnsiConsole.Clear(); 75 | await adminActions.NotBookedApartmentsAsync(); 76 | break; 77 | case "View All Econo class Apartments": 78 | AnsiConsole.Clear(); 79 | await adminActions.GetAllEconoApartmentsAsync(); 80 | break; 81 | case "View All Normal class Apartments": 82 | AnsiConsole.Clear(); 83 | await adminActions.GetAllNormalApartmentsAsync(); 84 | break; 85 | case "View All Premium class Apartments": 86 | AnsiConsole.Clear(); 87 | await adminActions.GetAllPremiumApartmentsAsync(); 88 | break; 89 | case "View summary balance of Hotel": 90 | AnsiConsole.Clear(); 91 | await adminActions.HotelBalanceAsync(); 92 | break; 93 | case "Update admin password\n": 94 | AnsiConsole.Clear(); 95 | await adminActions.UpdateAdminPasswordAsync(); 96 | return; 97 | case "[red]Sign out[/]": 98 | return; 99 | } 100 | } 101 | } 102 | #endregion 103 | } 104 | -------------------------------------------------------------------------------- /HotelBookingSystem.Service/Services/ApartmentService.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.DTOs.ApartmentModels; 3 | using HotelBookingSystem.Services.Configurations; 4 | using HotelBookingSystem.Services.Extensions; 5 | using HotelBookingSystem.Services.Helpers; 6 | using HotelBookingSystem.Services.Interfaces; 7 | 8 | namespace HotelBookingSystem.Services.Services; 9 | 10 | public class ApartmentService : IApartmentService 11 | { 12 | private List apartments; 13 | 14 | public async ValueTask CreateAsync(ApartmentCreateModel apartment) 15 | { 16 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 17 | 18 | var createdApartment = apartments.Create(apartment.MapTo()); 19 | 20 | await FileIO.WriteAsync(Constants.APARTMENTSPATH, apartments); 21 | 22 | return createdApartment; 23 | } 24 | public async ValueTask DeleteAsync(int id) 25 | { 26 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 27 | 28 | var existApartment = apartments.FirstOrDefault(apartment => apartment.Id == id && !apartment.IsDeleted) 29 | ?? throw new Exception($"Apartment not found with id: {id}"); 30 | 31 | existApartment.IsDeleted = true; 32 | existApartment.DeletedAt = DateTime.Now; 33 | 34 | await FileIO.WriteAsync(Constants.APARTMENTSPATH, apartments); 35 | return true; 36 | } 37 | public async ValueTask GetAsync(int id) 38 | { 39 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 40 | 41 | var existApartment = apartments.FirstOrDefault(apartment => apartment.Id == id && !apartment.IsDeleted) 42 | ?? throw new Exception($"Apartment not found with id: {id}"); 43 | 44 | return existApartment; 45 | } 46 | public async ValueTask> GetAllAsync() 47 | { 48 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 49 | return apartments.Where(apartment => !apartment.IsDeleted).ToList(); 50 | } 51 | public async ValueTask SetOrderedAsync(int apartmentId, int customerId) 52 | { 53 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 54 | 55 | var existApartment = apartments.FirstOrDefault(apartment => apartment.Id == apartmentId && !apartment.IsDeleted) 56 | ?? throw new Exception($"Apartment not found with id: {apartmentId}"); 57 | existApartment.OrderedCustomerId = customerId; 58 | 59 | await FileIO.WriteAsync(Constants.APARTMENTSPATH, apartments); 60 | return true; 61 | } 62 | public async ValueTask SetUnorderedAsync(int apartmentId, int customerId) 63 | { 64 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 65 | 66 | var existApartment = apartments.FirstOrDefault(apartment => apartment.Id == apartmentId && apartment.OrderedCustomerId == customerId && !apartment.IsDeleted) 67 | ?? throw new Exception($"Apartment not found with id: {apartmentId}"); 68 | existApartment.OrderedCustomerId = 0; 69 | 70 | await FileIO.WriteAsync(Constants.APARTMENTSPATH, apartments); 71 | return true; 72 | } 73 | public async ValueTask> BookedApartmentsAsync() 74 | { 75 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 76 | 77 | return apartments.Where(a => a.OrderedCustomerId > 0).ToList(); 78 | } 79 | public async ValueTask> NotBookedApartmentsAsync() 80 | { 81 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 82 | 83 | return apartments.Where(a => a.OrderedCustomerId == 0).ToList(); 84 | } 85 | public async ValueTask> GetAllPremiumAsync() 86 | { 87 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 88 | 89 | return apartments.Where(a => a.ApartmentType == Domain.Enums.ApartmentType.Econo).ToList(); 90 | } 91 | public async ValueTask> GetAllNormalAsync() 92 | { 93 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 94 | 95 | return apartments.Where(a => a.ApartmentType == Domain.Enums.ApartmentType.Normal).ToList(); 96 | } 97 | public async ValueTask> GetAllPreminumAsync() 98 | { 99 | apartments = await FileIO.ReadAsync(Constants.APARTMENTSPATH); 100 | 101 | return apartments.Where(a => a.ApartmentType == Domain.Enums.ApartmentType.Premium).ToList(); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /HotelBookingSystem.Service/Services/CustomerService.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.DTOs.CustomerModels; 3 | using HotelBookingSystem.Services.Configurations; 4 | using HotelBookingSystem.Services.Extensions; 5 | using HotelBookingSystem.Services.Helpers; 6 | using HotelBookingSystem.Services.Interfaces; 7 | 8 | namespace HotelBookingSystem.Services.Services; 9 | 10 | public class CustomerService : ICustomerService 11 | { 12 | private ApartmentService apartmentService; 13 | public CustomerService(ApartmentService apartmentService) 14 | { 15 | this.apartmentService = apartmentService; 16 | } 17 | 18 | private List customers; 19 | 20 | public async ValueTask BookApartmentAsync(int apartmentId, int customerId) 21 | { 22 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 23 | 24 | var existCustomer = customers.FirstOrDefault(customers => customers.Id == customerId && !customers.IsDeleted) 25 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 26 | 27 | var existAparment = await apartmentService.GetAsync(apartmentId) 28 | ?? throw new Exception($"Apartment is not exists with Id: {apartmentId}"); 29 | 30 | if (existAparment.OrderedCustomerId == 0 && existCustomer.ApartmentId == 0) 31 | { 32 | if (existAparment.Price <= existCustomer.Balance) 33 | { 34 | var administration = await FileIO.ReadAsync(Constants.ADMINISTRATIONINFO); 35 | 36 | var admin = administration.FirstOrDefault() 37 | ?? throw new Exception("administration info corrupted, transaction canceled."); 38 | 39 | existCustomer.Balance -= existAparment.Price; 40 | admin.HotelBalanceInfo += existAparment.Price; 41 | 42 | await FileIO.WriteAsync(Constants.ADMINISTRATIONINFO, administration); 43 | 44 | existCustomer.ApartmentId = apartmentId; 45 | 46 | await apartmentService.SetOrderedAsync(existAparment.Id, existCustomer.Id); 47 | } 48 | else 49 | { 50 | throw new Exception("Customer's balance is not enough to book this apartment"); 51 | } 52 | } 53 | else if (existAparment.OrderedCustomerId == customerId) 54 | { 55 | throw new Exception("You are already booked this apartment"); 56 | } 57 | else 58 | { 59 | throw new Exception("Someone has already booked this apartment or you have already booked another one."); 60 | } 61 | 62 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 63 | return existCustomer; 64 | } 65 | public async ValueTask CreateAsync(CustomerCreateModel customer) 66 | { 67 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 68 | 69 | if (customers.Any(c => (c.Username == customer.Username || c.Email == customer.Email) && !c.IsDeleted)) 70 | throw new Exception($"Customer is already exists with username: ({customer.Username}) or email ({customer.Email})"); 71 | 72 | var createdCustomer = customers.Create(customer.MapTo()); 73 | 74 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 75 | return createdCustomer.MapTo(); 76 | } 77 | public async ValueTask DeleteAsync(int customerId) 78 | { 79 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 80 | 81 | var existCustomer = customers.FirstOrDefault(customers => customers.Id == customerId && !customers.IsDeleted) 82 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 83 | 84 | existCustomer.IsDeleted = true; 85 | existCustomer.DeletedAt = DateTime.UtcNow; 86 | 87 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 88 | return true; 89 | } 90 | public async ValueTask DeleteBookingApartmentAsync(int apartmentId, int customerId) 91 | { 92 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 93 | 94 | var existCustomer = customers.FirstOrDefault(customers => customers.Id == customerId && !customers.IsDeleted) 95 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 96 | 97 | var existAparment = await apartmentService.GetAsync(apartmentId) 98 | ?? throw new Exception($"Apartment is not exists with Id: {apartmentId}"); 99 | 100 | try 101 | { 102 | existCustomer.ApartmentId = 0; 103 | await apartmentService.SetUnorderedAsync(apartmentId, customerId); 104 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 105 | } 106 | catch (Exception ex) 107 | { 108 | throw new Exception(ex.Message); 109 | } 110 | return existCustomer; 111 | } 112 | public async ValueTask GetCustomerAsync(int customerId) 113 | { 114 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 115 | 116 | var existCustomer = customers.FirstOrDefault(customer => customer.Id == customerId && !customer.IsDeleted) 117 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 118 | return existCustomer; 119 | } 120 | public async ValueTask GetToLoginAsync(string username, string password) 121 | { 122 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 123 | 124 | var existCustomer = customers.FirstOrDefault(customer => customer.Username == username && PasswordHashing.VerifyPassword(customer.Password, password) && !customer.IsDeleted) 125 | ?? throw new Exception($"Customer is not exists with username or incorrect password: {username}"); 126 | return existCustomer; 127 | } 128 | public async ValueTask UpdateAsync(int customerId, CustomerUpdateModel customer) 129 | { 130 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 131 | 132 | var existCustomer = customers.FirstOrDefault(customer => customer.Id == customerId && !customer.IsDeleted) 133 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 134 | 135 | if (customers.Any(c => c.Id != customerId && c.Username == customer.Username)) 136 | throw new Exception("Someone is using this username already"); 137 | if (customers.Any(c => c.Id != customerId && c.Email == customer.Email)) 138 | throw new Exception("Someone is using this email already"); 139 | 140 | existCustomer.Username = customer.Username; 141 | existCustomer.Password = PasswordHashing.Hashing(customer.Password); 142 | existCustomer.Email = customer.Email; 143 | existCustomer.Firstname = customer.Firstname; 144 | existCustomer.Lastname = customer.Lastname; 145 | existCustomer.UpdatedAt = DateTime.UtcNow; 146 | 147 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 148 | return existCustomer.MapTo(); 149 | } 150 | public async ValueTask ViewCustomerAsync(int customerId) 151 | { 152 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 153 | 154 | var existCustomer = customers.FirstOrDefault(customer => customer.Id == customerId && !customer.IsDeleted) 155 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 156 | return existCustomer.MapTo(); 157 | } 158 | public async ValueTask> GetAllAsync() 159 | { 160 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 161 | return customers.Where(customer => !customer.IsDeleted).ToList(); 162 | } 163 | public async ValueTask DepositAsync(int customerId, double amount) 164 | { 165 | customers = await FileIO.ReadAsync(Constants.CUSTOMERSPATH); 166 | var existCustomer = customers.FirstOrDefault(customer => customer.Id == customerId && !customer.IsDeleted) 167 | ?? throw new Exception($"Customer is not exists with Id: {customerId}"); 168 | existCustomer.Balance += amount; 169 | await FileIO.WriteAsync(Constants.CUSTOMERSPATH, customers); 170 | return existCustomer; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/AdminPanel/Actions/AdminActions.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.DTOs.ApartmentModels; 3 | using HotelBookingSystem.Services.Services; 4 | using Spectre.Console; 5 | 6 | namespace HotelBookingSystem.Presentation.SpectreUI.AdminPanel.Actions; 7 | 8 | public class AdminActions 9 | { 10 | public AdminActions(Admin admin, AdminService adminService, ApartmentService apartmentService) 11 | { 12 | this.admin = admin; 13 | this.adminService = adminService; 14 | this.apartmentService = apartmentService; 15 | 16 | } 17 | 18 | private Admin admin; 19 | private AdminService adminService; 20 | private ApartmentService apartmentService; 21 | 22 | #region Add new Apartment to the Hotel 23 | public async Task AddNewApartmentAsync() 24 | { 25 | ApartmentCreateModel model = new ApartmentCreateModel(); 26 | var price = AnsiConsole.Ask("Enter [green]Price[/]:"); 27 | var countOfRooms = AnsiConsole.Ask("Enter [green]Count of rooms[/]:"); 28 | AnsiConsole.Markup("Apartment Type \n" + 29 | "---------------\n" + 30 | "1. Econo\n" + 31 | "2. Normal\n" + 32 | "3. Premium\n" + 33 | "---------------\n"); 34 | again: 35 | var type = AnsiConsole.Ask("Choose [green]Apartment Type[/]:"); 36 | switch (type) 37 | { 38 | case 1: 39 | model.ApartmentType = Domain.Enums.ApartmentType.Econo; 40 | break; 41 | case 2: 42 | model.ApartmentType = Domain.Enums.ApartmentType.Normal; 43 | break; 44 | case 3: 45 | model.ApartmentType = Domain.Enums.ApartmentType.Premium; 46 | break; 47 | default: 48 | AnsiConsole.MarkupLine("[red]Invalid choose[/] press any key to try again..."); 49 | Console.ReadLine(); 50 | goto again; 51 | } 52 | 53 | model.CountOfRooms = countOfRooms; 54 | model.Price = price; 55 | try 56 | { 57 | Apartment created = await apartmentService.CreateAsync(model); 58 | 59 | var table = new Table(); 60 | 61 | table.AddColumn("[yellow]Created Apartment[/]"); 62 | 63 | table.AddRow($"[green]Apartment ID[/]: {created.Id}"); 64 | table.AddRow($"[green]Type[/]: {created.ApartmentType}"); 65 | table.AddRow($"[green]Price[/]: {created.Price}"); 66 | table.AddRow($"[green]Count of rooms[/]: {created.CountOfRooms}"); 67 | 68 | AnsiConsole.Write(table); 69 | AnsiConsole.WriteLine("Press any key to exit..."); 70 | Console.ReadLine(); 71 | } 72 | catch (Exception ex) 73 | { 74 | Console.Clear(); 75 | Console.WriteLine(ex.Message); 76 | AnsiConsole.WriteLine("Press any key to exit and try again."); 77 | Console.ReadLine(); 78 | AnsiConsole.Clear(); 79 | return; 80 | } 81 | } 82 | #endregion 83 | 84 | #region Delete Apartment from the hotel 85 | public async Task DeleteApartmentAsync() 86 | { 87 | var id = AnsiConsole.Ask("Enter [green]ApartmentID[/]:"); 88 | try 89 | { 90 | AnsiConsole.Clear(); 91 | await apartmentService.DeleteAsync(id); 92 | AnsiConsole.MarkupLine("[green]Apartment Deleted[/] Press enter to exit..."); 93 | Console.ReadLine(); 94 | AnsiConsole.Clear(); 95 | return; 96 | } 97 | catch (Exception ex) 98 | { 99 | Console.Clear(); 100 | Console.WriteLine(ex.Message); 101 | AnsiConsole.WriteLine("Press any key to exit..."); 102 | Console.ReadLine(); 103 | AnsiConsole.Clear(); 104 | return; 105 | } 106 | } 107 | #endregion 108 | 109 | #region Get Apartment by ID 110 | public async Task GetApartmentByIdAsync() 111 | { 112 | var id = AnsiConsole.Ask("Enter [green]ApartmentID[/]:"); 113 | try 114 | { 115 | AnsiConsole.Clear(); 116 | var apartment = await adminService.GetApartmentByIdAsync(id); 117 | var table = new Table(); 118 | 119 | table.AddColumn("[yellow]Apartment[/]"); 120 | 121 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 122 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 123 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 124 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 125 | 126 | AnsiConsole.Write(table); 127 | 128 | AnsiConsole.MarkupLine("Press enter to exit..."); 129 | Console.ReadLine(); 130 | AnsiConsole.Clear(); 131 | return; 132 | } 133 | catch (Exception ex) 134 | { 135 | Console.Clear(); 136 | Console.WriteLine(ex.Message); 137 | AnsiConsole.WriteLine("Press any enter to exit..."); 138 | Console.ReadLine(); 139 | AnsiConsole.Clear(); 140 | return; 141 | } 142 | } 143 | #endregion 144 | 145 | #region Get All Aparments 146 | public async Task GetAllApartmentsAsync() 147 | { 148 | var apartments = await adminService.GetAllApartmentsAsync(); 149 | if (apartments.Count == 0) 150 | { 151 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 152 | Console.ReadLine(); 153 | } 154 | else 155 | { 156 | foreach (var apartment in apartments) 157 | { 158 | var table = new Table(); 159 | 160 | table.AddColumn("[yellow]Apartment[/]"); 161 | 162 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 163 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 164 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 165 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 166 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 167 | 168 | AnsiConsole.Write(table); 169 | } 170 | AnsiConsole.WriteLine("Press any key to exit..."); 171 | Console.ReadLine(); 172 | } 173 | } 174 | #endregion 175 | 176 | #region Get All Customers 177 | public async Task GetAllCustomersAsync() 178 | { 179 | var customers = await adminService.GetAllCustomersAsync(); 180 | if (customers.Count == 0) 181 | { 182 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have customers.[/]\nPress any key to exit..."); 183 | Console.ReadLine(); 184 | } 185 | else 186 | { 187 | foreach (var customer in customers) 188 | { 189 | var table = new Table(); 190 | table.AddColumn("[yellow]Your Profile[/]"); 191 | 192 | table.AddRow($"[green]Cusomer ID[/]: {customer.Id}"); 193 | table.AddRow($"[green]Username[/]: {customer.Username}"); 194 | table.AddRow($"[green]Email[/]: {customer.Email}"); 195 | table.AddRow($"[green]Firstname[/]: {customer.Firstname}"); 196 | table.AddRow($"[green]Lastname[/]: {customer.Lastname}"); 197 | table.AddRow($"[green]Booked Apartment ID[/]: {customer.ApartmentId}"); 198 | 199 | AnsiConsole.Write(table); 200 | } 201 | AnsiConsole.WriteLine("Press any key to exit..."); 202 | Console.ReadLine(); 203 | } 204 | } 205 | #endregion 206 | 207 | #region Get All Econo Class Apartments 208 | public async Task GetAllEconoApartmentsAsync() 209 | { 210 | var apartments = await apartmentService.GetAllPremiumAsync(); 211 | if (apartments.Count == 0) 212 | { 213 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 214 | Console.ReadLine(); 215 | } 216 | else 217 | { 218 | foreach (var apartment in apartments) 219 | { 220 | if (apartment.OrderedCustomerId == 0) 221 | { 222 | var table = new Table(); 223 | 224 | table.AddColumn("[yellow]Apartment[/]"); 225 | 226 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 227 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 228 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 229 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 230 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 231 | 232 | AnsiConsole.Write(table); 233 | } 234 | else 235 | { 236 | var table = new Table(); 237 | 238 | table.AddColumn("[yellow]Apartment[/]"); 239 | 240 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 241 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 242 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 243 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 244 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 245 | 246 | AnsiConsole.Write(table); 247 | } 248 | 249 | } 250 | AnsiConsole.WriteLine("Press any key to exit..."); 251 | Console.ReadLine(); 252 | } 253 | } 254 | #endregion 255 | 256 | #region Get All Normal Class Apartment 257 | public async Task GetAllNormalApartmentsAsync() 258 | { 259 | var apartments = await apartmentService.GetAllNormalAsync(); 260 | if (apartments.Count == 0) 261 | { 262 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 263 | Console.ReadLine(); 264 | } 265 | else 266 | { 267 | foreach (var apartment in apartments) 268 | { 269 | 270 | if (apartment.OrderedCustomerId == 0) 271 | { 272 | var table = new Table(); 273 | 274 | table.AddColumn("[yellow]Apartment[/]"); 275 | 276 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 277 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 278 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 279 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 280 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 281 | 282 | AnsiConsole.Write(table); 283 | } 284 | else 285 | { 286 | var table = new Table(); 287 | 288 | table.AddColumn("[yellow]Apartment[/]"); 289 | 290 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 291 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 292 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 293 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 294 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 295 | 296 | AnsiConsole.Write(table); 297 | } 298 | } 299 | AnsiConsole.WriteLine("Press any key to exit..."); 300 | Console.ReadLine(); 301 | } 302 | } 303 | #endregion 304 | 305 | #region Get All Premium Class Apartments 306 | public async Task GetAllPremiumApartmentsAsync() 307 | { 308 | var apartments = await apartmentService.GetAllPremiumAsync(); 309 | if (apartments.Count == 0) 310 | { 311 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 312 | Console.ReadLine(); 313 | } 314 | else 315 | { 316 | foreach (var apartment in apartments) 317 | { 318 | 319 | if (apartment.OrderedCustomerId == 0) 320 | { 321 | var table = new Table(); 322 | 323 | table.AddColumn("[yellow]Apartment[/]"); 324 | 325 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 326 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 327 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 328 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 329 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 330 | 331 | AnsiConsole.Write(table); 332 | } 333 | else 334 | { 335 | var table = new Table(); 336 | 337 | table.AddColumn("[yellow]Apartment[/]"); 338 | 339 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 340 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 341 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 342 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 343 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 344 | 345 | AnsiConsole.Write(table); 346 | } 347 | } 348 | AnsiConsole.WriteLine("Press any key to exit..."); 349 | Console.ReadLine(); 350 | } 351 | } 352 | #endregion 353 | 354 | #region Booked Apartments 355 | public async Task BookedApartmentsAsync() 356 | { 357 | var apartments = await apartmentService.BookedApartmentsAsync(); 358 | if (apartments.Count == 0) 359 | { 360 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 361 | Console.ReadLine(); 362 | } 363 | else 364 | { 365 | foreach (var apartment in apartments) 366 | { 367 | var table = new Table(); 368 | 369 | table.AddColumn("[yellow]Apartment[/]"); 370 | 371 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 372 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 373 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 374 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 375 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 376 | 377 | AnsiConsole.Write(table); 378 | } 379 | AnsiConsole.WriteLine("Press any key to exit..."); 380 | Console.ReadLine(); 381 | } 382 | } 383 | #endregion 384 | 385 | #region Not Booked Apartments 386 | public async Task NotBookedApartmentsAsync() 387 | { 388 | var apartments = await apartmentService.NotBookedApartmentsAsync(); 389 | if (apartments.Count == 0) 390 | { 391 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 392 | Console.ReadLine(); 393 | } 394 | else 395 | { 396 | foreach (var apartment in apartments) 397 | { 398 | var table = new Table(); 399 | 400 | table.AddColumn("[yellow]Apartment[/]"); 401 | 402 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 403 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 404 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 405 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 406 | 407 | AnsiConsole.Write(table); 408 | } 409 | AnsiConsole.WriteLine("Press any key to exit..."); 410 | Console.ReadLine(); 411 | } 412 | } 413 | #endregion 414 | 415 | #region Hotel's Summary Balance 416 | public async Task HotelBalanceAsync() 417 | { 418 | AnsiConsole.Clear(); 419 | var balance = await adminService.HotelBalanceInfoAsync(); 420 | var table = new Table(); 421 | 422 | table.AddColumn("[yellow]Hotel[/]"); 423 | 424 | table.AddRow($"[green]Summary Balance ($)[/]: {balance}"); 425 | 426 | AnsiConsole.Write(table); 427 | 428 | AnsiConsole.MarkupLine("Press enter to exit..."); 429 | Console.ReadLine(); 430 | AnsiConsole.Clear(); 431 | return; 432 | } 433 | #endregion 434 | 435 | #region Update Admin Password 436 | public async Task UpdateAdminPasswordAsync() 437 | { 438 | var adminmodel = new Admin(); 439 | reenterpassword: 440 | var password = AnsiConsole.Prompt( 441 | new TextPrompt("Enter your [green]password[/]:") 442 | .PromptStyle("yellow") 443 | .Secret()); 444 | while (password.Length < 8) 445 | { 446 | AnsiConsole.WriteLine("Password's length must be at least 8 characters"); 447 | goto reenterpassword; 448 | } 449 | try 450 | { 451 | adminmodel.Password = password; 452 | admin = await adminService.UpdatePasswordAsync(adminmodel); 453 | AnsiConsole.MarkupLine("[green]Password Changed[/] Press enter to exit..."); 454 | Console.ReadLine(); 455 | AnsiConsole.Clear(); 456 | return; 457 | } 458 | catch (Exception ex) 459 | { 460 | Console.Clear(); 461 | Console.WriteLine(ex.Message); 462 | AnsiConsole.WriteLine("Press any key to exit..."); 463 | Console.ReadLine(); 464 | AnsiConsole.Clear(); 465 | return; 466 | } 467 | 468 | } 469 | #endregion 470 | } 471 | -------------------------------------------------------------------------------- /HotelBookingSystem.Presentation/SpectreUI/CustomerPanel/Actions/CustomerActions.cs: -------------------------------------------------------------------------------- 1 | using HotelBookingSystem.Domain.Entities; 2 | using HotelBookingSystem.DTOs.CustomerModels; 3 | using HotelBookingSystem.Services.Extensions; 4 | using HotelBookingSystem.Services.Services; 5 | using Spectre.Console; 6 | using System.Text.RegularExpressions; 7 | 8 | namespace HotelBookingSystem.Presentation.SpectreUI.CustomerPanel.Actions; 9 | 10 | public class CustomerActions 11 | { 12 | private Customer Customer; 13 | private CustomerService customerService; 14 | private ApartmentService apartmentService; 15 | public CustomerActions(Customer customer, CustomerService customerService, ApartmentService apartmentService) 16 | { 17 | Customer = customer; 18 | this.customerService = customerService; 19 | this.apartmentService = apartmentService; 20 | } 21 | 22 | #region Deposit 23 | public async Task DepositAsync() 24 | { 25 | var amount = AnsiConsole.Ask("Enter [green]amount[/]: "); 26 | await AnsiConsole.Status() 27 | .Start("Process...", async ctx => 28 | { 29 | AnsiConsole.MarkupLine("loading services..."); 30 | try 31 | { 32 | Customer = await customerService.DepositAsync(Customer.Id, amount); 33 | } 34 | catch (Exception ex) 35 | { 36 | AnsiConsole.WriteLine(ex.Message); 37 | } 38 | Thread.Sleep(1000); 39 | AnsiConsole.Clear(); 40 | }); 41 | AnsiConsole.MarkupLine("[green]Done[/] Press any key to continue..."); 42 | Console.ReadLine(); 43 | } 44 | #endregion 45 | 46 | #region View Booked Apartments 47 | public async Task BookedApartmentsAsync() 48 | { 49 | var apartments = await apartmentService.BookedApartmentsAsync(); 50 | if (apartments.Count == 0) 51 | { 52 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 53 | Console.ReadLine(); 54 | } 55 | else 56 | { 57 | foreach (var apartment in apartments) 58 | { 59 | var table = new Table(); 60 | 61 | table.AddColumn("[yellow]Apartment[/]"); 62 | 63 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 64 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 65 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 66 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 67 | 68 | AnsiConsole.Write(table); 69 | } 70 | AnsiConsole.WriteLine("Press any key to exit..."); 71 | Console.ReadLine(); 72 | } 73 | } 74 | #endregion 75 | 76 | #region View Not Booked Apartments 77 | public async Task NotBookedApartmentsAsync() 78 | { 79 | var apartments = await apartmentService.NotBookedApartmentsAsync(); 80 | if (apartments.Count == 0) 81 | { 82 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 83 | Console.ReadLine(); 84 | } 85 | else 86 | { 87 | foreach (var apartment in apartments) 88 | { 89 | var table = new Table(); 90 | 91 | table.AddColumn("[yellow]Apartment[/]"); 92 | 93 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 94 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 95 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 96 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 97 | 98 | AnsiConsole.Write(table); 99 | } 100 | AnsiConsole.WriteLine("Press any key to exit..."); 101 | Console.ReadLine(); 102 | } 103 | } 104 | #endregion 105 | 106 | #region Book New Apartment 107 | public async Task BookNewApartmentAsync() 108 | { 109 | var apartmentId = AnsiConsole.Ask("Enter [green]apartment ID[/]: "); 110 | await AnsiConsole.Status() 111 | .Start("Process...", async ctx => 112 | { 113 | AnsiConsole.MarkupLine("loading services..."); 114 | try 115 | { 116 | AnsiConsole.Clear(); 117 | Customer = await customerService.BookApartmentAsync(apartmentId, Customer.Id); 118 | AnsiConsole.MarkupLine("[green]You Booked a new apartment[/] Press any key to continue..."); 119 | Console.ReadLine(); 120 | } 121 | catch (Exception ex) 122 | { 123 | Console.Clear(); 124 | Console.WriteLine(ex.Message); 125 | AnsiConsole.WriteLine("Press any key to exit and try again."); 126 | Console.ReadLine(); 127 | AnsiConsole.Clear(); 128 | return; 129 | } 130 | AnsiConsole.Clear(); 131 | }); 132 | } 133 | #endregion 134 | 135 | #region Get All Econo Class Apartments 136 | public async Task GetAllEconoApartmentsAsync() 137 | { 138 | var apartments = await apartmentService.GetAllPremiumAsync(); 139 | if (apartments.Count == 0) 140 | { 141 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 142 | Console.ReadLine(); 143 | } 144 | else 145 | { 146 | foreach (var apartment in apartments) 147 | { 148 | if (apartment.OrderedCustomerId == 0) 149 | { 150 | var table = new Table(); 151 | 152 | table.AddColumn("[yellow]Apartment[/]"); 153 | 154 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 155 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 156 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 157 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 158 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 159 | 160 | AnsiConsole.Write(table); 161 | } 162 | else 163 | { 164 | var table = new Table(); 165 | 166 | table.AddColumn("[yellow]Apartment[/]"); 167 | 168 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 169 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 170 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 171 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 172 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 173 | 174 | AnsiConsole.Write(table); 175 | } 176 | 177 | } 178 | AnsiConsole.WriteLine("Press any key to exit..."); 179 | Console.ReadLine(); 180 | } 181 | } 182 | #endregion 183 | 184 | #region Get All Normal Class Apartment 185 | public async Task GetAllNormalApartmentsAsync() 186 | { 187 | var apartments = await apartmentService.GetAllNormalAsync(); 188 | if (apartments.Count == 0) 189 | { 190 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 191 | Console.ReadLine(); 192 | } 193 | else 194 | { 195 | foreach (var apartment in apartments) 196 | { 197 | 198 | if (apartment.OrderedCustomerId == 0) 199 | { 200 | var table = new Table(); 201 | 202 | table.AddColumn("[yellow]Apartment[/]"); 203 | 204 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 205 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 206 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 207 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 208 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 209 | 210 | AnsiConsole.Write(table); 211 | } 212 | else 213 | { 214 | var table = new Table(); 215 | 216 | table.AddColumn("[yellow]Apartment[/]"); 217 | 218 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 219 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 220 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 221 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 222 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 223 | 224 | AnsiConsole.Write(table); 225 | } 226 | } 227 | AnsiConsole.WriteLine("Press any key to exit..."); 228 | Console.ReadLine(); 229 | } 230 | } 231 | #endregion 232 | 233 | #region Get All Premium Class Apartments 234 | public async Task GetAllPremiumApartmentsAsync() 235 | { 236 | var apartments = await apartmentService.GetAllPremiumAsync(); 237 | if (apartments.Count == 0) 238 | { 239 | AnsiConsole.MarkupLine("[yellow]The hotel does not yet have apartments.[/]\nPress any key to exit..."); 240 | Console.ReadLine(); 241 | } 242 | else 243 | { 244 | foreach (var apartment in apartments) 245 | { 246 | 247 | if (apartment.OrderedCustomerId == 0) 248 | { 249 | var table = new Table(); 250 | 251 | table.AddColumn("[yellow]Apartment[/]"); 252 | 253 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 254 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 255 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 256 | table.AddRow($"[green]Ordered CustomerID[/]: {"Not Booked Yet"}"); 257 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 258 | 259 | AnsiConsole.Write(table); 260 | } 261 | else 262 | { 263 | var table = new Table(); 264 | 265 | table.AddColumn("[yellow]Apartment[/]"); 266 | 267 | table.AddRow($"[green]Apartment ID[/]: {apartment.Id}"); 268 | table.AddRow($"[green]Type[/]: {apartment.ApartmentType}"); 269 | table.AddRow($"[green]Price[/]: {apartment.Price}"); 270 | table.AddRow($"[green]Ordered CustomerID[/]: {apartment.OrderedCustomerId}"); 271 | table.AddRow($"[green]Count of rooms[/]: {apartment.CountOfRooms}"); 272 | 273 | AnsiConsole.Write(table); 274 | } 275 | } 276 | AnsiConsole.WriteLine("Press any key to exit..."); 277 | Console.ReadLine(); 278 | } 279 | } 280 | #endregion 281 | 282 | #region Remove Booked Apartment 283 | public async Task RemoveBookedApartmentAsync() 284 | { 285 | reenter: 286 | var mapped = Customer.MapTo(); 287 | var table = new Table(); 288 | 289 | table.AddColumn("[yellow]Your Profile[/]"); 290 | 291 | table.AddRow($"[green]Cusomer ID[/]: {mapped.Id}"); 292 | table.AddRow($"[green]Username[/]: {mapped.Username}"); 293 | table.AddRow($"[green]Email[/]: {mapped.Email}"); 294 | table.AddRow($"[green]Balance ($)[/]: {mapped.Balance}"); 295 | table.AddRow($"[green]Firstname[/]: {mapped.Firstname}"); 296 | table.AddRow($"[green]Lastname[/]: {mapped.Lastname}"); 297 | table.AddRow($"[green]Booked Apartment ID[/]: {mapped.ApartmentId}"); 298 | 299 | AnsiConsole.Write(table); 300 | 301 | if (mapped.ApartmentId != 0) 302 | { 303 | AnsiConsole.WriteLine($"Are you sure you want to remove Booked Apartment with ID: {mapped.ApartmentId}?..."); 304 | AnsiConsole.Write("Press (yes) to confirm, (no) to cancel:"); 305 | string choice = Console.ReadLine(); 306 | switch (choice) 307 | { 308 | case "yes": 309 | try 310 | { 311 | Customer = await customerService.DeleteBookingApartmentAsync(mapped.ApartmentId, mapped.Id); 312 | } 313 | catch (Exception ex) 314 | { 315 | Console.Clear(); 316 | Console.WriteLine(ex.Message); 317 | AnsiConsole.WriteLine("Press any key to exit and try again."); 318 | Console.ReadLine(); 319 | AnsiConsole.Clear(); 320 | return; 321 | } 322 | break; 323 | case "no": 324 | AnsiConsole.Clear(); 325 | AnsiConsole.MarkupLine("[green]Canceled[/]"); 326 | Thread.Sleep(1000); 327 | return; 328 | default: 329 | Console.WriteLine("invalid input"); 330 | await Console.Out.WriteLineAsync("Press any key to reenter..."); 331 | Console.ReadLine(); 332 | goto reenter; 333 | } 334 | } 335 | else 336 | { 337 | AnsiConsole.WriteLine($"You are not booked any apartment yet."); 338 | AnsiConsole.WriteLine("Press any key."); 339 | Console.ReadLine(); 340 | AnsiConsole.Clear(); 341 | return; 342 | } 343 | } 344 | #endregion 345 | 346 | #region View Profile 347 | public async Task ViewProfileAsync() 348 | { 349 | var customerView = await customerService.ViewCustomerAsync(Customer.Id); 350 | var table = new Table(); 351 | if (customerView.ApartmentId != 0) 352 | { 353 | table.AddColumn("[yellow]Your Profile[/]"); 354 | 355 | table.AddRow($"[green]Cusomer ID[/]: {customerView.Id}"); 356 | table.AddRow($"[green]Username[/]: {customerView.Username}"); 357 | table.AddRow($"[green]Email[/]: {customerView.Email}"); 358 | table.AddRow($"[green]Balance ($)[/]: {customerView.Balance}"); 359 | table.AddRow($"[green]Firstname[/]: {customerView.Firstname}"); 360 | table.AddRow($"[green]Lastname[/]: {customerView.Lastname}"); 361 | table.AddRow($"[green]Booked Apartment ID[/]: {customerView.ApartmentId}"); 362 | 363 | AnsiConsole.Write(table); 364 | AnsiConsole.WriteLine("Press any key to exit..."); 365 | Console.ReadLine(); 366 | } 367 | else 368 | { 369 | table.AddColumn("[yellow]Your Profile[/]"); 370 | 371 | table.AddRow($"[green]Cusomer ID[/]: {customerView.Id}"); 372 | table.AddRow($"[green]Username[/]: {customerView.Username}"); 373 | table.AddRow($"[green]Email[/]: {customerView.Email}"); 374 | table.AddRow($"[green]Balance ($)[/]: {customerView.Balance}"); 375 | table.AddRow($"[green]Firstname[/]: {customerView.Firstname}"); 376 | table.AddRow($"[green]Lastname[/]: {customerView.Lastname}"); 377 | table.AddRow($"[green]Booked Apartment ID[/]: {"Not ordered yet"}"); 378 | 379 | AnsiConsole.Write(table); 380 | AnsiConsole.WriteLine("Press any key to exit..."); 381 | Console.ReadLine(); 382 | } 383 | } 384 | #endregion 385 | 386 | #region Update Customer Details 387 | public async Task UpdateCustomerDetailsAsync() 388 | { 389 | CustomerUpdateModel customerUpdate = new CustomerUpdateModel(); 390 | 391 | var username = AnsiConsole.Ask("Enter your [green]username[/]:"); 392 | reenterpassword: 393 | var password = AnsiConsole.Prompt( 394 | new TextPrompt("Enter your [green]password[/]:") 395 | .PromptStyle("yellow") 396 | .Secret()); 397 | while (password.Length < 8) 398 | { 399 | AnsiConsole.WriteLine("Password's length must be at least 8 characters"); 400 | goto reenterpassword; 401 | } 402 | string email = string.Empty; 403 | while (string.IsNullOrWhiteSpace(email = AnsiConsole.Ask("Enter your [green]email[/]")) || !Regex.IsMatch(email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")) 404 | { 405 | Console.WriteLine("Invalid email address!"); 406 | } 407 | string firstname = AnsiConsole.Ask("Enter your [green]Firstname[/]"); 408 | string lastname = AnsiConsole.Ask("Enter your [green]Lastname[/]"); 409 | 410 | customerUpdate.Username = username; 411 | customerUpdate.Password = password; 412 | customerUpdate.Email = email; 413 | customerUpdate.Firstname = firstname; 414 | customerUpdate.Lastname = lastname; 415 | 416 | try 417 | { 418 | await customerService.UpdateAsync(Customer.Id, customerUpdate); 419 | Customer = await customerService.GetCustomerAsync(Customer.Id); 420 | AnsiConsole.MarkupLine("[green]Success[/] Press any key to continue..."); 421 | Console.ReadLine(); 422 | } 423 | catch (Exception ex) 424 | { 425 | Console.Clear(); 426 | Console.WriteLine(ex.Message); 427 | AnsiConsole.WriteLine("Press any key to exit..."); 428 | Console.ReadLine(); 429 | AnsiConsole.Clear(); 430 | return; 431 | } 432 | } 433 | #endregion 434 | 435 | #region Delete Account 436 | public async Task DeleteAccountAsync() 437 | { 438 | reenter: 439 | AnsiConsole.WriteLine($"Are you sure you want to delete your account with username: {Customer.Username}?..."); 440 | AnsiConsole.Write("Press (yes) to confirm, (no) to cancel:"); 441 | string choice = Console.ReadLine(); 442 | switch (choice) 443 | { 444 | case "yes": 445 | try 446 | { 447 | AnsiConsole.Clear(); 448 | await customerService.DeleteAsync(Customer.Id); 449 | AnsiConsole.MarkupLine("[green]Success[/]Press any key to exit..."); 450 | Console.ReadLine(); 451 | AnsiConsole.Clear(); 452 | return; 453 | } 454 | catch (Exception ex) 455 | { 456 | Console.Clear(); 457 | Console.WriteLine(ex.Message); 458 | AnsiConsole.WriteLine("Press any key to exit..."); 459 | Console.ReadLine(); 460 | AnsiConsole.Clear(); 461 | return; 462 | } 463 | case "no": 464 | AnsiConsole.Clear(); 465 | AnsiConsole.MarkupLine("[green]Canceled[/]"); 466 | Thread.Sleep(1000); 467 | return; 468 | default: 469 | Console.WriteLine("invalid input"); 470 | await Console.Out.WriteLineAsync("Press any key to reenter..."); 471 | Console.ReadLine(); 472 | goto reenter; 473 | } 474 | } 475 | #endregion 476 | } 477 | --------------------------------------------------------------------------------