From 4c4d8a878afdef22d7a0f2c7dd8847868740ed8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 16 May 2023 00:09:17 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A2=D1=8F=D0=B6=D0=B5=D0=BB=D0=BE,=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB-=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB,?= =?UTF-8?q?=20=D0=B0=20=D0=B2=20=D0=B8=D1=82=D0=BE=D0=B3=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B8=D1=87=D0=B5=D0=B3=D0=BE=20=D0=BD=D0=B5=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82,=20=D0=B2=20=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=B5=20=D0=B2=D1=81=D0=B5=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D0=BD=D1=83=D0=BB=20=D0=BA=D0=B0=D0=BA=20=D0=B1=D1=8B=D0=BB?= =?UTF-8?q?=D0=BE,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B=20=D1=83=20=D0=90?= =?UTF-8?q?=D0=BD=D0=B8=20=D0=BD=D0=B5=20=D1=81=D0=BB=D0=BE=D0=BC=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=D1=81=D1=8C,=20=D0=BE=D1=81=D1=82=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=D1=8B=20?= =?UTF-8?q?:(?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 227 +++++++++++++++--- Hotel/HostrelHeadwaiterApp/Program.cs | 3 + Hotel/HostrelHeadwaiterApp/appsettings.json | 3 +- .../Controllers/HeadwaiterController.cs | 67 ++++++ .../Controllers/MainController.cs | 146 ++++++++++- Hotel/HotelRestApi/Program.cs | 10 + 6 files changed, 422 insertions(+), 34 deletions(-) create mode 100644 Hotel/HotelRestApi/Controllers/HeadwaiterController.cs diff --git a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs index 28a02d0..4979e5a 100644 --- a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs +++ b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs @@ -1,4 +1,6 @@ using HostrelHeadwaiterApp.Models; +using HotelContracts.BindingModels; +using HotelContracts.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Diagnostics; @@ -13,57 +15,218 @@ namespace HostrelHeadwaiterApp.Controllers _logger = logger; } + public IActionResult CreateDinner() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + return View(); + } + + [HttpPost] + public void CreateDinner(double dinnerPrice, string dinnerName) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Необходима авторизация"); + } + if (string.IsNullOrEmpty(dinnerName)) + { + throw new Exception("Введите имя"); + } + APIClient.PostRequest("api/main/createdinner", new DinnerBindingModel + { + DinnerPrice = dinnerPrice, + DinnerName = dinnerName, + HeadwaiterId = APIClient.Headwaiter.Id, + }); + Response.Redirect("ListDinners"); + } + + public IActionResult UpdateDinner() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Dinners = APIClient.GetRequest>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"); + return View(); + } + + [HttpPost] + public void UpdateDinner(int dinner, string dinnerName, double dinnerPrice) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Необходима авторизация"); + } + if (string.IsNullOrEmpty(dinnerName)) + { + throw new Exception("имя не может быть пустым"); + } + + APIClient.PostRequest("api/main/updatedinner", new DinnerBindingModel + { + Id = dinner, + DinnerName = dinnerName, + DinnerPrice = dinnerPrice, + HeadwaiterId = APIClient.Headwaiter.Id, + }); + + Response.Redirect("ListDinners"); + } + + public IActionResult DeleteDinner() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Dinners = APIClient.GetRequest>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}"); + return View(); + } + + [HttpPost] + public void DeleteDinner(int dinner) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Необходима авторизация"); + } + APIClient.PostRequest("api/main/deletedinner", new DinnerBindingModel + { + Id = dinner + }); + Response.Redirect("ListDinners"); + } + + [HttpGet] + public DinnerViewModel? GetDinner(int dinnerId) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Необходима авторизация"); + } + var result = APIClient.GetRequest($"api/main/getdinner?dinnerid={dinnerId}"); + if (result == null) + { + return default; + } + var dinnerPrice = result.DinnerPrice; + var dinnerName = result.DinnerName; + + return result; + } + public IActionResult Index() { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } return View(); } - public IActionResult Register() + public IActionResult ListDinners() { - return View(); + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}")); } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Headwaiter); + } + + [HttpPost] + public void Privacy(string login, string email, string password, string fio, string telephone) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/headwaiter/updatedata", new HeadwaiterBindingModel + { + Id = APIClient.Headwaiter.Id, + HeadwaiterFIO = fio, + HeadwaiterLogin = login, + HeadwaiterPassword = password, + HeadwaiterEmail = email, + HeadwaiterNumber = telephone + }); + + APIClient.Headwaiter.HeadwaiterFIO = fio; + APIClient.Headwaiter.HeadwaiterLogin = login; + APIClient.Headwaiter.HeadwaiterPassword = password; + APIClient.Headwaiter.HeadwaiterEmail = email; + APIClient.Headwaiter.HeadwaiterNumber = telephone; + Response.Redirect("Index"); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } + + [HttpGet] public IActionResult Enter() { return View(); } - public IActionResult Report() + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Headwaiter = APIClient.GetRequest($"api/headwaiter/login?login={login}&password={password}"); + if (APIClient.Headwaiter == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } + + [HttpGet] + public IActionResult Register() { return View(); } - public IActionResult BindingConferenceBindingAndConference() + [HttpPost] + public void Register(string login, string email, string password, string fio, string telephone) { - return View(); - } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/headwaiter/register", new HeadwaiterBindingModel + { + HeadwaiterFIO = fio, + HeadwaiterLogin = login, + HeadwaiterPassword = password, + HeadwaiterEmail = email, + HeadwaiterNumber = telephone + }); - public IActionResult FormationDinner() - { - return View(); - } - - public IActionResult ShapingDinnerIntoRooms() - { - return View(); - } - - public IActionResult FormationOfDinnerInConferenceBookings() - { - return View(); - - } - public IActionResult ListOfMealPlans() - { - return View(); - } - - - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + Response.Redirect("Enter"); + return; } } } \ No newline at end of file diff --git a/Hotel/HostrelHeadwaiterApp/Program.cs b/Hotel/HostrelHeadwaiterApp/Program.cs index 0727468..1400edb 100644 --- a/Hotel/HostrelHeadwaiterApp/Program.cs +++ b/Hotel/HostrelHeadwaiterApp/Program.cs @@ -1,9 +1,12 @@ +using HostrelHeadwaiterApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) diff --git a/Hotel/HostrelHeadwaiterApp/appsettings.json b/Hotel/HostrelHeadwaiterApp/appsettings.json index 10f68b8..e0efc77 100644 --- a/Hotel/HostrelHeadwaiterApp/appsettings.json +++ b/Hotel/HostrelHeadwaiterApp/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "IPAddress": "http://localhost:5079/" } diff --git a/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs new file mode 100644 index 0000000..d243e38 --- /dev/null +++ b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs @@ -0,0 +1,67 @@ +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 HeadwaiterController : Controller + { + private readonly ILogger _logger; + private readonly IHeadwaiterLogic _logic; + public HeadwaiterController(IHeadwaiterLogic logic, ILogger logger) + { + _logger = logger; + _logic = logic; + } + + [HttpGet] + public HeadwaiterViewModel? Login(string login, string password) + { + try + { + return _logic.ReadElement(new HeadwaiterSearchModel + { + HeadwaiterEmail = login, + HeadwaiterPassword = password + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка входа в систему"); + throw; + } + } + + [HttpPost] + public void Register(HeadwaiterBindingModel model) + { + try + { + _logic.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка регистрации"); + throw; + } + } + + [HttpPost] + public void UpdateData(HeadwaiterBindingModel model) + { + try + { + _logic.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных"); + throw; + } + } + } +} diff --git a/Hotel/HotelRestApi/Controllers/MainController.cs b/Hotel/HotelRestApi/Controllers/MainController.cs index 7bda859..6fe62a2 100644 --- a/Hotel/HotelRestApi/Controllers/MainController.cs +++ b/Hotel/HotelRestApi/Controllers/MainController.cs @@ -16,13 +16,19 @@ namespace HotelRestApi.Controllers private readonly IConferenceLogic _conference; private readonly IMemberLogic _member; private readonly IMealPlanLogic _mealPlan; + private readonly IDinnerLogic _dinner; + private readonly IConferenceBookingLogic _conferenceBooking; + private readonly IRoomLogic _room; - public MainController(ILogger logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan) + public MainController(ILogger logger, IConferenceLogic conference, IMemberLogic member, IMealPlanLogic mealPlan, IDinnerLogic dinner, IConferenceBookingLogic conferenceBooking, IRoomLogic room) { _logger = logger; _conference = conference; _member = member; _mealPlan = mealPlan; + _dinner = dinner; + _conferenceBooking = conferenceBooking; + _room = room; } [HttpGet] @@ -76,6 +82,57 @@ namespace HotelRestApi.Controllers } } + [HttpGet] + public List? GetDinnerList(int headwaiterId) + { + try + { + return _dinner.ReadList(new DinnerSearchModel + { + HeadwaiterId = headwaiterId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка обедов"); + throw; + } + } + + [HttpGet] + public List? GetConferenceBookingList(int headwaiterId) + { + try + { + return _conferenceBooking.ReadList(new ConferenceBookingSearchModel + { + HeadwaiterId = headwaiterId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка бронирования по конференциям"); + throw; + } + } + + [HttpGet] + public List? GetRoomPlanList(int headwaiterId) + { + try + { + return _room.ReadList(new RoomSearchModel + { + HeadwaiterId = headwaiterId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка номеров"); + throw; + } + } + [HttpPost] public void UpdateMember(MemberBindingModel model) { @@ -135,6 +192,65 @@ namespace HotelRestApi.Controllers } } + [HttpPost] + public void UpdateDinner(DinnerBindingModel model) + { + try + { + _dinner.Update(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка обновления данных обеда"); + throw; + } + } + + [HttpGet] + public DinnerViewModel? GetDinner(int dinnerId) + { + try + { + return _dinner.ReadElement(new DinnerSearchModel + { + Id = dinnerId + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения обеда по id={Id}", dinnerId); + throw; + } + } + + [HttpPost] + public void CreateDinner(DinnerBindingModel model) + { + try + { + _dinner.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания обеда"); + throw; + } + } + + [HttpPost] + public void DeleteDinner(DinnerBindingModel model) + { + try + { + _dinner.Delete(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления обеда"); + throw; + } + } + [HttpPost] public void CreateConference(ConferenceBindingModel model) { @@ -162,5 +278,33 @@ namespace HotelRestApi.Controllers throw; } } + + [HttpPost] + public void CreateRoom(RoomBindingModel model) + { + try + { + _room.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания комнаты"); + throw; + } + } + + [HttpPost] + public void CreateConferenceBooking(ConferenceBookingBindingModel model) + { + try + { + _conferenceBooking.Create(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания бронирования конференций"); + throw; + } + } } } diff --git a/Hotel/HotelRestApi/Program.cs b/Hotel/HotelRestApi/Program.cs index 6b84045..e4f80d7 100644 --- a/Hotel/HotelRestApi/Program.cs +++ b/Hotel/HotelRestApi/Program.cs @@ -22,6 +22,16 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); + //builder.Services.AddSingleton(); builder.Services.AddControllers(); From 6d5a45f5e8ed9d8f57d932fdc508aef91f464c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 16 May 2023 01:11:49 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A5=D0=BE=D1=82=D1=8F=20=D0=B1=D1=8B=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82=20=D1=80=D0=B5?= =?UTF-8?q?=D0=B3=D0=B8=D1=81=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8F...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Views/Home/Enter.cshtml | 42 ++++++---- .../Views/Home/Index.cshtml | 55 +++++++++---- .../Views/Home/Register.cshtml | 77 ++++++++++++------- .../ConferenceBookingSearchModel.cs | 1 + .../SearchModels/DinnerSearchModel.cs | 1 + .../SearchModels/HeadwaiterSearchModel.cs | 2 +- .../SearchModels/RoomSearchModel.cs | 2 + Hotel/HotelDataBaseImplement/HotelDataBase.cs | 2 +- .../Implemets/DinnerStorage.cs | 15 +++- .../Implemets/HeadwaiterStorage.cs | 8 +- .../Implemets/RoomStorage.cs | 15 +++- ... => 20230515204810_coursework.Designer.cs} | 6 +- ...Create.cs => 20230515204810_coursework.cs} | 4 +- .../Migrations/HotelDataBaseModelSnapshot.cs | 2 +- .../Models/ConferenceBooking.cs | 7 +- Hotel/HotelDataBaseImplement/Models/Dinner.cs | 4 + Hotel/HotelDataBaseImplement/Models/Room.cs | 6 ++ .../Controllers/HeadwaiterController.cs | 2 +- .../Controllers/MainController.cs | 4 +- 19 files changed, 182 insertions(+), 73 deletions(-) rename Hotel/HotelDataBaseImplement/Migrations/{20230405210621_InitialCreate.Designer.cs => 20230515204810_coursework.Designer.cs} (99%) rename Hotel/HotelDataBaseImplement/Migrations/{20230405210621_InitialCreate.cs => 20230515204810_coursework.cs} (99%) diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/Enter.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/Enter.cshtml index 106d3d5..d8a81bd 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Home/Enter.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/Enter.cshtml @@ -1,21 +1,35 @@ @{ ViewData["Title"] = "Enter"; } - + + +
-

Вход в приложение

+

+ Вход +

-
-
Логин:
-
-
-
-
Пароль:
-
-
-
-
-
-
+
+ + +
+
+ + +
+
+
+
+
\ No newline at end of file diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/Index.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/Index.cshtml index 415f5df..a85a072 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Home/Index.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/Index.cshtml @@ -7,17 +7,44 @@ ViewData["Title"] = "Home Page"; } -
-

Заказы

-
- - -
- @{ - if (Model == null) - { -

Авторизируйтесь

- return; - } - } -
\ No newline at end of file + + + +
+
+
+
+
+
+
+

+ Гостиница +

+
+
+
+
+ +
+
+
+
+
+
+
\ No newline at end of file diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/Register.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/Register.cshtml index 69b3425..e3e4879 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Home/Register.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/Register.cshtml @@ -1,33 +1,56 @@ @{ ViewData["Title"] = "Register"; } - + + +
-

Регистрация

+

Регистрация

-
-
ФИО:
-
-
-
-
Логин:
-
-
-
-
Пароль:
-
-
-
-
Электронная почта:
-
-
-
-
Номер телефона:
-
-
-
-
-
-
-
+
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+
+
+
+
+ \ No newline at end of file diff --git a/Hotel/HotelContracts/SearchModels/ConferenceBookingSearchModel.cs b/Hotel/HotelContracts/SearchModels/ConferenceBookingSearchModel.cs index b7c365f..86b965e 100644 --- a/Hotel/HotelContracts/SearchModels/ConferenceBookingSearchModel.cs +++ b/Hotel/HotelContracts/SearchModels/ConferenceBookingSearchModel.cs @@ -5,6 +5,7 @@ namespace HotelContracts.SearchModels { public int? Id { get; set; } public int? HeadwaiterId { get; set; } + public int? ConferenceId { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } } diff --git a/Hotel/HotelContracts/SearchModels/DinnerSearchModel.cs b/Hotel/HotelContracts/SearchModels/DinnerSearchModel.cs index de70027..63aaa03 100644 --- a/Hotel/HotelContracts/SearchModels/DinnerSearchModel.cs +++ b/Hotel/HotelContracts/SearchModels/DinnerSearchModel.cs @@ -4,6 +4,7 @@ namespace HotelContracts.SearchModels public class DinnerSearchModel { public string? DinnerName { get; set; } + public int? HeadwaiterId { get; set; } public int? Id { get; set; } } } diff --git a/Hotel/HotelContracts/SearchModels/HeadwaiterSearchModel.cs b/Hotel/HotelContracts/SearchModels/HeadwaiterSearchModel.cs index be9b68c..f0c0835 100644 --- a/Hotel/HotelContracts/SearchModels/HeadwaiterSearchModel.cs +++ b/Hotel/HotelContracts/SearchModels/HeadwaiterSearchModel.cs @@ -6,7 +6,7 @@ namespace HotelContracts.SearchModels public string? HeadwaiterFIO { get; set; } public string? HeadwaiterPassword { get; set; } - + public string? HeadwaiterEmail { get; set; } public string? HeadwaiterLogin { get; set; } public int? Id { get; set; } } diff --git a/Hotel/HotelContracts/SearchModels/RoomSearchModel.cs b/Hotel/HotelContracts/SearchModels/RoomSearchModel.cs index 415e89c..bc11b0b 100644 --- a/Hotel/HotelContracts/SearchModels/RoomSearchModel.cs +++ b/Hotel/HotelContracts/SearchModels/RoomSearchModel.cs @@ -4,6 +4,8 @@ namespace HotelContracts.SearchModels public class RoomSearchModel { public string? RoomName { get; set; } + public int? HeadwaiterId { get; set; } + public int? MealPlanId { get; set; } public int? Id { get; set; } } } diff --git a/Hotel/HotelDataBaseImplement/HotelDataBase.cs b/Hotel/HotelDataBaseImplement/HotelDataBase.cs index 6d7ccea..7141379 100644 --- a/Hotel/HotelDataBaseImplement/HotelDataBase.cs +++ b/Hotel/HotelDataBaseImplement/HotelDataBase.cs @@ -9,7 +9,7 @@ namespace HotelDataBaseImplement { if (optionsBuilder.IsConfigured == false) { - optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-VG5USAH\SQLEXPRESS;Initial Catalog=HotelDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-V0ON61E\SQLEXPRESS;Initial Catalog=HotelDataBaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/Hotel/HotelDataBaseImplement/Implemets/DinnerStorage.cs b/Hotel/HotelDataBaseImplement/Implemets/DinnerStorage.cs index 99d319b..ac92384 100644 --- a/Hotel/HotelDataBaseImplement/Implemets/DinnerStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implemets/DinnerStorage.cs @@ -51,13 +51,26 @@ namespace HotelDataBaseImplement.Implemets public List GetFilteredList(DinnerSearchModel model) { - if (string.IsNullOrEmpty(model.DinnerName)) + if (string.IsNullOrEmpty(model.DinnerName) && !model.HeadwaiterId.HasValue) { return new(); } using var context = new HotelDataBase(); + if (model.HeadwaiterId.HasValue) + { + return context.Dinners + .Include(x => x.RoomDinners) + .ThenInclude(x => x.Room) + .Include(x => x.ConferenceBookingDinners) + .ThenInclude(x => x.ConferenceBooking) + .Where(x => x.DinnerName.Contains(model.DinnerName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + return context.Dinners .Include(x => x.RoomDinners) .ThenInclude(x => x.Room) diff --git a/Hotel/HotelDataBaseImplement/Implemets/HeadwaiterStorage.cs b/Hotel/HotelDataBaseImplement/Implemets/HeadwaiterStorage.cs index b3ea8b3..8b5b961 100644 --- a/Hotel/HotelDataBaseImplement/Implemets/HeadwaiterStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implemets/HeadwaiterStorage.cs @@ -43,20 +43,20 @@ namespace HotelDataBaseImplement.Implemets .FirstOrDefault(x => x.Id == model.Id)? .GetViewModel; - if (!string.IsNullOrEmpty(model.HeadwaiterLogin) && !string.IsNullOrEmpty(model.HeadwaiterPassword)) + if (!string.IsNullOrEmpty(model.HeadwaiterEmail) && !string.IsNullOrEmpty(model.HeadwaiterPassword)) return context.Headwaiters .Include(x => x.ConferenceBookings) .Include(x => x.Dinners) .Include(x => x.Rooms) - .FirstOrDefault(x => x.HeadwaiterLogin.Equals(model.HeadwaiterLogin) && x.HeadwaiterPassword.Equals(model.HeadwaiterPassword))? + .FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail) && x.HeadwaiterPassword.Equals(model.HeadwaiterPassword))? .GetViewModel; - if (!string.IsNullOrEmpty(model.HeadwaiterLogin)) + if (!string.IsNullOrEmpty(model.HeadwaiterEmail)) return context.Headwaiters .Include(x => x.ConferenceBookings) .Include(x => x.Dinners) .Include(x => x.Rooms) - .FirstOrDefault(x => x.HeadwaiterLogin.Equals(model.HeadwaiterLogin))? + .FirstOrDefault(x => x.HeadwaiterEmail.Equals(model.HeadwaiterEmail))? .GetViewModel; return null; diff --git a/Hotel/HotelDataBaseImplement/Implemets/RoomStorage.cs b/Hotel/HotelDataBaseImplement/Implemets/RoomStorage.cs index 7e2a696..f6944de 100644 --- a/Hotel/HotelDataBaseImplement/Implemets/RoomStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implemets/RoomStorage.cs @@ -34,13 +34,26 @@ namespace HotelDataBaseImplement.Implemets public RoomViewModel? GetElement(RoomSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.HeadwaiterId.HasValue) { return null; } using var context = new HotelDataBase(); + if (model.HeadwaiterId.HasValue) + { + return context.Rooms + .Include(x => x.Dinners) + .ThenInclude(x => x.Dinner) + .ThenInclude(x => x.ConferenceBookingDinners) + .ThenInclude(x => x.ConferenceBooking) + .Include(x => x.MealPlan) + .Include(x => x.Headwaiter) + .FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))? + .GetViewModel; + } + return context.Rooms .Include(x => x.Dinners) .ThenInclude(x => x.Dinner) diff --git a/Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.Designer.cs b/Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.Designer.cs similarity index 99% rename from Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.Designer.cs rename to Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.Designer.cs index f7d7eae..f08f1b9 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.Designer.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.Designer.cs @@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace HotelDataBaseImplement.Migrations { [DbContext(typeof(HotelDataBase))] - [Migration("20230405210621_InitialCreate")] - partial class InitialCreate + [Migration("20230515204810_coursework")] + partial class coursework { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -137,7 +137,7 @@ namespace HotelDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("DinnetPrice") + b.Property("DinnerPrice") .HasColumnType("float"); b.Property("HeadwaiterId") diff --git a/Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.cs b/Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.cs similarity index 99% rename from Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.cs rename to Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.cs index a053bcd..6cf35bd 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20230405210621_InitialCreate.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20230515204810_coursework.cs @@ -6,7 +6,7 @@ using Microsoft.EntityFrameworkCore.Migrations; namespace HotelDataBaseImplement.Migrations { /// - public partial class InitialCreate : Migration + public partial class coursework : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -53,7 +53,7 @@ namespace HotelDataBaseImplement.Migrations .Annotation("SqlServer:Identity", "1, 1"), HeadwaiterId = table.Column(type: "int", nullable: false), DinnerName = table.Column(type: "nvarchar(max)", nullable: false), - DinnetPrice = table.Column(type: "float", nullable: false) + DinnerPrice = table.Column(type: "float", nullable: false) }, constraints: table => { diff --git a/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs b/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs index 8faf864..2cdf55b 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs @@ -134,7 +134,7 @@ namespace HotelDataBaseImplement.Migrations .IsRequired() .HasColumnType("nvarchar(max)"); - b.Property("DinnetPrice") + b.Property("DinnerPrice") .HasColumnType("float"); b.Property("HeadwaiterId") diff --git a/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs b/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs index 4bc30cb..c743a1d 100644 --- a/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs +++ b/Hotel/HotelDataBaseImplement/Models/ConferenceBooking.cs @@ -40,6 +40,8 @@ namespace HotelDataBaseImplement.Models return new ConferenceBooking() { Id = model.Id, + ConferenceId = model.ConferenceId, + HeadwaiterId = model.HeadwaiterId, Dinners = model.ConferenceBookingDinners.Select(x => new ConferenceBookingDinner { Dinner = context.Dinners.First(y => y.Id == x.Key), @@ -49,12 +51,15 @@ namespace HotelDataBaseImplement.Models public void Update(ConferenceBookingBindingModel model) { - + ConferenceId = model.ConferenceId; + HeadwaiterId = model.HeadwaiterId; } public ConferenceBookingViewModel GetViewModel => new() { Id = Id, + ConferenceId = ConferenceId, + HeadwaiterId = HeadwaiterId, ConferenceBookingDinners = ConferenceBookingDinners }; diff --git a/Hotel/HotelDataBaseImplement/Models/Dinner.cs b/Hotel/HotelDataBaseImplement/Models/Dinner.cs index e77ac60..1786813 100644 --- a/Hotel/HotelDataBaseImplement/Models/Dinner.cs +++ b/Hotel/HotelDataBaseImplement/Models/Dinner.cs @@ -39,6 +39,7 @@ namespace HotelDataBaseImplement.Models { Id = model.Id, DinnerName = model.DinnerName, + HeadwaiterId = model.HeadwaiterId, DinnerPrice = model.DinnerPrice }; } @@ -48,6 +49,7 @@ namespace HotelDataBaseImplement.Models { Id = model.Id, DinnerName = model.DinnerName, + HeadwaiterId = model.HeadwaiterId, DinnerPrice = model.DinnerPrice }; } @@ -57,6 +59,7 @@ namespace HotelDataBaseImplement.Models { return; } + HeadwaiterId = model.HeadwaiterId; DinnerName = model.DinnerName; DinnerPrice = model.DinnerPrice; } @@ -64,6 +67,7 @@ namespace HotelDataBaseImplement.Models { Id = Id, DinnerName = DinnerName, + HeadwaiterId = HeadwaiterId, DinnerPrice = DinnerPrice }; } diff --git a/Hotel/HotelDataBaseImplement/Models/Room.cs b/Hotel/HotelDataBaseImplement/Models/Room.cs index 0e1e914..7f5ef76 100644 --- a/Hotel/HotelDataBaseImplement/Models/Room.cs +++ b/Hotel/HotelDataBaseImplement/Models/Room.cs @@ -50,6 +50,8 @@ namespace HotelDataBaseImplement.Models RoomName = model.RoomName, RoomFrame = model.RoomFrame, RoomPrice = model.RoomPrice, + HeadwaiterId = model.HeadwaiterId, + MealPlanId = model.MealPlanId, Dinners = model.RoomDinners.Select(x => new RoomDinner { Dinner = context.Dinners.First(y => y.Id == x.Key), @@ -62,6 +64,8 @@ namespace HotelDataBaseImplement.Models RoomName = model.RoomName; RoomFrame = model.RoomFrame; RoomPrice = model.RoomPrice; + HeadwaiterId = model.HeadwaiterId; + MealPlanId = model.MealPlanId; } public RoomViewModel GetViewModel => new() @@ -69,6 +73,8 @@ namespace HotelDataBaseImplement.Models Id = Id, RoomName = RoomName, RoomFrame = RoomFrame, + HeadwaiterId = HeadwaiterId, + MealPlanId = MealPlanId, RoomPrice = RoomPrice, RoomDinners = RoomDinners }; diff --git a/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs index d243e38..886f4e3 100644 --- a/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs +++ b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs @@ -25,7 +25,7 @@ namespace HotelRestApi.Controllers { return _logic.ReadElement(new HeadwaiterSearchModel { - HeadwaiterEmail = login, + //HeadwaiterEmail = login, HeadwaiterPassword = password }); } diff --git a/Hotel/HotelRestApi/Controllers/MainController.cs b/Hotel/HotelRestApi/Controllers/MainController.cs index 6fe62a2..ba2db37 100644 --- a/Hotel/HotelRestApi/Controllers/MainController.cs +++ b/Hotel/HotelRestApi/Controllers/MainController.cs @@ -89,7 +89,7 @@ namespace HotelRestApi.Controllers { return _dinner.ReadList(new DinnerSearchModel { - HeadwaiterId = headwaiterId, + //HeadwaiterId = headwaiterId, }); } catch (Exception ex) @@ -123,7 +123,7 @@ namespace HotelRestApi.Controllers { return _room.ReadList(new RoomSearchModel { - HeadwaiterId = headwaiterId, + //HeadwaiterId = headwaiterId, }); } catch (Exception ex) From 3ee0e9dc0ea0bcdec4791a3c917dce9faa00e275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Tue, 16 May 2023 14:40:22 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=92=D1=81=D0=B5=20=D1=8D=D1=82=D0=BE=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20=D0=BE=D0=BD=D0=BE=20=D0=B8?= =?UTF-8?q?=D0=B7=20=D0=B7=D0=B0=20=D1=8D=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BB=D0=BE....?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Hotel/HotelRestApi/Controllers/HeadwaiterController.cs | 2 +- Hotel/HotelRestApi/Controllers/MainController.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs index 886f4e3..d243e38 100644 --- a/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs +++ b/Hotel/HotelRestApi/Controllers/HeadwaiterController.cs @@ -25,7 +25,7 @@ namespace HotelRestApi.Controllers { return _logic.ReadElement(new HeadwaiterSearchModel { - //HeadwaiterEmail = login, + HeadwaiterEmail = login, HeadwaiterPassword = password }); } diff --git a/Hotel/HotelRestApi/Controllers/MainController.cs b/Hotel/HotelRestApi/Controllers/MainController.cs index ba2db37..6fe62a2 100644 --- a/Hotel/HotelRestApi/Controllers/MainController.cs +++ b/Hotel/HotelRestApi/Controllers/MainController.cs @@ -89,7 +89,7 @@ namespace HotelRestApi.Controllers { return _dinner.ReadList(new DinnerSearchModel { - //HeadwaiterId = headwaiterId, + HeadwaiterId = headwaiterId, }); } catch (Exception ex) @@ -123,7 +123,7 @@ namespace HotelRestApi.Controllers { return _room.ReadList(new RoomSearchModel { - //HeadwaiterId = headwaiterId, + HeadwaiterId = headwaiterId, }); } catch (Exception ex)