From 7554c17813e9622cd476e0b2f87d90baa3398d90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=BD=D0=B0=20=D0=97=D0=B0=D0=B1=D1=80=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D0=BD=D0=B0?= Date: Sat, 6 Apr 2024 22:06:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BB=D0=B0=D0=BD=D1=8B=20=D0=BF=D0=B8?= =?UTF-8?q?=D1=82=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 138 ++++++++++++++++++ .../Views/Home/CreateMealPlan.cshtml | 29 ++++ .../Views/Home/DeleteMealPlan.cshtml | 22 +++ .../Views/Home/ListMealPlans.cshtml | 67 +++++++++ .../Views/Home/UpdateMealPlan.cshtml | 92 ++++++++++++ .../Controllers/MealPlanController.cs | 42 +++--- 6 files changed, 369 insertions(+), 21 deletions(-) create mode 100644 Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml create mode 100644 Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml create mode 100644 Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml create mode 100644 Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml diff --git a/Hotel/HotelOrganiserApp/Controllers/HomeController.cs b/Hotel/HotelOrganiserApp/Controllers/HomeController.cs index d6b9652..80e68b7 100644 --- a/Hotel/HotelOrganiserApp/Controllers/HomeController.cs +++ b/Hotel/HotelOrganiserApp/Controllers/HomeController.cs @@ -245,6 +245,144 @@ namespace HotelOrganiserApp.Controllers return result; } + public IActionResult ListMealPlans() + { + if (APIClient.Organiser == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"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>($"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? GetMealPlan(int mealPlanId) + { + if (APIClient.Organiser == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIClient.GetRequest>>>($"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 += ""; + table += $"{memberSurname}"; + table += $"{memberName}"; + table += $"{memberPatronymic}"; + table += $"{memberPhoneNumber}"; + table += ""; + } + return Tuple.Create(result.Item1, table); + } + + public IActionResult DeleteMealPlan() + { + if (APIClient.Organiser == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.MealPlans = APIClient.GetRequest>($"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)] public IActionResult Error() { diff --git a/Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml b/Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml new file mode 100644 index 0000000..dd01aef --- /dev/null +++ b/Hotel/HotelOrganiserApp/Views/Home/CreateMealPlan.cshtml @@ -0,0 +1,29 @@ +@{ + ViewData["Title"] = "CreateMealPlan"; +} + +
+
+

Добавление плана питания

+
+
+ +
+ +
+
+ +
+ +
+
+ +
+
diff --git a/Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml b/Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml new file mode 100644 index 0000000..2778832 --- /dev/null +++ b/Hotel/HotelOrganiserApp/Views/Home/DeleteMealPlan.cshtml @@ -0,0 +1,22 @@ +@{ + ViewData["Title"] = "DeleteMealPlan"; +} + +
+
+

Удаление плана питания

+
+
+ + +
+
+
+ +
+
\ No newline at end of file diff --git a/Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml b/Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml new file mode 100644 index 0000000..5c384e5 --- /dev/null +++ b/Hotel/HotelOrganiserApp/Views/Home/ListMealPlans.cshtml @@ -0,0 +1,67 @@ +@using HotelContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "ListMealPlans"; +} + +
+

Список планов питания

+
+ +
+
+
+
+ +
+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
+ Номер + + Название плана питания + + Стоимость +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.MealPlanName) + + @Html.DisplayFor(modelItem => item.MealPlanPrice) +
+
+
+
+
+
+ + diff --git a/Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml b/Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml new file mode 100644 index 0000000..683ba7b --- /dev/null +++ b/Hotel/HotelOrganiserApp/Views/Home/UpdateMealPlan.cshtml @@ -0,0 +1,92 @@ +@using HotelContracts.ViewModels; +@using HotelDataModels.Models; + +@{ + ViewData["Title"] = "UpdateMealPlan"; +} + +
+
+

Изменение плана питания

+
+
+ +
+ +
+
+
+ + +
+
+ + +
+
+ + + + + + + + + + + + +
+ Фамилия + + Имя + + Отчество + + Номер телефона +
+
+
+
+
+
+
+ + +@section Scripts +{ + +} diff --git a/Hotel/HotelRestApi/Controllers/MealPlanController.cs b/Hotel/HotelRestApi/Controllers/MealPlanController.cs index 71943cb..4933f15 100644 --- a/Hotel/HotelRestApi/Controllers/MealPlanController.cs +++ b/Hotel/HotelRestApi/Controllers/MealPlanController.cs @@ -37,30 +37,30 @@ namespace HotelRestApi.Controllers } } - [HttpGet] - public Tuple>, List>>? GetMealPlan(int mealPlanId) - { - try - { - using var context = new HotelDataBase(); - var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId }); - if (elem == null) - { - return null; - } + [HttpGet] + public Tuple>>? GetMealPlan(int mealPlanId) + { + try + { + using var context = new HotelDataBase(); + var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId }); + if (elem == 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()); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка получения плана питания по id={Id}", mealPlanId); - throw; - } - } + return Tuple.Create(elem, members); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения плана питания по id={Id}", mealPlanId); + throw; + } + } - [HttpPost] + [HttpPost] public void CreateMealPlan(MealPlanBindingModel model) { try