Исполнитель: сделал бизнес логику, начал делать DataBaseImplement
This commit is contained in:
parent
777f14f7c9
commit
0398a5c289
@ -5,11 +5,13 @@ VisualStudioVersion = 17.9.34622.214
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelView", "HotelView\HotelView.csproj", "{5A101CB8-E719-4690-BC6C-83476A65A950}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataModels", "HotelDataModels\HotelDataModels.csproj", "{F7796750-0D31-4A5A-8551-897D939C2198}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataModels", "HotelDataModels\HotelDataModels.csproj", "{F7796750-0D31-4A5A-8551-897D939C2198}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{2245C449-6B2E-47AA-AB95-BEE11D387FCD}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelContracts\HotelContracts.csproj", "{2245C449-6B2E-47AA-AB95-BEE11D387FCD}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{B1B6D8C2-CCB1-47AB-A3B6-14BE5BE6E3E7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelBusinessLogic", "HotelBusinessLogic\HotelBusinessLogic.csproj", "{B1B6D8C2-CCB1-47AB-A3B6-14BE5BE6E3E7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{B1B6D8C2-CCB1-47AB-A3B6-14BE5BE6E3E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B1B6D8C2-CCB1-47AB-A3B6-14BE5BE6E3E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B1B6D8C2-CCB1-47AB-A3B6-14BE5BE6E3E7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -10,6 +10,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -18,13 +19,132 @@ namespace HotelBusinessLogic.BusinessLogic
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConferenceStorage _conferenceStorage;
|
||||
|
||||
public ConferenceLogic(ILogger<ConferenceLogic> logger, IConferenceStorage conferenceStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_conferenceStorage = conferenceStorage;
|
||||
}
|
||||
|
||||
//List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model);
|
||||
//ConferenceViewModel? ReadElement(ConferenceSearchModel? model);
|
||||
public List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ConferenceName:{ConferenceName}.Id:{ Id}", model?.ConferenceName, model?.Id);
|
||||
|
||||
//bool AddParticipantToConference(ConferenceSearchModel model, IParticipantModel participant);
|
||||
//bool Create(ConferenceBindingModel model);
|
||||
//bool Update(ConferenceBindingModel model);
|
||||
//bool Delete(ConferenceBindingModel model);
|
||||
var list = model == null ? _conferenceStorage.GetFullList() : _conferenceStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ConferenceViewModel? ReadElement(ConferenceSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
|
||||
_logger.LogInformation("ReadElement. ConferenceName:{ConferenceName}.Id:{ Id}", model?.ConferenceName, model?.Id);
|
||||
|
||||
var element = _conferenceStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement fing. Id:{id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ConferenceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.ConferenceParticipants = new();
|
||||
|
||||
if (_conferenceStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ConferenceBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_conferenceStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ConferenceBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_conferenceStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddParticipantToConference(ConferenceSearchModel model, IParticipantModel participant)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddParticipantToConference. ConferenceName:{ConferenceName}.Id:{ Id}", model.ConferenceName, model.Id);
|
||||
var element = _conferenceStorage.GetElement(model);
|
||||
|
||||
if(element == null)
|
||||
{
|
||||
_logger.LogWarning("AddParticipantToConference element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddParticipantToConference find. Id:{Id}", element.Id);
|
||||
|
||||
element.ConferenceParticipants[participant.Id] = participant;
|
||||
|
||||
_conferenceStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
ConferenceName = element.ConferenceName,
|
||||
Subject = element.Subject,
|
||||
OrganiserId = element.OrganiserId,
|
||||
ConferenceParticipants = element.ConferenceParticipants,
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckModel(ConferenceBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
|
||||
if (!withParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(model.ConferenceName))
|
||||
throw new ArgumentException("Нет названия конференции", nameof(model.ConferenceName));
|
||||
|
||||
_logger.LogInformation("Conference. ConferenceName:{ConferenceName}. Id: { Id}", model.ConferenceName, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
170
Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs
Normal file
170
Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs
Normal file
@ -0,0 +1,170 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MealPlanLogic : IMealPlanLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMealPlanStorage _mealPlanStorage;
|
||||
|
||||
public MealPlanLogic (ILogger<MealPlanLogic> logger, IMealPlanStorage mealPlanStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_mealPlanStorage = mealPlanStorage;
|
||||
}
|
||||
|
||||
public List<MealPlanViewModel>? ReadList(MealPlanSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. MealPlanName:{MealPlanName}.Id:{ Id}", model?.MealPlanName, model?.Id);
|
||||
|
||||
var list = model == null ? _mealPlanStorage.GetFullList() : _mealPlanStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public MealPlanViewModel? ReadElement(MealPlanSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. MealPlanName:{MealPlanName}.Id:{ Id}", model?.MealPlanName, model?.Id);
|
||||
|
||||
var element = _mealPlanStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogInformation("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find: Id:{Id}", model.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(MealPlanBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.MealPlanParticipants = new();
|
||||
|
||||
if (_mealPlanStorage.Insert == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(MealPlanBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_mealPlanStorage.Update == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(MealPlanBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
|
||||
if (_mealPlanStorage.Delete == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddMemberToMealPlan(MealPlanSearchModel model, IParticipantModel participant)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddMemberToMealPlan. MealPlanName:{MealPlanName}.Id:{ Id}", model.MealPlanName, model.Id);
|
||||
|
||||
var element = _mealPlanStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddMemberToMealPlan element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddMemberToMealPlan find. Id:{Id}", element.Id);
|
||||
|
||||
element.MealPlanParticipants[participant.Id] = participant;
|
||||
|
||||
_mealPlanStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
MealPlanName = element.MealPlanName,
|
||||
MealPlanPrice = element.MealPlanPrice,
|
||||
OrganiserId = element.OrganiserId,
|
||||
MealPlanParticipants = element.MealPlanParticipants
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckModel(MealPlanBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(model.MealPlanName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия плана питания", nameof(model.MealPlanName));
|
||||
}
|
||||
|
||||
if (model.MealPlanPrice < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость плана питания не может быть меньше 0", nameof(model.MealPlanPrice));
|
||||
}
|
||||
|
||||
_logger.LogInformation("MealPlan. MealPlanName:{MealPlanName}.MealPlanPrice:{ MealPlanPrice}. Id: { Id}", model.MealPlanName, model.MealPlanPrice, model.Id);
|
||||
|
||||
var element = _mealPlanStorage.GetElement(new MealPlanSearchModel
|
||||
{
|
||||
MealPlanName = model.MealPlanName,
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("План питания с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
140
Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs
Normal file
140
Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs
Normal file
@ -0,0 +1,140 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class OrganiserLogic : IOrganiserLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrganiserStorage _organiserStorage;
|
||||
|
||||
public OrganiserLogic(ILogger<OrganiserLogic> logger, IOrganiserStorage organiserStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_organiserStorage = organiserStorage;
|
||||
}
|
||||
|
||||
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.LogInformation("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
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.LogInformation("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(OrganiserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_organiserStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogInformation("Insert error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(OrganiserBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_organiserStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogInformation("Update error");
|
||||
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.LogInformation("Delete error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckModel(OrganiserBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
|
||||
if (!withParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(model.OrganiserLogin))
|
||||
throw new ArgumentException("Нет логина организатора", nameof(model.OrganiserLogin));
|
||||
|
||||
if (string.IsNullOrEmpty(model.OrganiserPassword))
|
||||
throw new ArgumentException("Нет пароля организатора", nameof(model.OrganiserLogin));
|
||||
|
||||
if (string.IsNullOrEmpty(model.OrganiserEmail))
|
||||
throw new ArgumentException("Нет эл. почты организатора", nameof(model.OrganiserEmail));
|
||||
|
||||
if (string.IsNullOrEmpty(model.OrganiserNumber))
|
||||
throw new ArgumentException("Нет номера организатора", nameof(model.OrganiserNumber));
|
||||
|
||||
if (string.IsNullOrEmpty(model.OrganiserFIO))
|
||||
throw new ArgumentException("Нет ФИО организатора", nameof(model.OrganiserFIO));
|
||||
|
||||
_logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id);
|
||||
|
||||
var element = _organiserStorage.GetElement(new()
|
||||
{
|
||||
OrganiserEmail = model.OrganiserEmail,
|
||||
});
|
||||
|
||||
if (element != null && element.Id == model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Организатор с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
121
Hotel/HotelBusinessLogic/BusinessLogic/ParticipantLogic.cs
Normal file
121
Hotel/HotelBusinessLogic/BusinessLogic/ParticipantLogic.cs
Normal file
@ -0,0 +1,121 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.BusinessLogicsContracts;
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.StoragesContracts;
|
||||
using HotelContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ParticipantLogic : IParticipantLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IParticipantStorage _participantStorage;
|
||||
|
||||
public ParticipantLogic(ILogger<ParticipantLogic> logger, IParticipantStorage participantStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_participantStorage = participantStorage;
|
||||
}
|
||||
|
||||
public List<ParticipantViewModel>? ReadList(ParticipantSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{Id}", model?.FIO, model?.Id);
|
||||
|
||||
var list = model == null ? _participantStorage.GetFullList() : _participantStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogInformation("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public ParticipantViewModel? ReadElement(ParticipantSearchModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement.FIO:{FIO}.Id:{Id}", model.FIO, model.Id);
|
||||
|
||||
var element = _participantStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogInformation("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ParticipantBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
var result = _participantStorage.Insert(model);
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
_logger.LogWarning("Insert error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ParticipantBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (_participantStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ParticipantBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
if (_participantStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete error");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void CheckModel (ParticipantBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
if (!withParams)
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(model.FIO))
|
||||
throw new ArgumentNullException("Нет ФИО участника", nameof(model.FIO));
|
||||
if (string.IsNullOrEmpty (model.Number))
|
||||
throw new ArgumentNullException("Нет номера участника", nameof(model.Number));
|
||||
|
||||
_logger.LogInformation("Participant. FIO:{FIO}.Number:{Number}. Id:{Id}", model.FIO, model.Number, model.Id);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ namespace HotelContracts.BindingModels
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string MealPlantName { get; set; } = string.Empty;
|
||||
public string MealPlanName { get; set; } = string.Empty;
|
||||
|
||||
public double MealPlanPrice { get; set; }
|
||||
|
||||
|
@ -10,6 +10,7 @@ namespace HotelContracts.BusinessLogicsContracts
|
||||
List<ConferenceViewModel>? ReadList(ConferenceSearchModel? model);
|
||||
ConferenceViewModel? ReadElement(ConferenceSearchModel? model);
|
||||
|
||||
bool AddParticipantToConference(ConferenceSearchModel model, IParticipantModel participant);
|
||||
bool Create(ConferenceBindingModel model);
|
||||
bool Update(ConferenceBindingModel model);
|
||||
bool Delete(ConferenceBindingModel model);
|
||||
|
@ -2,11 +2,6 @@
|
||||
using HotelContracts.SearchModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.BusinessLogicsContracts
|
||||
{
|
||||
@ -18,5 +13,6 @@ namespace HotelContracts.BusinessLogicsContracts
|
||||
bool Create(MealPlanBindingModel model);
|
||||
bool Update(MealPlanBindingModel model);
|
||||
bool Delete(MealPlanBindingModel model);
|
||||
bool AddMemberToMealPlan(MealPlanSearchModel model, IParticipantModel participant);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace HotelContracts.SearchModels
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? MealPlantName { get; set; }
|
||||
public string? MealPlanName { get; set; }
|
||||
|
||||
public int? OrganiserId { get; set; }
|
||||
}
|
||||
|
@ -16,6 +16,6 @@ namespace HotelContracts.StoragesContracts
|
||||
|
||||
ConferenceViewModel? Update(ConferenceBindingModel model);
|
||||
|
||||
ConferenceViewModel? Create(ConferenceBindingModel model);
|
||||
ConferenceViewModel? Delete(ConferenceBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,6 @@ namespace HotelContracts.StoragesContracts
|
||||
|
||||
MealPlanViewModel? Update(MealPlanBindingModel model);
|
||||
|
||||
MealPlanViewModel? Create(MealPlanBindingModel model);
|
||||
MealPlanViewModel? Delete(MealPlanBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace HotelContracts.StoragesContracts
|
||||
{
|
||||
public interface ParticipantStorage
|
||||
public interface IParticipantStorage
|
||||
{
|
||||
List<ParticipantViewModel> GetFullList();
|
||||
|
||||
@ -21,6 +21,6 @@ namespace HotelContracts.StoragesContracts
|
||||
|
||||
ParticipantViewModel? Update(ParticipantBindingModel model);
|
||||
|
||||
ParticipantViewModel? Create(ParticipantBindingModel model);
|
||||
ParticipantViewModel? Delete(ParticipantBindingModel model);
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ namespace HotelContracts.ViewModels
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название плана питания")]
|
||||
public string MealPlantName { get; set; } = string.Empty;
|
||||
public string MealPlanName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Цена плана питания")]
|
||||
public double MealPlanPrice { get; set; }
|
||||
|
24
Hotel/HotelDataBaseImplement/HotelDataBase.cs
Normal file
24
Hotel/HotelDataBaseImplement/HotelDataBase.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using HotelDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace HotelDataBaseImplement
|
||||
{
|
||||
public class HotelDataBase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=Hotel_bd;Username=postgres;Password=admin");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
public virtual DbSet<Conference> Conferences { get; set; }
|
||||
public virtual DbSet<MealPlan> MealPlans { set; get; }
|
||||
public virtual DbSet<Participant> Participant { set; get; }
|
||||
public virtual DbSet<Organiser> Organisers { set; get; }
|
||||
}
|
||||
}
|
24
Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj
Normal file
24
Hotel/HotelDataBaseImplement/HotelDataBaseImplement.csproj
Normal file
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.11" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.11">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
|
||||
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
34
Hotel/HotelDataBaseImplement/Models/Conference.cs
Normal file
34
Hotel/HotelDataBaseImplement/Models/Conference.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using HotelDataModels.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
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 Conference : IConferenceModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ConferenceName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public int OrganiserId { get; private set; }
|
||||
|
||||
private Dictionary<int, IParticipantModel> _conferenceMembers = null;
|
||||
|
||||
public Dictionary<int, IParticipantModel> ConferenceParticipants
|
||||
{
|
||||
get
|
||||
{
|
||||
return _conferenceMembers;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
public class ConferenceParticipant
|
||||
{
|
||||
}
|
||||
}
|
8
Hotel/HotelDataBaseImplement/Models/MealPlan.cs
Normal file
8
Hotel/HotelDataBaseImplement/Models/MealPlan.cs
Normal file
@ -0,0 +1,8 @@
|
||||
using HotelDataModels.Models;
|
||||
|
||||
namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
public class MealPlan : IMealPlanModel
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
public class MealPlanParticipant
|
||||
{
|
||||
}
|
||||
}
|
86
Hotel/HotelDataBaseImplement/Models/Organiser.cs
Normal file
86
Hotel/HotelDataBaseImplement/Models/Organiser.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
public class Organiser : IOrganiserModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string OrganiserLogin { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string OrganiserPassword { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string OrganiserEmail { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string OrganiserNumber { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string OrganiserFIO { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("OrganiserId")]
|
||||
public virtual List<Conference> Conferences { get; set; } = new();
|
||||
|
||||
[ForeignKey("OrganiserId")]
|
||||
public virtual List<MealPlan> MealPlans { get; set; } = new();
|
||||
|
||||
[ForeignKey("OrganiserId")]
|
||||
public virtual List<Participant> Participants { get; set; } = new();
|
||||
|
||||
public static Organiser? Create(OrganiserBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
return null;
|
||||
|
||||
return new Organiser()
|
||||
{
|
||||
Id = model.Id,
|
||||
OrganiserLogin = model.OrganiserLogin,
|
||||
OrganiserPassword = model.OrganiserPassword,
|
||||
OrganiserEmail = model.OrganiserEmail,
|
||||
OrganiserNumber = model.OrganiserNumber,
|
||||
OrganiserFIO = model.OrganiserFIO,
|
||||
};
|
||||
}
|
||||
|
||||
public static Organiser Create(OrganiserViewModel model)
|
||||
{
|
||||
return new Organiser
|
||||
{
|
||||
Id = model.Id,
|
||||
OrganiserLogin = model.OrganiserLogin,
|
||||
OrganiserPassword = model.OrganiserPassword,
|
||||
OrganiserEmail = model.OrganiserEmail,
|
||||
OrganiserNumber = model.OrganiserNumber,
|
||||
OrganiserFIO = model.OrganiserFIO,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrganiserBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
OrganiserLogin = model.OrganiserLogin;
|
||||
OrganiserPassword = model.OrganiserPassword;
|
||||
OrganiserEmail = model.OrganiserEmail;
|
||||
OrganiserNumber = model.OrganiserNumber;
|
||||
OrganiserFIO = model.OrganiserFIO;
|
||||
}
|
||||
|
||||
public OrganiserViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
OrganiserLogin = OrganiserLogin,
|
||||
OrganiserPassword = OrganiserPassword,
|
||||
OrganiserEmail = OrganiserEmail,
|
||||
OrganiserNumber = OrganiserNumber,
|
||||
OrganiserFIO = OrganiserFIO,
|
||||
};
|
||||
}
|
||||
}
|
57
Hotel/HotelDataBaseImplement/Models/Participant.cs
Normal file
57
Hotel/HotelDataBaseImplement/Models/Participant.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using HotelContracts.BindingModels;
|
||||
using HotelContracts.ViewModels;
|
||||
using HotelDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HotelDataBaseImplement.Models
|
||||
{
|
||||
public class Participant : IParticipantModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string FIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Number { get; set; } = string.Empty;
|
||||
|
||||
public int OrganiserId { get; private set; }
|
||||
|
||||
public virtual Organiser Organiser { get; set; }
|
||||
|
||||
[ForeignKey("ParticipantId")]
|
||||
public virtual List<MealPlanParticipant> MealPlanParticipants { get; set; } = new();
|
||||
|
||||
[ForeignKey("ParticipantId")]
|
||||
public virtual List<ConferenceParticipant> ConferenceParticipant { get; set; } = new();
|
||||
|
||||
public static Participant? Create(ParticipantBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Participant()
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Number = model.Number,
|
||||
OrganiserId = model.OrganiserId,
|
||||
};
|
||||
}
|
||||
|
||||
public static Participant Create(ParticipantViewModel model)
|
||||
{
|
||||
return new Participant
|
||||
{
|
||||
Id = model.Id,
|
||||
FIO = model.FIO,
|
||||
Number = model.Number,
|
||||
OrganiserId = model.OrganiserId,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
{
|
||||
public interface IMealPlanModel : IId
|
||||
{
|
||||
string MealPlantName { get; }
|
||||
string MealPlanName { get; }
|
||||
double MealPlanPrice { get; }
|
||||
int OrganiserId { get; }
|
||||
public Dictionary<int, IParticipantModel> MealPlanParticipants { get; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user