diff --git a/Hotel/Hotel.sln b/Hotel/Hotel.sln index fedf05d..cc9d978 100644 --- a/Hotel/Hotel.sln +++ b/Hotel/Hotel.sln @@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelView", "HotelView\HotelView.csproj", "{BEF2955E-B161-42D6-9385-D06D31FA5CF8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelView", "HotelView\HotelView.csproj", "{BEF2955E-B161-42D6-9385-D06D31FA5CF8}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataModels", "HotelDataModels\HotelDataModels.csproj", "{311319D0-3CD8-48F0-8258-017FBD83728D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataModels", "HotelDataModels\HotelDataModels.csproj", "{311319D0-3CD8-48F0-8258-017FBD83728D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{85D5192D-24CF-48CD-800F-BE5E02B738B6}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{85D5192D-24CF-48CD-800F-BE5E02B738B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{66786012-F68B-4515-9C19-4C97049F9C49}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -27,6 +29,10 @@ Global {85D5192D-24CF-48CD-800F-BE5E02B738B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {85D5192D-24CF-48CD-800F-BE5E02B738B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {85D5192D-24CF-48CD-800F-BE5E02B738B6}.Release|Any CPU.Build.0 = Release|Any CPU + {66786012-F68B-4515-9C19-4C97049F9C49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Hotel/HotelBusinessLogic/BookingLogic.cs b/Hotel/HotelBusinessLogic/BookingLogic.cs new file mode 100644 index 0000000..d0d84d1 --- /dev/null +++ b/Hotel/HotelBusinessLogic/BookingLogic.cs @@ -0,0 +1,99 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using HotelDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic +{ + public class BookingLogic : IBookingLogic + { + private readonly IBookingStorage _bookingStorage; + + public BookingLogic(IBookingStorage bookingStorage) + { + _bookingStorage = bookingStorage; + } + public BookingViewModel? ReadElement(BookingSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _bookingStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(BookingSearchModel? model) + { + var list = model == null ? _bookingStorage.GetFullList() : _bookingStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(BookingBindingModel model) + { + CheckModel(model); + if (_bookingStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(BookingBindingModel model) + { + CheckModel(model, false); + if (_bookingStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(BookingBindingModel model) + { + CheckModel(model); + if (_bookingStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(BookingBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.RoomId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор комнаты", nameof(model.RoomId)); + } + if (model.ClientId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор клиента", nameof(model.ClientId)); + } + + } + } +} diff --git a/Hotel/HotelBusinessLogic/ClientLogic.cs b/Hotel/HotelBusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..7a979b1 --- /dev/null +++ b/Hotel/HotelBusinessLogic/ClientLogic.cs @@ -0,0 +1,106 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic +{ + public class ClientLogic : IClientLogic + { + private readonly IClientStorage _clientStorage; + + public ClientLogic(IClientStorage clientStorage) + { + _clientStorage = clientStorage; + } + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _clientStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(ClientSearchModel? model) + { + var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(ClientBindingModel model) + { + CheckModel(model, false); + if (_clientStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(ClientBindingModel model) + { + CheckModel(model); + if (_clientStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(ClientBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет имени клиента", nameof(model.Name)); + } + if (string.IsNullOrEmpty(model.Surname)) + { + throw new ArgumentNullException("Нет фамилии клиента", nameof(model.Surname)); + } + if (string.IsNullOrEmpty(model.PhoneNumber)) + { + throw new ArgumentNullException("Нет номера телефона", nameof(model.PhoneNumber)); + } + if (string.IsNullOrEmpty(model.Password)) + { + throw new ArgumentNullException("Нет пароля", nameof(model.Password)); + } + + } + } +} diff --git a/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj new file mode 100644 index 0000000..8c6f560 --- /dev/null +++ b/Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Hotel/HotelBusinessLogic/PostLogic.cs b/Hotel/HotelBusinessLogic/PostLogic.cs new file mode 100644 index 0000000..2de8713 --- /dev/null +++ b/Hotel/HotelBusinessLogic/PostLogic.cs @@ -0,0 +1,95 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic +{ + public class PostLogic : IPostLogic + { + private readonly IPostStorage _postStorage; + + public PostLogic(IPostStorage postStorage) + { + _postStorage = postStorage; + } + public PostViewModel? ReadElement(PostSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _postStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(PostSearchModel? model) + { + var list = model == null ? _postStorage.GetFullList() : _postStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(PostBindingModel model) + { + CheckModel(model); + if (_postStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(PostBindingModel model) + { + CheckModel(model, false); + if (_postStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(PostBindingModel model) + { + CheckModel(model); + if (_postStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(PostBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.PostName)) + { + throw new ArgumentNullException("Нужно заполнить поле должности", nameof(model.PostName)); + } + + + } + } +} diff --git a/Hotel/HotelBusinessLogic/RoomLogic.cs b/Hotel/HotelBusinessLogic/RoomLogic.cs new file mode 100644 index 0000000..ffd8130 --- /dev/null +++ b/Hotel/HotelBusinessLogic/RoomLogic.cs @@ -0,0 +1,114 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic +{ + public class RoomLogic : IRoomLogic + { + private readonly IRoomStorage _roomStorage; + + public RoomLogic(IRoomStorage roomStorage) + { + _roomStorage = roomStorage; + } + public RoomViewModel? ReadElement(RoomSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _roomStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(RoomSearchModel? model) + { + var list = model == null ? _roomStorage.GetFullList() : _roomStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(RoomBindingModel model) + { + CheckModel(model); + if (_roomStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(RoomBindingModel model) + { + CheckModel(model, false); + if (_roomStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(RoomBindingModel model) + { + CheckModel(model); + if (_roomStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(RoomBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Condition)) + { + throw new ArgumentNullException("Нет поля состояние", nameof(model.Condition)); + } + if (model.WorkerId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор рабочего", nameof(model.WorkerId)); + } + if (model.Number <= 0) + { + throw new ArgumentNullException("нет поля номера", nameof(model.Number)); + } + if (model.Floor <= 0) + { + throw new ArgumentNullException("нет поля этаж", nameof(model.Floor)); + } + if (model.NumberOfBeds <= 0) + { + throw new ArgumentNullException("нет поля количество спальных мест", nameof(model.NumberOfBeds)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("нет поля цены", nameof(model.Cost)); + } + + } + } +} diff --git a/Hotel/HotelBusinessLogic/WorkerLogic.cs b/Hotel/HotelBusinessLogic/WorkerLogic.cs new file mode 100644 index 0000000..742256e --- /dev/null +++ b/Hotel/HotelBusinessLogic/WorkerLogic.cs @@ -0,0 +1,115 @@ +using HotelContracts.BindingModels; +using HotelContracts.BusinessLogicsContracts; +using HotelContracts.SearchModels; +using HotelContracts.StoragesContracts; +using HotelContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HotelBusinessLogic +{ + public class WorkerLogic : IWorkerLogic + { + private readonly IWorkerStorage _workerStorage; + + public WorkerLogic(IWorkerStorage workerStorage) + { + _workerStorage = workerStorage; + } + public WorkerViewModel? ReadElement(WorkerSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _workerStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(WorkerSearchModel? model) + { + var list = model == null ? _workerStorage.GetFullList() : _workerStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(WorkerBindingModel model) + { + CheckModel(model, false); + if (_workerStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(WorkerBindingModel model) + { + CheckModel(model); + if (_workerStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(WorkerBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Phone)) + { + throw new ArgumentNullException("Нет поля номер телефона", nameof(model.Phone)); + } + if (string.IsNullOrEmpty(model.FIO)) + { + throw new ArgumentNullException("Нет поля ФИО", nameof(model.FIO)); + } + if (model.PostId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор должности", nameof(model.PostId)); + } + if (model.WorkExperience < 0) + { + throw new ArgumentNullException("Рабочий опыт не может быть меньше 0", nameof(model.WorkExperience)); + } + if (model.PostId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор должности", nameof(model.PostId)); + } + if (model.Salary <= 0) + { + throw new ArgumentNullException("Зарплата не может быть меньше 0", nameof(model.Salary)); + } + + + } + } +}