From 560865010e3d6daede4a24188f376a72148f3e52 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: Thu, 18 May 2023 18:09:59 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=90=D0=B1=D0=B0=D0=BB=D0=B4=D0=B5=D1=82?= =?UTF-8?q?=D1=8C,=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D1=8B=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D0=B0=D1=8E=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 68 +++++++++++++++ .../HotelHeadwaiterApp.csproj | 2 + .../Views/Home/ListDinnerRoomToFile.cshtml | 73 ++++++++++++++++ .../Views/Shared/_Layout.cshtml | 2 + .../BusinessLogics/ReportLogicHeadwaiter.cs | 87 ++++++++++--------- .../AbstractSaveToExcelHeadwaiter.cs | 4 +- .../AbstractSaveToPdfHeadwaiter.cs | 4 +- .../AbstractSaveToWordHeadwaiter.cs | 6 +- .../HelperModels/ExcelInfoHeadwaiter.cs | 2 +- .../HelperModels/PdfInfoHeadwaiter.cs | 2 +- .../HelperModels/WordInfoHeadwaiter.cs | 2 +- .../Implements/SaveToPdfHeadwaiter.cs | 2 +- .../ReportHeadwaiterBindingModel.cs.cs | 4 +- .../IReportHeadwaiterLogic.cs | 10 +-- ...wModel.cs => ReportDinnerRoomViewModel.cs} | 4 +- ...ViewModel.cs => ReportDinnersViewModel.cs} | 4 +- Hotel/HotelDataBaseImplement/HotelDataBase.cs | 2 +- .../Controllers/ReportController.cs | 32 ++++++- Hotel/HotelRestApi/Program.cs | 5 ++ 19 files changed, 253 insertions(+), 62 deletions(-) create mode 100644 Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnerRoomToFile.cshtml rename Hotel/HotelContracts/ViewModels/{ReportMealPlanDinnerViewModel.cs => ReportDinnerRoomViewModel.cs} (65%) rename Hotel/HotelContracts/ViewModels/{ReportConferenceBindingRoomsViewModel.cs => ReportDinnersViewModel.cs} (69%) diff --git a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs index 1658910..ec8b5e8 100644 --- a/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs +++ b/Hotel/HostrelHeadwaiterApp/Controllers/HomeController.cs @@ -554,5 +554,73 @@ namespace HostrelHeadwaiterApp.Controllers }); Response.Redirect("ListConferenceBookings"); } + + /*--------------------Reports------------------------*/ + + [HttpGet] + public IActionResult ListDinnerRoomToFile() + { + if (APIClient.Headwaiter == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getdinnerlist?headwaiterId={APIClient.Headwaiter.Id}")); + } + + [HttpPost] + public void ListDinnerRoomToFile(int[] Ids, string type) + { + if (APIClient.Headwaiter == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + + if (Ids.Length <= 0) + { + throw new Exception("Количество должно быть больше 0"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Неверный тип отчета"); + } + + List res = new List(); + + foreach (var item in Ids) + { + res.Add(item); + } + + if (type == "docx") + { + APIClient.PostRequest("api/report/createheadwaiterreporttowordfile", new ReportHeadwaiterBindingModel + { + Ids = res, + FileName = "E:\\ReportsCourseWork\\wordfile.docx" + }); + Response.Redirect("GetWordFile"); + } + else + { + APIClient.PostRequest("api/report/createheadwaiterreporttoexcelfile", new ReportHeadwaiterBindingModel + { + Ids = res, + FileName = "E:\\ReportsCourseWork\\excelfile.xlsx" + }); + Response.Redirect("GetExcelFile"); + } + } + + [HttpGet] + public IActionResult GetWordFile() + { + return new PhysicalFileResult("E:\\ReportsCourseWork\\wordfile.docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + + public IActionResult GetExcelFile() + { + return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } } } \ No newline at end of file diff --git a/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj b/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj index b7c9b39..6dc593f 100644 --- a/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj +++ b/Hotel/HostrelHeadwaiterApp/HotelHeadwaiterApp.csproj @@ -8,10 +8,12 @@ + + diff --git a/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnerRoomToFile.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnerRoomToFile.cshtml new file mode 100644 index 0000000..69473fd --- /dev/null +++ b/Hotel/HostrelHeadwaiterApp/Views/Home/ListDinnerRoomToFile.cshtml @@ -0,0 +1,73 @@ +@using HotelContracts.ViewModels + +@model List + +@{ + ViewData["Title"] = "ListDinnerRoomToFile"; +} + +
+
+

Создание отчета по обедам

+
+
+ +
+
+
+ +
+ + +
+
+ + +
+
+
+ + + + + + + + + + @foreach (var item in Model) + { + + + + + + } + +
ОбедЦена
+
+ +
+
@Html.DisplayFor(modelItem => item.DinnerName)@Html.DisplayFor(modelItem => item.DinnerPrice)
+
+
+
+ +
+
+
+ + diff --git a/Hotel/HostrelHeadwaiterApp/Views/Shared/_Layout.cshtml b/Hotel/HostrelHeadwaiterApp/Views/Shared/_Layout.cshtml index 6cbae9d..24a9fdc 100644 --- a/Hotel/HostrelHeadwaiterApp/Views/Shared/_Layout.cshtml +++ b/Hotel/HostrelHeadwaiterApp/Views/Shared/_Layout.cshtml @@ -37,6 +37,8 @@ Аутентификация + Отчет (word/excel) + diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs index ef2dd77..77a459e 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogicHeadwaiter.cs @@ -17,45 +17,48 @@ namespace HotelBusinessLogic.BusinessLogics { private readonly IRoomStorage _roomStorage; private readonly IDinnerStorage _dinnerStorage; - private readonly IMealPlanStorage _mealPlansStorage; private readonly IConferenceBookingStorage _conferenceBookingStorage; private readonly AbstractSaveToExcelHeadwaiter _saveToExcel; private readonly AbstractSaveToWordHeadwaitre _saveToWord; private readonly AbstractSaveToPdfHeadwaiter _saveToPdf; - public ReportLogicHeadwaiter(IRoomStorage roomStorage, IDinnerStorage dinnerStorage, IMealPlanStorage mealPlansStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf) + public ReportLogicHeadwaiter(IRoomStorage roomStorage, IDinnerStorage dinnerStorage, IConferenceBookingStorage conferenceBookingStorage, AbstractSaveToExcelHeadwaiter saveToExcel, AbstractSaveToWordHeadwaitre saveToWord, AbstractSaveToPdfHeadwaiter saveToPdf) { _roomStorage = roomStorage; _dinnerStorage = dinnerStorage; - _mealPlansStorage = mealPlansStorage; _conferenceBookingStorage = conferenceBookingStorage; _saveToExcel = saveToExcel; _saveToWord = saveToWord; _saveToPdf = saveToPdf; } - public List GetMealPlanDinner() + public List GetDinnerRoom(List Ids) { - var mealPlans = _mealPlansStorage.GetFullList(); - var dinners = _dinnerStorage.GetFullList(); + if (Ids == null) + { + return new List(); + } var rooms = _roomStorage.GetFullList(); - var list = new List(); + List dinners = new List(); + foreach (var memId in Ids) + { + var res = _dinnerStorage.GetElement(new DinnerSearchModel { Id = memId }); + if (res != null) + { + dinners.Add(res); + } + } + var list = new List(); foreach (var dinner in dinners) { - var record = new ReportMealPlanDinnerViewModel + var record = new ReportDinnerRoomViewModel { DinnerName = dinner.DinnerName, - MealPlans = new List>() + Rooms = new List>() }; foreach (var room in rooms) { if (room.RoomDinners.ContainsKey(dinner.Id)) { - foreach (var mealPlan in mealPlans) - { - if (mealPlan.MealPlanRooms.ContainsKey(room.Id)) - { - record.MealPlans.Add(new Tuple(mealPlan.MealPlanName, mealPlan.MealPlanPrice)); - } - } + record.Rooms.Add(new Tuple(room.RoomName, room.RoomPrice)); } } list.Add(record); @@ -63,26 +66,34 @@ namespace HotelBusinessLogic.BusinessLogics return list; } - public List GetConferenceBindingRooms(ReportHeadwaiterBindingModel model) + public List GetDinners(ReportHeadwaiterBindingModel model) { - var listAll = new List(); + var listAll = new List(); - var listConferenceBinding = _conferenceBookingStorage.GetFilteredList(new ConferenceBookingSearchModel + var listСonferences = _roomStorage.GetFilteredList(new RoomSearchModel { HeadwaiterId = model.HeadwaiterId, - DateFrom = model.DateFrom, - DateTo = model.DateTo + RoomName = model.RoomName, }); - var listRooms = _roomStorage.GetFilteredList(new RoomSearchModel()); - - foreach (var room in listRooms) + foreach (var room in listСonferences) { - listAll.Add(new ReportConferenceBindingRoomsViewModel + foreach (var c in room.RoomDinners) { - RoomName = room.RoomName, - RoomPrice = room.RoomPrice, - RoomFrame = room.RoomFrame + listAll.Add(new ReportDinnersViewModel + { + RoomName = room.RoomName, + DinnerName = c.Value.DinnerName + }); + } + } + var listConferenceBookings = _conferenceBookingStorage.GetFilteredList(new ConferenceBookingSearchModel()); + + foreach (var conferenceBooking in listConferenceBookings) + { + listAll.Add(new ReportDinnersViewModel + { + NameHall = conferenceBooking.NameHall }); } @@ -90,35 +101,33 @@ namespace HotelBusinessLogic.BusinessLogics return listAll; } - public void SaveMealPlanDinnerToExcelFile(ReportHeadwaiterBindingModel model) + public void SaveDinnerRoomToExcelFile(ReportHeadwaiterBindingModel model) { _saveToExcel.CreateReport(new ExcelInfoHeadwaiter { FileName = model.FileName, - Title = "Список участников", - MealPlanDinner = GetMealPlanDinner() + Title = "Список номеров", + DinnerRooms = GetDinnerRoom(model.Ids) }); } - public void SaveMealPlanDinnerToWordFile(ReportHeadwaiterBindingModel model) + public void SaveDinnerRoomToWordFile(ReportHeadwaiterBindingModel model) { _saveToWord.CreateDoc(new WordInfoHeadwaiter { FileName = model.FileName, - Title = "Список участников", - MealPlanDinner = GetMealPlanDinner() + Title = "Список номеров", + DinnerRooms = GetDinnerRoom(model.Ids) }); } - public void SaveConferenceBindingRoomsToPdfFile(ReportHeadwaiterBindingModel model) + public void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model) { _saveToPdf.CreateDoc(new PdfInfoHeadwaiter { FileName = model.FileName, - Title = "Список участников", - DateFrom = model.DateFrom!.Value, - DateTo = model.DateTo!.Value, - ConferenceBindingRooms = GetConferenceBindingRooms(model) + Title = "Список обедов", + Dinners = GetDinners(model) }); } } diff --git a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToExcelHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToExcelHeadwaiter.cs index 0af9d13..84b7c3f 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToExcelHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToExcelHeadwaiter.cs @@ -30,7 +30,7 @@ namespace HotelBusinessLogic.OfficePackage uint rowIndex = 2; - foreach (var mc in info.MealPlanDinner) + foreach (var mc in info.DinnerRooms) { InsertCellInWorksheet(new ExcelCellParameters { @@ -42,7 +42,7 @@ namespace HotelBusinessLogic.OfficePackage rowIndex++; - foreach (var mealPlan in mc.MealPlans) + foreach (var mealPlan in mc.Rooms) { InsertCellInWorksheet(new ExcelCellParameters { diff --git a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs index e46d9e1..b709298 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToPdfHeadwaiter.cs @@ -32,7 +32,7 @@ namespace HotelBusinessLogic.OfficePackage Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center }); - foreach (var conferenceBindingRooms in info.ConferenceBindingRooms) + foreach (var conferenceBindingRooms in info.Dinners) { CreateRow(new PdfRowParameters { @@ -43,7 +43,7 @@ namespace HotelBusinessLogic.OfficePackage } CreateParagraph(new PdfParagraph { - Text = $"Итого: {info.ConferenceBindingRooms.Sum(x => x.RoomPrice)}\t", + Text = $"Итого: {info.Dinners.Sum(x => x.RoomPrice)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Rigth }); diff --git a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaiter.cs index 568a543..387a752 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/AbstractSaveToWordHeadwaiter.cs @@ -24,12 +24,12 @@ namespace HotelBusinessLogic.OfficePackage } }); - foreach (var mc in info.MealPlanDinner) + foreach (var mc in info.DinnerRooms) { CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> - { (mc.DinnerName+" - ", new WordTextProperties { Size = "24", Bold=true})}, + { (mc.DinnerName, new WordTextProperties { Size = "24", Bold=true})}, TextProperties = new WordTextProperties { Size = "24", @@ -37,7 +37,7 @@ namespace HotelBusinessLogic.OfficePackage } }); - foreach (var mealPlan in mc.MealPlans) + foreach (var mealPlan in mc.Rooms) { CreateParagraph(new WordParagraph { diff --git a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/ExcelInfoHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/ExcelInfoHeadwaiter.cs index 9872e4e..7f4e462 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/ExcelInfoHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/ExcelInfoHeadwaiter.cs @@ -11,7 +11,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List MealPlanDinner + public List DinnerRooms { get; set; diff --git a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs index 73620d8..12262da 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/PdfInfoHeadwaiter.cs @@ -13,6 +13,6 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } public DateTime DateTo { get; set; } - public List ConferenceBindingRooms { get; set; } = new(); + public List Dinners { get; set; } = new(); } } diff --git a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/WordInfoHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/WordInfoHeadwaiter.cs index 67ca4b0..b39521a 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/WordInfoHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/HelperModels/WordInfoHeadwaiter.cs @@ -11,6 +11,6 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; - public List MealPlanDinner { get; set; } = new(); + public List DinnerRooms { get; set; } = new(); } } diff --git a/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfHeadwaiter.cs b/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfHeadwaiter.cs index 871ab00..c8e3350 100644 --- a/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfHeadwaiter.cs +++ b/Hotel/HotelBusinessLogic/OfficePackage/Implements/SaveToPdfHeadwaiter.cs @@ -11,7 +11,7 @@ using System.Threading.Tasks; namespace HotelBusinessLogic.OfficePackage.Implements { - internal class SaveToPdfHeadwaiter : AbstractSaveToPdfHeadwaiter + public class SaveToPdfHeadwaiter : AbstractSaveToPdfHeadwaiter { private Document? _document; private Section? _section; diff --git a/Hotel/HotelContracts/BindingModels/ReportHeadwaiterBindingModel.cs.cs b/Hotel/HotelContracts/BindingModels/ReportHeadwaiterBindingModel.cs.cs index 0e8bf74..9dbd4fd 100644 --- a/Hotel/HotelContracts/BindingModels/ReportHeadwaiterBindingModel.cs.cs +++ b/Hotel/HotelContracts/BindingModels/ReportHeadwaiterBindingModel.cs.cs @@ -9,8 +9,8 @@ namespace HotelContracts.BindingModels public class ReportHeadwaiterBindingModel { public string FileName { get; set; } = string.Empty; - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } + public string RoomName { get; set; } = string.Empty; + public List? Ids { get; set; } public int HeadwaiterId { get; set; } } } diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IReportHeadwaiterLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IReportHeadwaiterLogic.cs index 7e0f69a..569619a 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IReportHeadwaiterLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IReportHeadwaiterLogic.cs @@ -10,10 +10,10 @@ namespace HotelContracts.BusinessLogicsContracts { public interface IReportHeadwaiterLogic { - List GetMealPlanDinner(); - List GetConferenceBindingRooms(ReportHeadwaiterBindingModel model); - void SaveMealPlanDinnerToWordFile(ReportHeadwaiterBindingModel model); - void SaveMealPlanDinnerToExcelFile(ReportHeadwaiterBindingModel model); - void SaveConferenceBindingRoomsToPdfFile(ReportHeadwaiterBindingModel model); + List GetDinnerRoom(List Ids); + List GetDinners(ReportHeadwaiterBindingModel model); + void SaveDinnerRoomToWordFile(ReportHeadwaiterBindingModel model); + void SaveDinnerRoomToExcelFile(ReportHeadwaiterBindingModel model); + void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model); } } diff --git a/Hotel/HotelContracts/ViewModels/ReportMealPlanDinnerViewModel.cs b/Hotel/HotelContracts/ViewModels/ReportDinnerRoomViewModel.cs similarity index 65% rename from Hotel/HotelContracts/ViewModels/ReportMealPlanDinnerViewModel.cs rename to Hotel/HotelContracts/ViewModels/ReportDinnerRoomViewModel.cs index 2ea18cf..8523146 100644 --- a/Hotel/HotelContracts/ViewModels/ReportMealPlanDinnerViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ReportDinnerRoomViewModel.cs @@ -6,10 +6,10 @@ using System.Threading.Tasks; namespace HotelContracts.ViewModels { - public class ReportMealPlanDinnerViewModel + public class ReportDinnerRoomViewModel { public string DinnerName { get; set; } = string.Empty; - public List> MealPlans { get; set; } = new(); + public List> Rooms { get; set; } = new(); } } diff --git a/Hotel/HotelContracts/ViewModels/ReportConferenceBindingRoomsViewModel.cs b/Hotel/HotelContracts/ViewModels/ReportDinnersViewModel.cs similarity index 69% rename from Hotel/HotelContracts/ViewModels/ReportConferenceBindingRoomsViewModel.cs rename to Hotel/HotelContracts/ViewModels/ReportDinnersViewModel.cs index 6e26c26..5fff054 100644 --- a/Hotel/HotelContracts/ViewModels/ReportConferenceBindingRoomsViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ReportDinnersViewModel.cs @@ -6,10 +6,12 @@ using System.Threading.Tasks; namespace HotelContracts.ViewModels { - public class ReportConferenceBindingRoomsViewModel + public class ReportDinnersViewModel { public int Id { get; set; } public string RoomName { get; set; } = string.Empty; + public string NameHall { get; set; } = string.Empty; + public string DinnerName { get; set; } = string.Empty; public double RoomPrice { get; set; } public string RoomFrame { get; set; } = string.Empty; diff --git a/Hotel/HotelDataBaseImplement/HotelDataBase.cs b/Hotel/HotelDataBaseImplement/HotelDataBase.cs index 6d7ccea..5f56ccf 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=HotelDataBaseFu;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/Hotel/HotelRestApi/Controllers/ReportController.cs b/Hotel/HotelRestApi/Controllers/ReportController.cs index 027d18e..f292734 100644 --- a/Hotel/HotelRestApi/Controllers/ReportController.cs +++ b/Hotel/HotelRestApi/Controllers/ReportController.cs @@ -11,10 +11,12 @@ namespace HotelRestApi.Controllers { private readonly ILogger _logger; private readonly IReportOrganiserLogic _reportOrganiserLogic; - public ReportController(ILogger logger, IReportOrganiserLogic reportOrganiserLogic) + private readonly IReportHeadwaiterLogic _reportHeadwaiterLogic; + public ReportController(ILogger logger, IReportOrganiserLogic reportOrganiserLogic, IReportHeadwaiterLogic reportHeadwaiterLogic) { _logger = logger; _reportOrganiserLogic = reportOrganiserLogic; + _reportHeadwaiterLogic = reportHeadwaiterLogic; } [HttpPost] @@ -43,5 +45,33 @@ namespace HotelRestApi.Controllers throw; } } + + + [HttpPost] + public void CreateHeadwaiterReportToWordFile(ReportHeadwaiterBindingModel model) + { + try + { + _reportHeadwaiterLogic.SaveDinnerRoomToWordFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void CreateHeadwaiterReportToExcelFile(ReportHeadwaiterBindingModel model) + { + try + { + _reportHeadwaiterLogic.SaveDinnerRoomToExcelFile(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } } } diff --git a/Hotel/HotelRestApi/Program.cs b/Hotel/HotelRestApi/Program.cs index 795e966..a67a1bc 100644 --- a/Hotel/HotelRestApi/Program.cs +++ b/Hotel/HotelRestApi/Program.cs @@ -24,11 +24,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.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); From d6b16a62f5dcb578c6aa6135b4e9d04d9397f791 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: Thu, 18 May 2023 18:19:52 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=B0?= =?UTF-8?q?=D1=87=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/HeadwaiterLogic.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs index 0733463..38403cf 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/HeadwaiterLogic.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading.Tasks; namespace HotelBusinessLogic.BusinessLogics @@ -140,6 +141,11 @@ namespace HotelBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет номера телефона метродотеля", nameof(model.HeadwaiterNumber)); } + if (model.HeadwaiterEmail.Length > _loginMaxLength || !Regex.IsMatch(model.HeadwaiterEmail, @"([a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+)")) + { + throw new Exception($"В качестве логина должна быть указана почта и иметь длинну не более {_loginMaxLength} символов"); + } + if (string.IsNullOrEmpty(model.HeadwaiterEmail)) { throw new ArgumentNullException("Нет почты метродотеля", nameof(model.HeadwaiterEmail)); @@ -150,21 +156,17 @@ namespace HotelBusinessLogic.BusinessLogics throw new ArgumentNullException("Нет пароля метродотеля", nameof(model.HeadwaiterPassword)); } - if (model.HeadwaiterPassword.Length < _passwordMinLength) + if (model.HeadwaiterPassword.Length > _passwordMaxLength || model.HeadwaiterPassword.Length < _passwordMinLength + || !Regex.IsMatch(model.HeadwaiterPassword, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$")) { - throw new ArgumentNullException("Пароль слишком короткий", nameof(model.HeadwaiterPassword)); - } - - if (model.HeadwaiterPassword.Length > _passwordMaxLength) - { - throw new ArgumentNullException("Пароль слишком длинный", nameof(model.HeadwaiterPassword)); + throw new Exception($"Пароль длиной от {_passwordMinLength} до {_passwordMaxLength} должен состоять из цифр, букв и небуквенных символов"); } _logger.LogInformation("Headwaiter. HeadwaiterFIO: {HeadwaiterFIO}. HeadwaiterLogin: {HeadwaiterLogin}. Id: {Id}", model.HeadwaiterFIO, model.HeadwaiterLogin, model.Id); var element = _headwaiterStorage.GetElement(new HeadwaiterSearchModel { - HeadwaiterLogin = model.HeadwaiterLogin + HeadwaiterEmail = model.HeadwaiterEmail }); if (element != null && element.Id != model.Id)