diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index cc9d978..f7036d1 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelCont EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{66786012-F68B-4515-9C19-4C97049F9C49}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDatabaseImplement", "HotelDatabaseImplement\HotelDatabaseImplement.csproj", "{90B9109F-0F4A-4940-A45F-37839F2F773B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {66786012-F68B-4515-9C19-4C97049F9C49}.Debug|Any CPU.Build.0 = Debug|Any CPU {66786012-F68B-4515-9C19-4C97049F9C49}.Release|Any CPU.ActiveCfg = Release|Any CPU {66786012-F68B-4515-9C19-4C97049F9C49}.Release|Any CPU.Build.0 = Release|Any CPU + {90B9109F-0F4A-4940-A45F-37839F2F773B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90B9109F-0F4A-4940-A45F-37839F2F773B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90B9109F-0F4A-4940-A45F-37839F2F773B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90B9109F-0F4A-4940-A45F-37839F2F773B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelDatabaseImplement/HotelDataBase.cs b/Hotel/HotelDatabaseImplement/HotelDataBase.cs new file mode 100644 index 0000000..6e77968 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/HotelDataBase.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using HotelDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement +{ + public class HotelDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=TestProject;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Bookings { get; set; } + public virtual DbSet Clients { get; set; } + public virtual DbSet Posts { get; set; } + public virtual DbSet Rooms { get; set; } + public virtual DbSet Workers { get; set; } + } +} diff --git a/Hotel/HotelDatabaseImplement/HotelDatabaseImplement.csproj b/Hotel/HotelDatabaseImplement/HotelDatabaseImplement.csproj new file mode 100644 index 0000000..c406d9b --- /dev/null +++ b/Hotel/HotelDatabaseImplement/HotelDatabaseImplement.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + diff --git a/Hotel/HotelDatabaseImplement/Implements/BookingStorage.cs b/Hotel/HotelDatabaseImplement/Implements/BookingStorage.cs new file mode 100644 index 0000000..2d8ac2f --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Implements/BookingStorage.cs @@ -0,0 +1,17 @@ +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Implements +{ + public class BookingStorage : IBookingStorage + { + + } +} diff --git a/Hotel/HotelDatabaseImplement/Implements/ClientStorage.cs b/Hotel/HotelDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..74ab6c7 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,13 @@ +using HotelContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + } +} diff --git a/Hotel/HotelDatabaseImplement/Implements/PostStorage.cs b/Hotel/HotelDatabaseImplement/Implements/PostStorage.cs new file mode 100644 index 0000000..2a2a416 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Implements/PostStorage.cs @@ -0,0 +1,13 @@ +using HotelContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Implements +{ + public class PostStorage : IPostStorage + { + } +} diff --git a/Hotel/HotelDatabaseImplement/Implements/RoomStorage.cs b/Hotel/HotelDatabaseImplement/Implements/RoomStorage.cs new file mode 100644 index 0000000..c33a631 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Implements/RoomStorage.cs @@ -0,0 +1,13 @@ +using HotelContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Implements +{ + public class RoomStorage : IRoomStorage + { + } +} diff --git a/Hotel/HotelDatabaseImplement/Implements/WorkerStorage.cs b/Hotel/HotelDatabaseImplement/Implements/WorkerStorage.cs new file mode 100644 index 0000000..31adada --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Implements/WorkerStorage.cs @@ -0,0 +1,13 @@ +using HotelContracts.StoragesContracts; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Implements +{ + public class WorkerStorage : IWorkerStorage + { + } +} diff --git a/Hotel/HotelDatabaseImplement/Models/Booking.cs b/Hotel/HotelDatabaseImplement/Models/Booking.cs new file mode 100644 index 0000000..27bf1a9 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Models/Booking.cs @@ -0,0 +1,70 @@ +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Enums; +using HotelDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Models +{ + public class Booking : IBookingModel + { + [Required] + public int RoomId { get; set; } + [Required] + public int ClientId { get; set; } + [Required] + public DateTime ArrivalDate { get; set; } + [Required] + public DateTime DepartureDate { get; set; } + [Required] + public int NumberHoursSpent { get; set; } + [Required] + public AcceptanceStatus Status { get; set; } + [Required] + public int TotalCost { get; set; } + [Required] + public int Id { get; set; } + public static Booking Create(BookingBindingModel model) + { + return new Booking() + { + Id = model.Id, + RoomId = model.RoomId, + ClientId = model.ClientId, + ArrivalDate = model.ArrivalDate, + DepartureDate = model.DepartureDate, + NumberHoursSpent = model.NumberHoursSpent, + Status = model.Status, + TotalCost = model.TotalCost, + }; + } + public void Update(BookingBindingModel model) + { + if (model == null) return; + Id = model.Id; + RoomId = model.RoomId; + ClientId = model.ClientId; + ArrivalDate = model.ArrivalDate; + DepartureDate = model.DepartureDate; + NumberHoursSpent = model.NumberHoursSpent; + Status = model.Status; + TotalCost = model.TotalCost; + } + public BookingViewModel GetViewModel => new() + { + Id = Id, + RoomId = RoomId, + ClientId = ClientId, + ArrivalDate = ArrivalDate, + DepartureDate = DepartureDate, + NumberHoursSpent = NumberHoursSpent, + Status = Status, + TotalCost = TotalCost + }; + } +} diff --git a/Hotel/HotelDatabaseImplement/Models/Client.cs b/Hotel/HotelDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..5929f7f --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Models/Client.cs @@ -0,0 +1,59 @@ +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Models +{ + public class Client : IClientModel + { + [Required] + public string Name { get; set; } = string.Empty; + [Required] + public string Surname { get; set; } = string.Empty; + [Required] + public DateTime DateOfBirth { get; set; } + [Required] + public string PhoneNumber { get; set; } = string.Empty; + [Required] + public string Password { get; set; } = string.Empty; + + public int Id { get; set; } + public static Client Create(HotelDatabase context, ClientBindingModel model) + { + return new Client() + { + Id = model.Id, + Name = model.Name, + Surname = model.Surname, + DateOfBirth = model.DateOfBirth, + PhoneNumber = model.PhoneNumber, + Password = model.Password, + }; + } + public void Update(ClientBindingModel model) + { + if (model == null) return; + Id = model.Id; + Name = model.Name; + Surname = model.Surname; + DateOfBirth = model.DateOfBirth; + PhoneNumber = model.PhoneNumber; + Password = model.Password; + } + public ClientViewModel GetViewModel => new() + { + Id = Id, + Name = Name, + Surname = Surname, + DateOfBirth = DateOfBirth, + PhoneNumber = PhoneNumber, + Password = Password + }; + } +} diff --git a/Hotel/HotelDatabaseImplement/Models/Post.cs b/Hotel/HotelDatabaseImplement/Models/Post.cs new file mode 100644 index 0000000..47714db --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Models/Post.cs @@ -0,0 +1,43 @@ +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Models +{ + public class Post : IPostModel + { + [Required] + public string PostName { get; set; } = string.Empty; + + public int Id { get; set; } + public static Post? Create(PostBindingModel model) + { + if (model == null) return null; + return new Post() + { + Id = model.Id, + PostName = model.PostName + }; + } + + public void Update(PostBindingModel model) + { + if (model == null) return; + Id = model.Id; + PostName = model.PostName; + } + + public PostViewModel GetViewModel => new() + { + Id = Id, + PostName = PostName + }; + } +} diff --git a/Hotel/HotelDatabaseImplement/Models/Room.cs b/Hotel/HotelDatabaseImplement/Models/Room.cs new file mode 100644 index 0000000..c95adb5 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Models/Room.cs @@ -0,0 +1,69 @@ +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Models +{ + public class Room : IRoomModel + { + [Required] + public int WorkerId { get; set; } + [Required] + public int Number { get; set; } + [Required] + public int Floor { get; set; } + [Required] + public int NumberOfBeds { get; set; } + [Required] + public string Condition { get; set; } = string.Empty; + [Required] + public int Cost { get; set; } + + public int Id { get; set; } + public static Room? Create(RoomBindingModel model) + { + if (model == null) return null; + return new Room() + { + Id = model.Id, + WorkerId = model.WorkerId, + Number = model.Number, + NumberOfBeds = model.NumberOfBeds, + Condition = model.Condition, + Cost = model.Cost, + Floor = model.Floor + }; + } + + public void Update(RoomBindingModel model) + { + if (model == null) return; + Id = model.Id; + WorkerId = model.WorkerId; + Number = model.Number; + NumberOfBeds = model.NumberOfBeds; + Condition = model.Condition; + Cost = model.Cost; + Floor = model.Floor; + + } + + public RoomViewModel GetViewModel => new() + { + Id = Id, + WorkerId = WorkerId, + Number = Number, + NumberOfBeds = NumberOfBeds, + Condition = Condition, + Cost = Cost, + Floor = Floor + }; + } +} diff --git a/Hotel/HotelDatabaseImplement/Models/Worker.cs b/Hotel/HotelDatabaseImplement/Models/Worker.cs new file mode 100644 index 0000000..73fd939 --- /dev/null +++ b/Hotel/HotelDatabaseImplement/Models/Worker.cs @@ -0,0 +1,66 @@ +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; +using HotelDataModels.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelDatabaseImplement.Models +{ + public class Worker : IWorkerModel + { + public int PostId { get; set; } + + public string FIO { get; set; } = string.Empty; + + public DateTime DateOfBirth { get; set; } + + public int WorkExperience { get; set; } + + public int Salary { get; set; } + + public string Phone { get; set; } = string.Empty; + + public int Id { get; set; } + public static Worker? Create(WorkerBindingModel model) + { + if (model == null) return null; + return new Worker() + { + Id = model.Id, + PostId = model.PostId, + FIO = model.FIO, + DateOfBirth = model.DateOfBirth, + WorkExperience = model.WorkExperience, + Salary = model.Salary, + Phone = model.Phone + }; + } + + public void Update(WorkerBindingModel model) + { + if (model == null) return; + Id = model.Id; + PostId = model.PostId; + FIO = model.FIO; + DateOfBirth = model.DateOfBirth; + WorkExperience = model.WorkExperience; + Salary = model.Salary; + Phone = model.Phone; + } + + public WorkerViewModel GetViewModel => new() + { + Id = Id, + PostId = PostId, + FIO = FIO, + DateOfBirth = DateOfBirth, + WorkExperience = WorkExperience, + Salary = Salary, + Phone = Phone + }; + } +}