BusinessLogic для организатора

This commit is contained in:
AnnZhimol 2023-04-06 17:58:51 +04:00
parent f63a05d7d4
commit 0f22fca83f
6 changed files with 394 additions and 1 deletions

View File

@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataModels", "HotelDat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{234B3526-A74E-43D2-9333-E74B4FF9A356}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{E34AD471-B0B3-473F-9A52-E7BB20CA1081}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,6 +35,10 @@ Global
{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B32CB19B-0F73-49F1-8821-7BBAFED6A6C5}.Release|Any CPU.Build.0 = Release|Any CPU
{E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E34AD471-B0B3-473F-9A52-E7BB20CA1081}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,35 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.ViewModels;
namespace HotelBusinessLogic.BusinessLogics
{
public class ConferenceLogic : IConferenceLogic
{
public bool Create(ConferenceBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(ConferenceBindingModel model)
{
throw new NotImplementedException();
}
public ConferenceViewModel? ReadElement(ConferenceSearchModel model)
{
throw new NotImplementedException();
}
public List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(ConferenceBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,35 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.ViewModels;
namespace HotelBusinessLogic.BusinessLogics
{
public class MealPlanLogic : IMealPlanLogic
{
public bool Create(MealPlanBindingModel model)
{
throw new NotImplementedException();
}
public bool Delete(MealPlanBindingModel model)
{
throw new NotImplementedException();
}
public MealPlanViewModel? ReadElement(MealPlanSearchModel model)
{
throw new NotImplementedException();
}
public List<MealPlanViewModel>? ReadList(MealPlanSearchModel? model)
{
throw new NotImplementedException();
}
public bool Update(MealPlanBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,125 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics
{
public class MemberLogic : IMemberLogic
{
private readonly ILogger _logger;
private readonly IMemberStorage _memberStorage;
public MemberLogic(ILogger<MemberLogic> logger, IMemberStorage memberStorage)
{
_logger = logger;
_memberStorage = memberStorage;
}
public bool Create(MemberBindingModel model)
{
CheckModel(model);
if (_memberStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(MemberBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_memberStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public MemberViewModel? ReadElement(MemberSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. MemberFIO:{MemberFIO}.Id:{Id}", model.MemberFIO, model.Id);
var element = _memberStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
return element;
}
public List<MemberViewModel>? ReadList(MemberSearchModel? model)
{
_logger.LogInformation("ReadList. MemberFIO:{MemberFIO}.Id:{ Id}", model?.MemberFIO, model?.Id);
var list = model == null ? _memberStorage.GetFullList() : _memberStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public bool Update(MemberBindingModel model)
{
CheckModel(model);
if (_memberStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(MemberBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MemberFIO))
{
throw new ArgumentNullException("Нет ФИО участника", nameof(model.MemberFIO));
}
if (string.IsNullOrEmpty(model.Citizenship))
{
throw new ArgumentNullException("Не указано гражданство участника", nameof(model.Citizenship));
}
_logger.LogInformation("Member. MemberFIO:{MemberFIO}.Citizenship:{ Citizenship}. Id: { Id}", model.MemberFIO, model.Citizenship, model.Id);
}
}
}

View File

@ -0,0 +1,171 @@
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace HotelBusinessLogic.BusinessLogics
{
public class OrganiserLogic : IOrganiserLogic
{
private readonly int _loginMaxLength = 50;
private readonly int _passwordMaxLength = 50;
private readonly int _passwordMinLength = 10;
private readonly ILogger _logger;
private readonly IOrganiserStorage _organiserStorage;
public OrganiserLogic(ILogger<OrganiserLogic> logger, IOrganiserStorage organiserStorage)
{
_logger = logger;
_organiserStorage = organiserStorage;
}
public bool Create(OrganiserBindingModel model)
{
CheckModel(model);
if (_organiserStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Delete(OrganiserBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id: {Id}", model.Id);
if (_organiserStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
public OrganiserViewModel? ReadElement(OrganiserSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}.", model.OrganiserFIO, model.OrganiserLogin, model.Id);
var element = _organiserStorage.GetElement(model);
if (element == null)
{
_logger.LogWarning("ReadElement element not found");
return null;
}
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
return element;
}
public List<OrganiserViewModel>? ReadList(OrganiserSearchModel? model)
{
_logger.LogInformation("ReadList. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}.", model?.OrganiserFIO, model?.OrganiserLogin, model?.Id);
var list = model == null ? _organiserStorage.GetFullList() : _organiserStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public bool Update(OrganiserBindingModel model)
{
CheckModel(model);
if (_organiserStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
private void CheckModel(OrganiserBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.OrganiserFIO))
{
throw new ArgumentNullException("Нет ФИО организатора", nameof(model.OrganiserFIO));
}
if (string.IsNullOrEmpty(model.OrganiserLogin))
{
throw new ArgumentNullException("Нет логина организатора", nameof(model.OrganiserLogin));
}
if (model.OrganiserLogin.Length>_loginMaxLength)
{
throw new ArgumentNullException("Логин слишком длинный", nameof(model.OrganiserLogin));
}
if (string.IsNullOrEmpty(model.OrganiserNumber))
{
throw new ArgumentNullException("Нет номера телефона организатора", nameof(model.OrganiserNumber));
}
if (string.IsNullOrEmpty(model.OrganiserEmail))
{
throw new ArgumentNullException("Нет почты организатора", nameof(model.OrganiserEmail));
}
if (string.IsNullOrEmpty(model.OrganiserPassword))
{
throw new ArgumentNullException("Нет пароля организатора", nameof(model.OrganiserPassword));
}
if (model.OrganiserPassword.Length < _passwordMinLength)
{
throw new ArgumentNullException("Пароль слишком короткий", nameof(model.OrganiserPassword));
}
if (model.OrganiserPassword.Length > _passwordMaxLength)
{
throw new ArgumentNullException("Пароль слишком длинный", nameof(model.OrganiserPassword));
}
_logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id);
var element = _organiserStorage.GetElement(new OrganiserSearchModel
{
OrganiserLogin = model.OrganiserLogin
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Организатор с таким логином уже есть");
}
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="OfficePackage\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
</ItemGroup>
</Project>