Сделал не доработанную, но рабочую бизнес логику
This commit is contained in:
parent
5e46d3249f
commit
b6bfe860fd
@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.9.34622.214
|
VisualStudioVersion = 17.9.34622.214
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
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
|
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
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{85D5192D-24CF-48CD-800F-BE5E02B738B6}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
99
Hotel/HotelBusinessLogic/BookingLogic.cs
Normal file
99
Hotel/HotelBusinessLogic/BookingLogic.cs
Normal file
@ -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<BookingViewModel>? 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
106
Hotel/HotelBusinessLogic/ClientLogic.cs
Normal file
106
Hotel/HotelBusinessLogic/ClientLogic.cs
Normal file
@ -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<ClientViewModel>? 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
14
Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj
Normal file
14
Hotel/HotelBusinessLogic/HotelBusinessLogic.csproj
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
95
Hotel/HotelBusinessLogic/PostLogic.cs
Normal file
95
Hotel/HotelBusinessLogic/PostLogic.cs
Normal file
@ -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<PostViewModel>? 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
114
Hotel/HotelBusinessLogic/RoomLogic.cs
Normal file
114
Hotel/HotelBusinessLogic/RoomLogic.cs
Normal file
@ -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<RoomViewModel>? 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
115
Hotel/HotelBusinessLogic/WorkerLogic.cs
Normal file
115
Hotel/HotelBusinessLogic/WorkerLogic.cs
Normal file
@ -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<WorkerViewModel>? 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user