From e7f2e4d4d98e22ccca77a0225d548f7d50c0b1f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Wed, 1 May 2024 00:14:05 +0400 Subject: [PATCH] full CRUD (75%) --- .../Controllers/HomeController.cs | 79 ++++++++++--------- .../Views/Home/CreateConferenceBooking.cshtml | 25 +++++- .../Views/Home/CreateLunch.cshtml | 3 + .../Views/Home/UpdateConferenceBooking.cshtml | 32 ++++---- 4 files changed, 80 insertions(+), 59 deletions(-) diff --git a/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs b/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs index bbd3282..2731524 100644 --- a/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs +++ b/Hotel/HotelHeadwaiterApp/Controllers/HomeController.cs @@ -125,7 +125,7 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}")); + return View(APIClient.GetRequest>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}")); } public IActionResult CreateLunch() @@ -171,7 +171,7 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}"); + ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } @@ -212,7 +212,7 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunchlist?headwaiterId={APIClient.Headwaiter.Id}"); + ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } @@ -353,7 +353,7 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.Rooms = APIClient.GetRequest>($"api/room/getroomlist?headwaiterId={APIClient.Headwaiter.Id}"); + ViewBag.Rooms = APIClient.GetRequest>($"api/room/getrooms?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } @@ -377,45 +377,37 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}")); + return View(APIClient.GetRequest>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}")); } - [HttpGet] - public Tuple? GetConferenceBooking(int conferenceBookingId) - { - if (APIClient.Headwaiter == null) - { - throw new Exception("Необходима авторизация"); - } - var result = APIClient.GetRequest>>>($"api/conferencebooking/getconferenceBooking?conferenceBookingId={conferenceBookingId}"); - if (result == null) - { - return default; - } - string table = ""; - for (int i = 0; i < result.Item2.Count; i++) - { - var lunchName = result.Item2[i].Item1; - var lunchPrice = result.Item2[i].Item2; - table += ""; - table += $"{lunchName}"; - table += $"{lunchPrice}"; - table += ""; - } - return Tuple.Create(result.Item1, table); - } + [HttpGet] + public Tuple>? GetConferenceBooking(int conferencebookingId) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIClient.GetRequest>>($"api/conferencebooking/getconferencebooking?conferencebookingId={conferencebookingId}"); + if (result == null) + { + return default; + } - public IActionResult CreateConferenceBooking() + return result; + } + + public IActionResult CreateConferenceBooking() { if (APIClient.Headwaiter == null) { return Redirect("~/Home/Enter"); } + ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } [HttpPost] - public void CreateConferenceBooking(string nameHall) + public void CreateConferenceBooking(string nameHall, DateTime bookingDate, List lunches) { if (string.IsNullOrEmpty(nameHall)) { @@ -425,11 +417,17 @@ namespace HotelHeadwaiterApp.Controllers { throw new Exception("Необходима авторизация"); } - + Dictionary a = new Dictionary(); + foreach (int lunch in lunches) + { + a.Add(lunch, new LunchSearchModel { Id = lunch } as ILunchModel); + } APIClient.PostRequest("api/conferencebooking/createconferenceBooking", new ConferenceBookingBindingModel { NameHall = nameHall, - HeadwaiterId = APIClient.Headwaiter.Id, + BookingDate = bookingDate, + HeadwaiterId = APIClient.Headwaiter.Id, + ConferenceBookingLunches = a }); Response.Redirect("ListConferenceBookings"); } @@ -440,13 +438,13 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.ConferenceBookings = APIClient.GetRequest>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}"); - ViewBag.Conferences = APIClient.GetRequest>($"api/conference/getconferences"); + ViewBag.ConferenceBookings = APIClient.GetRequest>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}"); + ViewBag.Lunches = APIClient.GetRequest>($"api/lunch/getlunches?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } [HttpPost] - public void UpdateConferenceBooking(int conference, int conferenceBooking, string nameHall, DateTime bookingDate) + public void UpdateConferenceBooking(int conferenceBooking, string nameHall, DateTime bookingDate, List lunches) { if (APIClient.Headwaiter == null) { @@ -456,13 +454,18 @@ namespace HotelHeadwaiterApp.Controllers { throw new Exception("Название не может быть пустым"); } + Dictionary a = new Dictionary(); + foreach (int lunch in lunches) + { + a.Add(lunch, new LunchSearchModel { Id = lunch } as ILunchModel); + } APIClient.PostRequest("api/conferencebooking/updateconferenceBooking", new ConferenceBookingBindingModel { Id = conferenceBooking, NameHall = nameHall, BookingDate = bookingDate, HeadwaiterId = APIClient.Headwaiter.Id, - ConferenceId = conference + ConferenceBookingLunches = a }); Response.Redirect("ListConferenceBookings"); } @@ -473,7 +476,7 @@ namespace HotelHeadwaiterApp.Controllers { return Redirect("~/Home/Enter"); } - ViewBag.ConferenceBookings = APIClient.GetRequest>($"api/conferencebooking/getconferenceBookinglist?headwaiterId={APIClient.Headwaiter.Id}"); + ViewBag.ConferenceBookings = APIClient.GetRequest>($"api/conferencebooking/getconferenceBookings?headwaiterId={APIClient.Headwaiter.Id}"); return View(); } diff --git a/Hotel/HotelHeadwaiterApp/Views/Home/CreateConferenceBooking.cshtml b/Hotel/HotelHeadwaiterApp/Views/Home/CreateConferenceBooking.cshtml index a6a4870..024caae 100644 --- a/Hotel/HotelHeadwaiterApp/Views/Home/CreateConferenceBooking.cshtml +++ b/Hotel/HotelHeadwaiterApp/Views/Home/CreateConferenceBooking.cshtml @@ -7,10 +7,27 @@

Добавление бронирования по конференции

- +
+ + +
+
+ + +
+
+ +
+
+
+ +
+

diff --git a/Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml b/Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml index 07b2dc0..97748c6 100644 --- a/Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml +++ b/Hotel/HotelHeadwaiterApp/Views/Home/CreateLunch.cshtml @@ -6,6 +6,9 @@

Добавление обеда

+
+ +
Бронирование:
-
- - -
@@ -26,18 +22,16 @@
- -
- - - - - - - - - -
ОбедЦена
+ +
+
+
+

@@ -58,7 +52,11 @@ data: { conferenceBookingId: conferenceBooking }, success: function (result) { $('#nameHall').val(result.item1.nameHall); - $('#table-elements').html(result.item2); + $('#bookingDate').val(result.item1.bookingDate); + $.map(result.item2, function (n) { + console.log("#" + n); + $("#" + n).attr("selected", "selected") + }); } }); };