Merge branch 'first_branch' of https://git.is.ulstu.ru/Extrimal/PIbd-21_Kurs_Work_Hotel into first_branch
This commit is contained in:
commit
a2f46b6b5a
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelContracts", "HotelCont
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDataBaseImplement", "HotelDataBaseImplement\HotelDataBaseImplement.csproj", "{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelRestApi", "HotelRestApi\HotelRestApi.csproj", "{0B4C604D-8EB3-45D0-8237-2816AF3BC004}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
|
||||||
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
{7D0D63D3-754C-45C4-8B71-882AFD86AAB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0B4C604D-8EB3-45D0-8237-2816AF3BC004}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0B4C604D-8EB3-45D0-8237-2816AF3BC004}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0B4C604D-8EB3-45D0-8237-2816AF3BC004}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0B4C604D-8EB3-45D0-8237-2816AF3BC004}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts;
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -97,6 +98,37 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public bool AddDinnerToConferenceBooking(ConferenceBookingSearchModel model, IDinnerModel dinner)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddDinnerToConferenceBooking. PlaceСonference:{PlaceСonference}.Id:{ Id}", model.PlaceСonference, model.Id);
|
||||||
|
var element = _conferenceBookingStorage.GetElement(model);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddDinnerToConferenceBooking element not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddDinnerToConferenceBooking find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
|
element.ConferenceBookingDinners[dinner.Id] = dinner;
|
||||||
|
|
||||||
|
_conferenceBookingStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = element.Id,
|
||||||
|
PlaceСonference = element.PlaceСonference,
|
||||||
|
DateСonference = element.DateСonference,
|
||||||
|
ConferenceId = element.ConferenceId,
|
||||||
|
AdministratorId = element.AdministratorId,
|
||||||
|
ConferenceBookingDinners = element.ConferenceBookingDinners,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private void CheckModel(ConferenceBookingBindingModel model, bool withParams = true)
|
private void CheckModel(ConferenceBookingBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts;
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDataModels.Models;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -59,7 +60,6 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public bool Create(RoomBindingModel model)
|
public bool Create(RoomBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -98,6 +98,40 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public bool AddDinnerToRoom(RoomSearchModel model, IDinnerModel dinner)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddDinnerToRoom. RoomNumber:{RoomNumber}.Id:{ Id}", model.RoomNumber, model.Id);
|
||||||
|
var element = _roomStorage.GetElement(model);
|
||||||
|
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("AddDinnerToRoom element not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("AddDinnerToRoom find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
|
element.RoomDinners[dinner.Id] = dinner;
|
||||||
|
|
||||||
|
_roomStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = element.Id,
|
||||||
|
RoomNumber = element.RoomNumber,
|
||||||
|
RoomPrice = element.RoomPrice,
|
||||||
|
CountBeds = element.CountBeds,
|
||||||
|
MealPlanId = element.MealPlanId,
|
||||||
|
AdministratorId = element.AdministratorId,
|
||||||
|
RoomDinners = element.RoomDinners,
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckModel(RoomBindingModel model, bool withParams = true)
|
private void CheckModel(RoomBindingModel model, bool withParams = true)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
@ -17,5 +17,6 @@ namespace HotelContracts.BusinessLogicsContracts
|
|||||||
bool Create(ConferenceBookingBindingModel model);
|
bool Create(ConferenceBookingBindingModel model);
|
||||||
bool Update(ConferenceBookingBindingModel model);
|
bool Update(ConferenceBookingBindingModel model);
|
||||||
bool Delete(ConferenceBookingBindingModel model);
|
bool Delete(ConferenceBookingBindingModel model);
|
||||||
|
bool AddDinnerToConferenceBooking(ConferenceBookingSearchModel model, IDinnerModel dinner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,5 +17,6 @@ namespace HotelContracts.BusinessLogicsContracts
|
|||||||
bool Create(RoomBindingModel model);
|
bool Create(RoomBindingModel model);
|
||||||
bool Update(RoomBindingModel model);
|
bool Update(RoomBindingModel model);
|
||||||
bool Delete(RoomBindingModel model);
|
bool Delete(RoomBindingModel model);
|
||||||
|
bool AddDinnerToRoom(RoomSearchModel model, IDinnerModel dinner);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
66
Hotel/HotelRestApi/Controllers/AdministratorController.cs
Normal file
66
Hotel/HotelRestApi/Controllers/AdministratorController.cs
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HotelRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class AdministratorController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IAdministratorLogic _logic;
|
||||||
|
public AdministratorController(IAdministratorLogic logic, ILogger<AdministratorController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public AdministratorViewModel? Login(string login, string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _logic.ReadElement(new AdministratorSearchModel
|
||||||
|
{
|
||||||
|
AdministratorLogin = login,
|
||||||
|
AdministratorPassword = password
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Login error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(AdministratorBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Registration error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateData(AdministratorBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Update data error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
587
Hotel/HotelRestApi/Controllers/MainController.cs
Normal file
587
Hotel/HotelRestApi/Controllers/MainController.cs
Normal file
@ -0,0 +1,587 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelDataBaseImplement;
|
||||||
|
using HotelDataBaseImplement.Models;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HotelRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class MainController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IConferenceLogic _conference;
|
||||||
|
private readonly IParticipantLogic _participant;
|
||||||
|
private readonly IMealPlanLogic _mealPlan;
|
||||||
|
private readonly IDinnerLogic _dinner;
|
||||||
|
private readonly IConferenceBookingLogic _conferenceBooking;
|
||||||
|
private readonly IRoomLogic _room;
|
||||||
|
|
||||||
|
public MainController(ILogger<MainController> logger, IConferenceLogic conference, IParticipantLogic participant, IMealPlanLogic mealPlan, IDinnerLogic dinner, IConferenceBookingLogic conferenceBooking, IRoomLogic room)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_conference = conference;
|
||||||
|
_participant = participant;
|
||||||
|
_mealPlan = mealPlan;
|
||||||
|
_dinner = dinner;
|
||||||
|
_conferenceBooking = conferenceBooking;
|
||||||
|
_room = room;
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public List<ConferenceViewModel>? GetConferenceList(int organiserId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _conference.ReadList(new ConferenceSearchModel
|
||||||
|
{
|
||||||
|
OrganiserId = organiserId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list Conference");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ParticipantViewModel>? GetParticipantList(int organiserId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _participant.ReadList(new ParticipantSearchModel
|
||||||
|
{
|
||||||
|
OrganiserId = organiserId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list Participant");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<MealPlanViewModel>? GetMealPlanList(int organiserId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _mealPlan.ReadList(new MealPlanSearchModel
|
||||||
|
{
|
||||||
|
OrganiserId = organiserId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list MealPlan");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<DinnerViewModel>? GetDinnerList(int administratorId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _dinner.ReadList(new DinnerSearchModel
|
||||||
|
{
|
||||||
|
AdministratorId = administratorId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list Dinner");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int administratorId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
|
||||||
|
{
|
||||||
|
AdministratorId = administratorId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list ConferenceBooking");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<RoomViewModel>? GetRoomList(int administratorId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _room.ReadList(new RoomSearchModel
|
||||||
|
{
|
||||||
|
AdministratorId = administratorId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get list Room");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateParticipant(ParticipantBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_participant.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update Participant");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ParticipantViewModel? GetParticipant(int participantId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _participant.ReadElement(new ParticipantSearchModel
|
||||||
|
{
|
||||||
|
Id = participantId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get participant by id={Id}", participantId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateParticipant(ParticipantBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_participant.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create Participant");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteParticipant(ParticipantBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_participant.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete Participant");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateDinner(DinnerBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dinner.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update Dinner");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public DinnerViewModel? GetDinner(int dinnerId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _dinner.ReadElement(new DinnerSearchModel
|
||||||
|
{
|
||||||
|
Id = dinnerId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get Dinner by id={Id}", dinnerId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateDinner(DinnerBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dinner.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create Dinner");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteDinner(DinnerBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_dinner.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete Dinner");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateConference(ConferenceBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conference.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create Conference");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateConference(ConferenceBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.ConferenceParticipants = null!;
|
||||||
|
_conference.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update Conference");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public (ConferenceViewModel, List<(string, string)>)? GetConference(int conferenceId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var elem = _conference.ReadElement(new ConferenceSearchModel { Id = conferenceId });
|
||||||
|
if (elem == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var participants = new List<(string, string)>();
|
||||||
|
|
||||||
|
foreach (var participant in elem.ConferenceParticipants)
|
||||||
|
{
|
||||||
|
participants.Add((participant.Value.FIO, participant.Value.Number));
|
||||||
|
}
|
||||||
|
return (elem, participants);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get conference by id={Id}", conferenceId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteConference(ConferenceBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conference.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete conference");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddParticipantToConference(Tuple<ConferenceSearchModel, ParticipantViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conference.AddParticipantToConference(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error add Participant to Conference");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateMealPlan(MealPlanBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mealPlan.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create MealPlan");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateMealPlan(MealPlanBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.MealPlanParticipants = null!;
|
||||||
|
_mealPlan.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update MealPlan");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public (MealPlanViewModel, List<(string, string)>, List<(int, int)>)? GetMealPlan(int mealPlanId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using var context = new HotelDataBase();
|
||||||
|
|
||||||
|
var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId });
|
||||||
|
if (elem == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var participants = new List<(string, string)>();
|
||||||
|
foreach (var participant in elem.MealPlanParticipants)
|
||||||
|
{
|
||||||
|
participants.Add((participant.Value.FIO, participant.Value.Number));
|
||||||
|
}
|
||||||
|
|
||||||
|
var rooms = new List<(int, int)>();
|
||||||
|
foreach (var room in context.Rooms.Where(room => room.MealPlanId == elem.Id))
|
||||||
|
{
|
||||||
|
rooms.Add((room.RoomNumber, room.CountBeds));
|
||||||
|
}
|
||||||
|
|
||||||
|
return (elem, participants, rooms);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get MealPlan by id={Id}", mealPlanId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteMealPlan(MealPlanBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mealPlan.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete MealPlan");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddParticipantToMealPlan(Tuple<MealPlanSearchModel, ParticipantViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_mealPlan.AddParticipantToMealPlan(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error add Participant to MealPlan");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create Room");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.RoomDinners = null!;
|
||||||
|
_room.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update Room");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public (RoomViewModel, List<(string, double)>)? GetRoom(int roomId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var elem = _room.ReadElement(new RoomSearchModel { Id = roomId });
|
||||||
|
if (elem == null)
|
||||||
|
return null;
|
||||||
|
var dinners = new List<(string, double)>();
|
||||||
|
foreach (var dinner in elem.RoomDinners)
|
||||||
|
{
|
||||||
|
dinners.Add((dinner.Value.DinnerName, dinner.Value.DinnerPrice));
|
||||||
|
}
|
||||||
|
return (elem, dinners);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get Room by id={Id}", roomId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete Room");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddDinnerToRoom(Tuple<RoomSearchModel, DinnerViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.AddDinnerToRoom(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error add Dinner to Room");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error create ConferenceBooking");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.ConferenceBookingDinners = null!;
|
||||||
|
_conferenceBooking.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error update ConferenceBooking");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public (ConferenceBookingViewModel, List<(string, double)>)? GetConferenceBooking(int conferenceBookingId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel { Id = conferenceBookingId });
|
||||||
|
if (elem == null)
|
||||||
|
return null;
|
||||||
|
var dinners = new List<(string, double)>();
|
||||||
|
foreach (var dinner in elem.ConferenceBookingDinners)
|
||||||
|
{
|
||||||
|
dinners.Add((dinner.Value.DinnerName, dinner.Value.DinnerPrice));
|
||||||
|
}
|
||||||
|
return (elem, dinners);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error get ConferenceBooking by id={Id}", conferenceBookingId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error delete ConferenceBooking");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddDinnerToConferenceBooking(Tuple<ConferenceBookingSearchModel, DinnerViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.AddDinnerToConferenceBooking(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Error add Dinner to ConferenceBooking");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
69
Hotel/HotelRestApi/Controllers/OrganiserController.cs
Normal file
69
Hotel/HotelRestApi/Controllers/OrganiserController.cs
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
|
using HotelContracts.SearchModels;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace HotelRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class OrganiserController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IOrganiserLogic _logic;
|
||||||
|
|
||||||
|
public OrganiserController(IOrganiserLogic logic, ILogger<OrganiserController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public OrganiserViewModel? Login(string login, string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _logic.ReadElement(new OrganiserSearchModel
|
||||||
|
{
|
||||||
|
OrganiserLogin = login,
|
||||||
|
OrganiserPassword = password
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Login error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(OrganiserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Registration error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateData(OrganiserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Update data error");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
Hotel/HotelRestApi/HotelRestApi.csproj
Normal file
20
Hotel/HotelRestApi/HotelRestApi.csproj
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HotelBusinessLogic\HotelBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\HotelDataBaseImplement\HotelDataBaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
53
Hotel/HotelRestApi/Program.cs
Normal file
53
Hotel/HotelRestApi/Program.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using HotelBusinessLogic.BusinessLogic;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelDataBaseImplement.Implemets;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
builder.Logging.AddLog4Net("log4net.config");
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddTransient<IOrganiserStorage, OrganiserStorage>();
|
||||||
|
builder.Services.AddTransient<IMealPlanStorage, MealPlanStorage>();
|
||||||
|
builder.Services.AddTransient<IParticipantStorage, ParticipantStorage>();
|
||||||
|
builder.Services.AddTransient<IConferenceStorage, ConferenceStorage>();
|
||||||
|
builder.Services.AddTransient<IAdministratorStorage, AdministratorStorage>();
|
||||||
|
builder.Services.AddTransient<IDinnerStorage, DinnerStorage>();
|
||||||
|
builder.Services.AddTransient<IRoomStorage, RoomStorage>();
|
||||||
|
builder.Services.AddTransient<IConferenceBookingStorage, ConferenceBookingStorage>();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<IOrganiserLogic, OrganiserLogic>();
|
||||||
|
builder.Services.AddTransient<IMealPlanLogic, MealPlanLogic>();
|
||||||
|
builder.Services.AddTransient<IParticipantLogic, ParticipantLogic>();
|
||||||
|
builder.Services.AddTransient<IConferenceLogic, ConferenceLogic>();
|
||||||
|
builder.Services.AddTransient<IAdministratorLogic, AdministratorLogic>();
|
||||||
|
builder.Services.AddTransient<IDinnerLogic, DinnerLogic>();
|
||||||
|
builder.Services.AddTransient<IRoomLogic, RoomLogic>();
|
||||||
|
builder.Services.AddTransient<IConferenceBookingLogic, ConferenceBookingLogic>();
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "HotelRestApi",
|
||||||
|
Version = "v1"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
var app = builder.Build();
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "HotelRestApi v1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
app.Run();
|
31
Hotel/HotelRestApi/Properties/launchSettings.json
Normal file
31
Hotel/HotelRestApi/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:17840",
|
||||||
|
"sslPort": 44363
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"HotelRestApi": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7080;http://localhost:5286",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
8
Hotel/HotelRestApi/appsettings.Development.json
Normal file
8
Hotel/HotelRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
9
Hotel/HotelRestApi/appsettings.json
Normal file
9
Hotel/HotelRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
16
Hotel/HotelRestApi/log4net.config
Normal file
16
Hotel/HotelRestApi/log4net.config
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<log4net>
|
||||||
|
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||||
|
<file value="c:/temp/HotelRestApi.log" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<maximumFileSize value="100KB" />
|
||||||
|
<maxSizeRollBackups value="2" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="TRACE" />
|
||||||
|
<appender-ref ref="RollingFile" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
Loading…
x
Reference in New Issue
Block a user