diff --git a/Hotel/HotelAdministratorApp/Controllers/HomeController.cs b/Hotel/HotelAdministratorApp/Controllers/HomeController.cs index 3bbfcb4..5611868 100644 --- a/Hotel/HotelAdministratorApp/Controllers/HomeController.cs +++ b/Hotel/HotelAdministratorApp/Controllers/HomeController.cs @@ -3,11 +3,13 @@ using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; using HotelContracts.ViewModels; +using HotelDataBaseImplement; using HotelDataBaseImplement.Models; using HotelDataModels.Models; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using System.Diagnostics; +using System.Globalization; using System.Numerics; namespace HotelAdministratorApp.Controllers @@ -484,20 +486,175 @@ namespace HotelAdministratorApp.Controllers { throw new Exception("Вы как сюда попали? Сюда вход только авторизованным"); } - var roomElem = APIClient.GetRequest($"api/main/getroombyid?roomId={room}"); - APIClient.PostRequest("api/main/updateroom", new RoomBindingModel + using var context = new HotelDataBase(); + var roomElem = APIClient.GetRequest($"api/main/getroombyid?roomId={room}"); + var dinners = _dinner.ReadList(new DinnerSearchModel { AdministratorId = APIClient.Administrator.Id }); + + APIClient.PostRequest("api/main/updateroom", new RoomBindingModel { Id = room, MealPlanId = mealplan, RoomNumber = roomElem.RoomNumber, DateCreate = roomElem.DateCreate, RoomPrice = roomElem.RoomPrice, + /*RoomDinners = roomElemrs,*/ AdministratorId = roomElem.AdministratorId, }); Response.Redirect("Rooms"); } + [HttpGet] + public IActionResult MealPlanDinnerReport() + { + if (APIClient.Administrator == null) + { + return Redirect("~/Home/Enter"); + } + ViewBag.Dinners = APIClient.GetRequest>($"api/main/getdinnerlist?administratorid={APIClient.Administrator.Id}"); + return View(); + } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [HttpPost] + public void MealPlanDinnerReport(List dinners, string type) + { + if (APIClient.Administrator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (dinners.Count <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + if (type == "docx") + { + APIClient.PostRequest("api/reportadministrator/createmealplanlistwordfile", new ReportMealPlanDinnerBindingModel + { + Dinners = dinners, + FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/reportadministrator/createmealplanlistexcelfile", new ReportMealPlanDinnerBindingModel + { + Dinners = dinners, + FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\exelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\exelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + [HttpGet] + public IActionResult Report() + { + ViewBag.Report = new List(); + return View(); + } + + [HttpGet] + public string GetDinnersReport(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Administrator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + List result; + try + { + string dateFromS = dateFrom.ToString("s", CultureInfo.InvariantCulture); + string dateToS = dateTo.ToString("s", CultureInfo.InvariantCulture); + result = APIClient.GetRequest> + ($"api/reportadministrator/getroomsconferencesreport?datefrom={dateFromS}&dateto={dateToS}&administratorid={APIClient.Administrator.Id}")!; + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + string table = ""; + table += "

Предварительный отчет

"; + table += "
"; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + table += ""; + foreach (var dinner in result) + { + table += ""; + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + foreach (var room in dinner.Rooms) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + foreach (var conference in dinner.Conferences) + { + table += ""; + table += $""; + table += $""; + table += $""; + table += $""; + table += ""; + } + table += ""; + } + table += "
ДатаНазвание обедаНомер комнатыНазвание конференции
{dinner.DinnerName}
{room.DateCreate}{room.RoomNumber}
{conference.StartDate}{conference.ConferenceName}
"; + table += "
"; + return table; + } + + [HttpPost] + public void AddDinnerToFile(DateTime dateFrom, DateTime dateTo) + { + if (APIClient.Administrator == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + APIClient.PostRequest("api/reportadministrator/SendRoomsConferencesReportToEmail", new ReportRoomsConferenceBindingModel + { + FileName = "C:\\Users\\sshan\\OneDrive\\Desktop\\reports\\reportpdf.pdf", + AdministratorId = APIClient.Administrator.Id, + DateFrom = dateFrom, + DateTo = dateTo, + Email = APIClient.Administrator.AdministratorEmail, + + }); + Response.Redirect("AddDinnerToFile"); + + } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/Hotel/HotelAdministratorApp/Program.cs b/Hotel/HotelAdministratorApp/Program.cs index 664e2d1..0e95034 100644 --- a/Hotel/HotelAdministratorApp/Program.cs +++ b/Hotel/HotelAdministratorApp/Program.cs @@ -1,5 +1,7 @@ using HotelAdministratorApp; using HotelBusinessLogic.BusinessLogic; +using HotelBusinessLogic.OfficePackage; +using HotelBusinessLogic.OfficePackage.Implements; using HotelContracts.BusinessLogicsContracts; using HotelContracts.StoragesContracts; using HotelDataBaseImplement.Implements; @@ -11,6 +13,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); var app = builder.Build(); APIClient.Connect(builder.Configuration); // Configure the HTTP request pipeline. diff --git a/Hotel/HotelAdministratorApp/Views/Home/AddDinnerToFile.cshtml b/Hotel/HotelAdministratorApp/Views/Home/AddDinnerToFile.cshtml index bb93718..6cdd5f7 100644 --- a/Hotel/HotelAdministratorApp/Views/Home/AddDinnerToFile.cshtml +++ b/Hotel/HotelAdministratorApp/Views/Home/AddDinnerToFile.cshtml @@ -23,17 +23,37 @@ - -
- - -
+
- +
- +
- \ No newline at end of file +
+ + +@section Scripts { + +} \ No newline at end of file diff --git a/Hotel/HotelAdministratorApp/Views/Home/AddDinnerRoomToFiles.cshtml b/Hotel/HotelAdministratorApp/Views/Home/MealPlanDinnerReport.cshtml similarity index 54% rename from Hotel/HotelAdministratorApp/Views/Home/AddDinnerRoomToFiles.cshtml rename to Hotel/HotelAdministratorApp/Views/Home/MealPlanDinnerReport.cshtml index 30b9e81..8056c34 100644 --- a/Hotel/HotelAdministratorApp/Views/Home/AddDinnerRoomToFiles.cshtml +++ b/Hotel/HotelAdministratorApp/Views/Home/MealPlanDinnerReport.cshtml @@ -1,5 +1,6 @@ -@{ - ViewData["Title"] = "AddDinnerRoomToFiles"; +@using HotelContracts.ViewModels +@{ + ViewData["Title"] = "MealPlanDinnerReport"; } @@ -11,33 +12,28 @@
- +
- +
- - - - - - - - - - -
- Название - - Калорийность - - Цена -
+
+
+
Обеды:
+
+ +
+

- +
\ No newline at end of file diff --git a/Hotel/HotelAdministratorApp/Views/Shared/_Layout.cshtml b/Hotel/HotelAdministratorApp/Views/Shared/_Layout.cshtml index 059c7e6..8ded28f 100644 --- a/Hotel/HotelAdministratorApp/Views/Shared/_Layout.cshtml +++ b/Hotel/HotelAdministratorApp/Views/Shared/_Layout.cshtml @@ -59,7 +59,7 @@