что-то типо обЭдов
This commit is contained in:
parent
beff83a5dc
commit
3d2a7d5425
@ -1,7 +1,9 @@
|
|||||||
using HostrelHeadwaiterApp;
|
using HostrelHeadwaiterApp;
|
||||||
using HotelContracts.BindingModels;
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.ViewModels;
|
||||||
using HotelHeadwaiterApp.Models;
|
using HotelHeadwaiterApp.Models;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace HotelHeadwaiterApp.Controllers
|
namespace HotelHeadwaiterApp.Controllers
|
||||||
@ -17,9 +19,62 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
|
|
||||||
public IActionResult Index()
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Register()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(string login, string email, string password, string surname, string name, string patronymic, string telephone)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин, пароль, фамилию, имя и отчество");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/headwaiter/register", new HeadwaiterBindingModel
|
||||||
|
{
|
||||||
|
HeadwaiterSurname = surname,
|
||||||
|
HeadwaiterName = name,
|
||||||
|
HeadwaiterPatronymic = patronymic,
|
||||||
|
HeadwaiterLogin = login,
|
||||||
|
HeadwaiterPassword = password,
|
||||||
|
HeadwaiterEmail = email,
|
||||||
|
HeadwaiterPhoneNumber = telephone
|
||||||
|
});
|
||||||
|
|
||||||
|
Response.Redirect("Enter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Enter()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Enter(string login, string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин и пароль");
|
||||||
|
}
|
||||||
|
APIClient.Headwaiter = APIClient.GetRequest<HeadwaiterViewModel>($"api/headwaiter/login?login={login}&password={password}");
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Неверный логин/пароль");
|
||||||
|
}
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult Privacy()
|
public IActionResult Privacy()
|
||||||
{
|
{
|
||||||
@ -63,32 +118,107 @@ namespace HotelHeadwaiterApp.Controllers
|
|||||||
Response.Redirect("Index");
|
Response.Redirect("Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
public IActionResult ListLunches()
|
||||||
public IActionResult Register()
|
|
||||||
{
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult CreateLunch()
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void Register(string login, string email, string password, string surname, string name, string patronymic, string telephone)
|
public void CreateLunch(string lunchName, double lunchPrice)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(surname) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(patronymic))
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Введите логин, пароль, фамилию, имя и отчество");
|
throw new Exception("Необходима авторизация");
|
||||||
}
|
}
|
||||||
APIClient.PostRequest("api/headwaiter/register", new HeadwaiterBindingModel
|
if (string.IsNullOrEmpty(lunchName))
|
||||||
{
|
{
|
||||||
HeadwaiterSurname = surname,
|
throw new Exception("Введите имя");
|
||||||
HeadwaiterName = name,
|
}
|
||||||
HeadwaiterPatronymic = patronymic,
|
if (lunchPrice < 0)
|
||||||
HeadwaiterLogin = login,
|
{
|
||||||
HeadwaiterPassword = password,
|
throw new Exception("Цена не может быть отрицательной");
|
||||||
HeadwaiterEmail = email,
|
}
|
||||||
HeadwaiterPhoneNumber = telephone
|
APIClient.PostRequest("api/lunch/createlunch", new LunchBindingModel
|
||||||
|
{
|
||||||
|
LunchPrice = lunchPrice,
|
||||||
|
LunchName = lunchName,
|
||||||
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||||
|
});
|
||||||
|
Response.Redirect("ListLunches");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult UpdateLunch()
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateLunch(int lunch, string lunchName, double lunchPrice)
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(lunchName))
|
||||||
|
{
|
||||||
|
throw new Exception("Имя не может быть пустым");
|
||||||
|
}
|
||||||
|
if (lunchPrice < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Цена не может быть отрицательной");
|
||||||
|
}
|
||||||
|
|
||||||
|
APIClient.PostRequest("api/lunch/updatelunch", new LunchBindingModel
|
||||||
|
{
|
||||||
|
Id = lunch,
|
||||||
|
LunchName = lunchName,
|
||||||
|
LunchPrice = lunchPrice,
|
||||||
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||||
});
|
});
|
||||||
|
|
||||||
Response.Redirect("Enter");
|
Response.Redirect("ListLunches");
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
public IActionResult DeleteLunch()
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.Lunches = APIClient.GetRequest<List<LunchViewModel>>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteLunch(int lunch)
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/lunch/deletelunch", new LunchBindingModel
|
||||||
|
{
|
||||||
|
Id = lunch
|
||||||
|
});
|
||||||
|
Response.Redirect("ListLunches");
|
||||||
}
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
|
26
Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml
Normal file
26
Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "CreateLunch";
|
||||||
|
}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Добавление обеда</h2>
|
||||||
|
</div>
|
||||||
|
<input type="text"
|
||||||
|
placeholder="Введите название обеда"
|
||||||
|
name="lunchName"
|
||||||
|
class="form-control" />
|
||||||
|
<br>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-2">Стоимость обеда</label>
|
||||||
|
</div>
|
||||||
|
<input type="number"
|
||||||
|
placeholder="Введите стоимость обеда"
|
||||||
|
name="lunchPrice"
|
||||||
|
class="form-control"
|
||||||
|
step="1" />
|
||||||
|
<br>
|
||||||
|
<div class="u-container-layout u-container-layout-2">
|
||||||
|
<input type="submit" value="Сохранить" class="btn btn-outline-dark text-center d-flex justify-content-md-center" />
|
||||||
|
</div>
|
||||||
|
</form>
|
17
Hotel/HotelHeadwaiterApp/Views/Home/DeleteLunch.cshtml
Normal file
17
Hotel/HotelHeadwaiterApp/Views/Home/DeleteLunch.cshtml
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "DeleteLunch";
|
||||||
|
}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Удаление обеда</h2>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Обеды: </label>
|
||||||
|
<select id="lunch" name="lunch" class="form-control" asp-items="@(new SelectList(@ViewBag.Lunches, "Id", "LunchName"))"></select>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="u-container-layout u-container-layout-2">
|
||||||
|
<input type="submit" value="Сохранить" class="btn btn-outline-dark text-center d-flex justify-content-md-center" />
|
||||||
|
</div>
|
||||||
|
</form>
|
39
Hotel/HotelHeadwaiterApp/Views/Home/Enter.cshtml
Normal file
39
Hotel/HotelHeadwaiterApp/Views/Home/Enter.cshtml
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Enter";
|
||||||
|
}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="mask d-flex align-items-center h-100 gradient-custom-3">
|
||||||
|
<div class="container h-100">
|
||||||
|
<div class="row d-flex justify-content-center align-items-center h-100">
|
||||||
|
<div class="col-12 col-md-9 col-lg-7 col-xl-6">
|
||||||
|
<div class="card" style="border-radius: 15px; border-color:black;">
|
||||||
|
<div class="card-body p-5">
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Вход </h2>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Электронная почта</label>
|
||||||
|
<input type="text"
|
||||||
|
placeholder="Введите свой логин"
|
||||||
|
name="login"
|
||||||
|
class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-2">Пароль</label>
|
||||||
|
<input type="password"
|
||||||
|
placeholder="Введите свой пароль"
|
||||||
|
name="password"
|
||||||
|
class="form-control" />
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="form-group text-center d-flex justify-content-center">
|
||||||
|
<button type="submit" class="btn btn-outline-dark text-center d-flex justify-content-md-center">Войти</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -10,7 +10,3 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-lg-3 col-md-4 col-sm-6 col-12 mb-4">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
67
Hotel/HotelHeadwaiterApp/Views/Home/ListLunches.cshtml
Normal file
67
Hotel/HotelHeadwaiterApp/Views/Home/ListLunches.cshtml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
@using HotelContracts.ViewModels
|
||||||
|
|
||||||
|
@model List<LunchViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "ListLunches";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Список обедов</h2>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section class="u-clearfix u-section-1" id="sec-e38b">
|
||||||
|
<div class="u-clearfix u-sheet u-sheet-1">
|
||||||
|
<div class="u-container-style u-layout-cell u-size-48 u-layout-cell-1">
|
||||||
|
<div class="u-container-layout u-container-layout-1">
|
||||||
|
<div class="btn-group" role="group" aria-label="Basic example">
|
||||||
|
<a asp-area="" asp-controller="Home" asp-action="CreateLunch"
|
||||||
|
class="btn btn-outline-dark mr-2">Добавить</a>
|
||||||
|
<a asp-area="" asp-controller="Home" asp-action="UpdateLunch"
|
||||||
|
class="btn btn-outline-dark mr-2">Изменить</a>
|
||||||
|
<a asp-area="" asp-controller="Home" asp-action="DeleteLunch"
|
||||||
|
class="btn btn-outline-dark">Удалить</a>
|
||||||
|
</div>
|
||||||
|
<div class="u-table u-table-responsive u-table-1">
|
||||||
|
<table class="table">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr style="height: 31px">
|
||||||
|
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||||
|
Номер
|
||||||
|
</th>
|
||||||
|
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||||
|
Цена обеда
|
||||||
|
</th>
|
||||||
|
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||||
|
Название обеда
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="u-table-body">
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr style="height: 75px">
|
||||||
|
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
|
||||||
|
@Html.DisplayFor(modelItem => item.Id)
|
||||||
|
</td>
|
||||||
|
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
|
||||||
|
@Html.DisplayFor(modelItem => item.LunchPrice)
|
||||||
|
</td>
|
||||||
|
<td class="u-border-1 u-border-grey-40 u-border-no-left u-border-no-right u-table-cell">
|
||||||
|
@Html.DisplayFor(modelItem => item.LunchName)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.btn-group > .btn {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
@ -1,9 +1,7 @@
|
|||||||
@{
|
@{
|
||||||
ViewData["Title"] = "Register";
|
ViewData["Title"] = "Register";
|
||||||
}
|
}
|
||||||
<div class="text-center">
|
|
||||||
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Регистрация </h2>
|
|
||||||
</div>
|
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="mask d-flex align-items-center h-100 gradient-custom-3">
|
<div class="mask d-flex align-items-center h-100 gradient-custom-3">
|
||||||
<div class="container h-100">
|
<div class="container h-100">
|
||||||
@ -11,6 +9,9 @@
|
|||||||
<div class="col-12 col-md-9 col-lg-7 col-xl-6">
|
<div class="col-12 col-md-9 col-lg-7 col-xl-6">
|
||||||
<div class="card" style="border-radius: 15px; border-color:black;">
|
<div class="card" style="border-radius: 15px; border-color:black;">
|
||||||
<div class="card-body p-5">
|
<div class="card-body p-5">
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Регистрация </h2>
|
||||||
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-1">Логин</label>
|
<label class="u-label u-text-custom-color-1 u-label-1">Логин</label>
|
||||||
<input type="text"
|
<input type="text"
|
||||||
|
62
Hotel/HotelHeadwaiterApp/Views/Home/UpdateLunch.cshtml
Normal file
62
Hotel/HotelHeadwaiterApp/Views/Home/UpdateLunch.cshtml
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
@using HotelContracts.ViewModels;
|
||||||
|
@using HotelDataModels.Models;
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "UpdateLunch";
|
||||||
|
}
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Изменение обеда</h2>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Обеды: </label>
|
||||||
|
<select id="lunch" name="lunch" class="form-control" asp-items="@(new SelectList(@ViewBag.Lunches, "Id", "LunchName"))"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Название обеда</label>
|
||||||
|
<input type="text"
|
||||||
|
id="lunchName"
|
||||||
|
placeholder="Введите название обеда"
|
||||||
|
name="lunchName"
|
||||||
|
class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-2">Стоимость обеда</label>
|
||||||
|
<input type="number"
|
||||||
|
id="lunchPrice"
|
||||||
|
placeholder="Введите стоимость обеда"
|
||||||
|
name="lunchPrice"
|
||||||
|
class="form-control"
|
||||||
|
step="1" />
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div class="u-container-layout u-container-layout-2">
|
||||||
|
<input type="submit" value="Сохранить" class="btn btn-outline-dark text-center d-flex justify-content-md-center" />
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts
|
||||||
|
{
|
||||||
|
<script>
|
||||||
|
function check() {
|
||||||
|
var lunch = $('#lunch').val();
|
||||||
|
if (lunch) {
|
||||||
|
$.ajax ({
|
||||||
|
method: "GET",
|
||||||
|
url: "/Home/GetLunch",
|
||||||
|
data: { lunchId: lunch },
|
||||||
|
success: function (result) {
|
||||||
|
$('#lunchName').val(result.LunchName);
|
||||||
|
$('#lunchPrice').val(result.LunchPrice);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
check();
|
||||||
|
$('#lunch').on('change', function () {
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
145
Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs
Normal file
145
Hotel/HotelRestApi/Controllers/ConferenceBookingController.cs
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
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 ConferenceBookingController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IConferenceBookingLogic _conferenceBooking;
|
||||||
|
|
||||||
|
public ConferenceBookingController(ILogger<ConferenceBookingController> logger, IConferenceBookingLogic conferenceBooking)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_conferenceBooking = conferenceBooking;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ConferenceBookingViewModel>? GetConferenceBookingList(int headwaiterId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _conferenceBooking.ReadList(new ConferenceBookingSearchModel
|
||||||
|
{
|
||||||
|
HeadwaiterId = headwaiterId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка бронирования по конференции");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ConferenceBookingViewModel? GetConferenceBookingById(int conferenceBookingId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel
|
||||||
|
{
|
||||||
|
Id = conferenceBookingId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (elem == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return elem;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public Tuple<ConferenceBookingViewModel, List<Tuple<string, double>>>? GetConferenceBooking(int conferenceBookingId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var elem = _conferenceBooking.ReadElement(new ConferenceBookingSearchModel
|
||||||
|
{
|
||||||
|
Id = conferenceBookingId
|
||||||
|
});
|
||||||
|
|
||||||
|
if (elem == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Tuple.Create(elem, elem.ConferenceBookingLunches.Select(x => Tuple.Create(x.Value.LunchName, x.Value.LunchPrice)).ToList());
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения по id={Id}", conferenceBookingId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания бронирования по конференции");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.ConferenceBookingLunches = null!;
|
||||||
|
_conferenceBooking.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных бронирования по конференции");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteConferenceBooking(ConferenceBookingBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления бронирования по конференции");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddLunchToConferenceBooking(Tuple<ConferenceBookingSearchModel, LunchViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_conferenceBooking.AddLunchToConferenceBooking(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка добавления обеда в бронирование по конференции.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
112
Hotel/HotelRestApi/Controllers/LunchController.cs
Normal file
112
Hotel/HotelRestApi/Controllers/LunchController.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
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 LunchController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly ILunchLogic _lunch;
|
||||||
|
|
||||||
|
public LunchController(ILogger<ConferenceBookingController> logger, ILunchLogic lunch)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_lunch = lunch;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<LunchViewModel>? GetLunchList(int headwaiterId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _lunch.ReadList(new LunchSearchModel
|
||||||
|
{
|
||||||
|
HeadwaiterId = headwaiterId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка обедов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<LunchViewModel>? GetLunches()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _lunch.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка обедов");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public LunchViewModel? GetLunchById(int lunchId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _lunch.ReadElement(new LunchSearchModel
|
||||||
|
{
|
||||||
|
Id = lunchId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения обеда по id={Id}", lunchId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateLunch(LunchBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_lunch.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания обеда");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateLunch(LunchBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_lunch.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных обеда");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteLunch(LunchBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_lunch.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления обеда");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
127
Hotel/HotelRestApi/Controllers/RoomController.cs
Normal file
127
Hotel/HotelRestApi/Controllers/RoomController.cs
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
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 RoomController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IRoomLogic _room;
|
||||||
|
|
||||||
|
public RoomController(ILogger<ConferenceBookingController> logger, IRoomLogic room)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_room = room;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<RoomViewModel>? GetRoomList(int headwaiterId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _room.ReadList(new RoomSearchModel
|
||||||
|
{
|
||||||
|
HeadwaiterId = headwaiterId,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<RoomViewModel>? GetRooms()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _room.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка номеров");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public RoomViewModel? GetRoomById(int roomId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _room.ReadElement(new RoomSearchModel
|
||||||
|
{
|
||||||
|
Id = roomId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения номера по id={Id}", roomId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания номера");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
model.RoomLunches = null!;
|
||||||
|
_room.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных номера");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteRoom(RoomBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.Delete(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка удаления номера");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void AddLunchToRoom(Tuple<RoomSearchModel, LunchViewModel> model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_room.AddLunchToRoom(model.Item1, model.Item2);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка добавления обеда к номеру.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user