Планы питания
This commit is contained in:
parent
17b9a01260
commit
7554c17813
@ -245,6 +245,144 @@ namespace HotelOrganiserApp.Controllers
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult ListMealPlans()
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(APIClient.GetRequest<List<MealPlanViewModel>>($"api/mealplan/getmealplanlist?organiserId={APIClient.Organiser.Id}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult CreateMealPlan()
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateMealPlan(string mealPlanName, double mealPlanPrice)
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(mealPlanName) || string.IsNullOrEmpty(mealPlanPrice.ToString()))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите название");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(mealPlanPrice.ToString()))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите стоимость");
|
||||||
|
}
|
||||||
|
if (mealPlanPrice < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Стоимость не может быть отрицательной");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/mealplan/createmealplan", new MealPlanBindingModel
|
||||||
|
{
|
||||||
|
MealPlanName = mealPlanName,
|
||||||
|
MealPlanPrice = mealPlanPrice,
|
||||||
|
OrganiserId = APIClient.Organiser.Id,
|
||||||
|
});
|
||||||
|
Response.Redirect("ListMealPlans");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult UpdateMealPlan()
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.MealPlans = APIClient.GetRequest<List<MealPlanViewModel>>($"api/mealplan/getmealplanlist?organiserId={APIClient.Organiser.Id}");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateMealPlan(int mealPlan, string mealPlanName, double mealPlanPrice)
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(mealPlanName))
|
||||||
|
{
|
||||||
|
throw new Exception("Название не может быть пустым");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(mealPlanPrice.ToString()))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите стоимость");
|
||||||
|
}
|
||||||
|
if (mealPlanPrice < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Стоимость не может быть отрицательной");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/mealplan/updatemealplan", new MealPlanBindingModel
|
||||||
|
{
|
||||||
|
Id = mealPlan,
|
||||||
|
MealPlanName = mealPlanName,
|
||||||
|
MealPlanPrice = mealPlanPrice,
|
||||||
|
OrganiserId = APIClient.Organiser.Id
|
||||||
|
});
|
||||||
|
Response.Redirect("ListMealPlans");
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public Tuple<MealPlanViewModel, string>? GetMealPlan(int mealPlanId)
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
var result = APIClient.GetRequest<Tuple<MealPlanViewModel, List<Tuple<string, string, string, string>>>>($"api/mealplan/getmealplan?mealPlanId={mealPlanId}");
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
string table = "";
|
||||||
|
for (int i = 0; i < result.Item2.Count; i++)
|
||||||
|
{
|
||||||
|
var memberSurname = result.Item2[i].Item1;
|
||||||
|
var memberName = result.Item2[i].Item2;
|
||||||
|
var memberPatronymic = result.Item2[i].Item3;
|
||||||
|
var memberPhoneNumber = result.Item2[i].Item4;
|
||||||
|
table += "<tr style=\"height: 44px\">";
|
||||||
|
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberSurname}</td>";
|
||||||
|
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberName}</td>";
|
||||||
|
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberPatronymic}</td>";
|
||||||
|
table += $"<td class=\"u-border-1 u-border-grey-30 u-table-cell\">{memberPhoneNumber}</td>";
|
||||||
|
table += "</tr>";
|
||||||
|
}
|
||||||
|
return Tuple.Create(result.Item1, table);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IActionResult DeleteMealPlan()
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
ViewBag.MealPlans = APIClient.GetRequest<List<MealPlanViewModel>>($"api/mealplan/getmealplanlist?organiserId={APIClient.Organiser.Id}");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void DeleteMealPlan(int mealPlan)
|
||||||
|
{
|
||||||
|
if (APIClient.Organiser == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Необходима авторизация");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/mealplan/deletemealplan", new MealPlanBindingModel
|
||||||
|
{
|
||||||
|
Id = mealPlan
|
||||||
|
});
|
||||||
|
Response.Redirect("ListMealPlans");
|
||||||
|
}
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
|
29
Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml
Normal file
29
Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "CreateMealPlan";
|
||||||
|
}
|
||||||
|
|
||||||
|
<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-2">Название плана питания</label>
|
||||||
|
</div>
|
||||||
|
<input type="text"
|
||||||
|
placeholder="Введите название плана питания"
|
||||||
|
name="mealPlanName"
|
||||||
|
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="mealPlanPrice"
|
||||||
|
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>
|
22
Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml
Normal file
22
Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "DeleteMealPlan";
|
||||||
|
}
|
||||||
|
|
||||||
|
<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="mealplan" name="mealplan" class="form-control">
|
||||||
|
@foreach (var mealplan in ViewBag.MealPlans)
|
||||||
|
{
|
||||||
|
<option value="@mealplan.Id">@(mealplan.MealPlanName)</option>
|
||||||
|
}
|
||||||
|
</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>
|
67
Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml
Normal file
67
Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
@using HotelContracts.ViewModels
|
||||||
|
|
||||||
|
@model List<MealPlanViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "ListMealPlans";
|
||||||
|
}
|
||||||
|
|
||||||
|
<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="CreateMealPlan"
|
||||||
|
class="btn btn-outline-dark mr-2">Добавить</a>
|
||||||
|
<a asp-area="" asp-controller="Home" asp-action="UpdateMealPlan"
|
||||||
|
class="btn btn-outline-dark mr-2">Изменить</a>
|
||||||
|
<a asp-area="" asp-controller="Home" asp-action="DeleteMealPlan"
|
||||||
|
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.MealPlanName)
|
||||||
|
</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.MealPlanPrice)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.btn-group > .btn {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
</style>
|
92
Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml
Normal file
92
Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
@using HotelContracts.ViewModels;
|
||||||
|
@using HotelDataModels.Models;
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "UpdateMealPlan";
|
||||||
|
}
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<div class="u-input u-input-rectangle">
|
||||||
|
<select id="mealplan" name="mealplan" class="form-control">
|
||||||
|
@foreach (var mealplan in ViewBag.MealPlans)
|
||||||
|
{
|
||||||
|
<option value="@mealplan.Id">@(mealplan.MealPlanName)</option>
|
||||||
|
}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Название плана питания</label>
|
||||||
|
<input type="text"
|
||||||
|
id="mealPlanName"
|
||||||
|
placeholder="Введите название плана питания"
|
||||||
|
name="mealPlanName"
|
||||||
|
class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Стоимость</label>
|
||||||
|
<input type="number"
|
||||||
|
id="mealPlanPrice"
|
||||||
|
placeholder="Введите стоимость плана питания"
|
||||||
|
name="mealPlanPrice"
|
||||||
|
class="form-control" />
|
||||||
|
</div>
|
||||||
|
<div class="u-table u-table-responsive u-table-1">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Участники плана питания</label>
|
||||||
|
<table class="table">
|
||||||
|
<thead class="thead-dark">
|
||||||
|
<tr style="height: 44px">
|
||||||
|
<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>
|
||||||
|
<th class="u-border-1 u-border-grey-50 u-table-cell">
|
||||||
|
Номер телефона
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody class="u-table-body" id="table-elements">
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
@section Scripts
|
||||||
|
{
|
||||||
|
<script>
|
||||||
|
function check() {
|
||||||
|
var mealPlan = $('#mealplan').val();
|
||||||
|
if (mealPlan) {
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
url: "/Home/GetMealPlan",
|
||||||
|
data: { mealPlanId: mealPlan },
|
||||||
|
success: function (result) {
|
||||||
|
$('#mealPlanName').val(result.item1.mealPlanName);
|
||||||
|
$('#mealPlanPrice').val(result.item1.mealPlanPrice);
|
||||||
|
$('#table-elements').html(result.item2);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
check();
|
||||||
|
$('#mealPlan').on('change', function () {
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
}
|
@ -38,7 +38,7 @@ namespace HotelRestApi.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public Tuple<MealPlanViewModel, List<Tuple<string, string>>, List<Tuple<string, string>>>? GetMealPlan(int mealPlanId)
|
public Tuple<MealPlanViewModel, List<Tuple<string, string, string, string>>>? GetMealPlan(int mealPlanId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -49,9 +49,9 @@ namespace HotelRestApi.Controllers
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var members = elem.MealPlanMembers.Select(x => Tuple.Create($"{x.Value.MemberSurname} {x.Value.MemberName} {x.Value.MemberPatronymic}", x.Value.MemberPhoneNumber)).ToList();
|
var members = elem.MealPlanMembers.Select(x => Tuple.Create(x.Value.MemberSurname, x.Value.MemberName, x.Value.MemberPatronymic, x.Value.MemberPhoneNumber)).ToList();
|
||||||
|
|
||||||
return Tuple.Create(elem, members, context.Rooms.Where(x => x.MealPlanId == elem.Id).Select(x => Tuple.Create(x.RoomName, x.RoomFrame)).ToList());
|
return Tuple.Create(elem, members);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user