diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/CleaningLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/CleaningLogic.cs index d2515c8..c587f24 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/CleaningLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/CleaningLogic.cs @@ -50,7 +50,7 @@ public class CleaningLogic : ICleaningLogic public bool Update(CleaningBindingModel model) { - CheckModel(model); + CheckModel(model, false); if (_cleaningStorage.Update(model) != null) return true; _logger.LogWarning("Update operation failed"); return false; diff --git a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogic.cs index cd97b78..d12ee11 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogics/ReportLogic.cs @@ -40,9 +40,10 @@ public class ReportLogic : IReportLogic _saveToPdf = saveToPdf; } - public List GetListCleaning() + public List GetListCleaning(List reservationsId) { - var reservations = _reservationStorage.GetFullList(); + var reservations = _reservationStorage.GetFullList() + .Where(x => reservationsId.Contains(x.Id)); List list = new(); foreach (var reservation in reservations) @@ -127,7 +128,7 @@ public class ReportLogic : IReportLogic { FileName = model.FileName, Title = "Комплекты для уборки", - ListCleaningModels = GetListCleaning() + ListCleaningModels = GetListCleaning(model.Reservations) }); } @@ -137,7 +138,7 @@ public class ReportLogic : IReportLogic { FileName = model.FileName, Title = "Комплекты для уборки", - ListCleaningModels = GetListCleaning() + ListCleaningModels = GetListCleaning(model.Reservations) }); } diff --git a/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs b/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs index 212cdd3..9d703cc 100644 --- a/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs +++ b/Hotel/HotelContracts/BindingModels/ReportBindingModel.cs @@ -5,4 +5,5 @@ public class ReportBindingModel public string FileName { get; set; } = string.Empty; public DateTime? From { get; set; } public DateTime? To { get; set; } + public List? Reservations { get; set; } } \ No newline at end of file diff --git a/Hotel/HotelContracts/BusinessLogicsContracts/IReportLogic.cs b/Hotel/HotelContracts/BusinessLogicsContracts/IReportLogic.cs index ea4937f..2e12d29 100644 --- a/Hotel/HotelContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/Hotel/HotelContracts/BusinessLogicsContracts/IReportLogic.cs @@ -5,7 +5,7 @@ namespace HotelContracts.BusinessLogicsContracts; public interface IReportLogic { - List GetListCleaning(); + List GetListCleaning(List reservationsId); List GetGuests(ReportBindingModel model); void SaveListCleaningToWordFile(ReportBindingModel model); void SaveListCleaningToExcelFile(ReportBindingModel model); diff --git a/Hotel/HotelContracts/ViewModels/ReportGuestViewModel.cs b/Hotel/HotelContracts/ViewModels/ReportGuestViewModel.cs index 7434bfd..2068482 100644 --- a/Hotel/HotelContracts/ViewModels/ReportGuestViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/ReportGuestViewModel.cs @@ -9,4 +9,9 @@ public class ReportGuestViewModel public DateTime StartDate { get; set; } public DateTime EndDate { get; set; } public Dictionary CleaningInstruments; + + public string GetCleaningInstruments() + { + return string.Join(", ", CleaningInstruments.Values.Select(x => x.Type)); + } } \ No newline at end of file diff --git a/Hotel/HotelView/Api.cs b/Hotel/HotelView/Api.cs index 4894d25..6c663ea 100644 --- a/Hotel/HotelView/Api.cs +++ b/Hotel/HotelView/Api.cs @@ -3,7 +3,6 @@ using HotelBusinessLogic.MailWorker; using HotelContracts.BindingModels; using HotelContracts.BusinessLogicsContracts; using HotelContracts.SearchModels; -using HotelContracts.StoragesContracts; using HotelContracts.ViewModels; namespace HotelView; @@ -74,33 +73,34 @@ public class Api Maitre.Fio.Replace(" ", "_") + "_" + DateTime.Now.ToShortDateString() + "." + ext; - public void SendReportWord() + public string SendReportWord(List reservations) { var fileName = GenerateFileName(); _reportLogic.SaveListCleaningToWordFile(new ReportBindingModel { - FileName = fileName - }); - _mailWorker.MailSendAsync(new MailSendInfoBindingModel - { - MailAddress = Maitre.Login, - Subject = "Список составляющих комплектов для подготовки номеров", - AttachmentMail = new Attachment(fileName) + FileName = fileName, + Reservations = reservations }); + return fileName; } - public void SendReportExcel() + public string SendReportExcel(List reservations) { var filename = GenerateFileName("xlsx"); _reportLogic.SaveListCleaningToExcelFile(new ReportBindingModel { - FileName = filename + FileName = filename, + Reservations = reservations }); - _mailWorker.MailSendAsync(new MailSendInfoBindingModel + return filename; + } + + public List GetPreRenderReport(DateTime from, DateTime to) + { + return _reportLogic.GetGuests(new ReportBindingModel { - MailAddress = Maitre.Login, - Subject = "Список составляющих комплектов для подготовки номеров", - AttachmentMail = new Attachment(filename) + From = from, + To = to }); } diff --git a/Hotel/HotelView/Controllers/HomeController.cs b/Hotel/HotelView/Controllers/HomeController.cs index 2e2c85d..0c694ed 100644 --- a/Hotel/HotelView/Controllers/HomeController.cs +++ b/Hotel/HotelView/Controllers/HomeController.cs @@ -4,10 +4,8 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using HotelContracts.BindingModels; using HotelContracts.SearchModels; -using HotelContracts.ViewModels; using HotelDataModels.Models; using HotelView.Utils; -using Microsoft.EntityFrameworkCore.Metadata.Internal; namespace HotelView.Controllers; @@ -44,11 +42,11 @@ public class HomeController : Controller ViewBag.GuestLiving = Math.Round((double)ViewBag.GuestLivingCount / guests.Count * 100); ViewBag.MaxDay = reservations.Max(x => x.EndDate - x.StartDate).Days; - ViewBag.AverageDay = reservations.Select(x => x.EndDate - x.StartDate) - .Select(x => x.Days).Average(); + ViewBag.AverageDay = Math.Round(reservations.Select(x => x.EndDate - x.StartDate) + .Select(x => x.Days).Average()); ViewBag.MaxCost = reservations.Max(x => x.GetCost()); - ViewBag.AverageCost = reservations.Select(x => x.GetCost()).Average(); + ViewBag.AverageCost = Math.Round(reservations.Select(x => x.GetCost()).Average()); ViewBag.LastReservation = reservations.Last(); ViewBag.LastReservationRooms = string.Join(",", reservations.Last().ReservationsRooms @@ -124,6 +122,34 @@ public class HomeController : Controller return View(_api.GetRoomLogic.ReadList(null)); } + [HttpGet] + public IActionResult EditRoom(int id) + { + ViewBag.Maitre = _api.Maitre; + var item = _api.GetRoomLogic.ReadElement(new RoomSearchModel + { + Id = id + }); + return View(item); + } + + [HttpPost] + public void EditRoom(int id, string type, double cost) + { + if (string.IsNullOrEmpty(type) || cost == 0) + { + throw new Exception("Invalid arguments"); + } + + _api.GetRoomLogic.Update(new RoomBindingModel + { + Id = id, + Cost = cost, + Type = type + }); + Response.Redirect("Rooms"); + } + [HttpPost] public void CreateRoom(string type, double cost) { @@ -162,6 +188,38 @@ public class HomeController : Controller }); Response.Redirect("Guests"); } + + [HttpGet] + public IActionResult EditGuest(int id) + { + ViewBag.Maitre = _api.Maitre; + var guest = _api.GetGuestLogic.ReadElement(new GuestSearchModel + { + Id = id + }); + return View(guest); + } + + [HttpPost] + public void EditGuest(int id, string name, string secondName, string lastName) + { + if (string.IsNullOrEmpty(name) || + string.IsNullOrEmpty(secondName) || + string.IsNullOrEmpty(lastName) || + id == 0) + { + throw new Exception("Invalid arguments"); + } + + _api.GetGuestLogic.Update(new GuestBindingModel + { + Id = id, + Name = name.FirstCharToUpper(), + SecondName = secondName.FirstCharToUpper(), + LastName = lastName.FirstCharToUpper() + }); + Response.Redirect("Guests"); + } [SuppressMessage("ReSharper.DPA", "DPA0000: DPA issues")] public IActionResult Reservations() @@ -212,12 +270,75 @@ public class HomeController : Controller Response.Redirect("Reservations"); } + [HttpGet] + public IActionResult EditReservation(int id) + { + ViewBag.Maitre = _api.Maitre; + var item = _api.GetReservationLogic.ReadElement(new ReservationSearchModel() + { + Id = id + }); + ViewBag.Guests = _api.GetGuestLogic.ReadList(null); + ViewBag.RoomsModel = item.ReservationsRooms.Select(x => x.Key).ToList(); + ViewBag.Rooms = _api.GetRoomLogic.ReadList(new RoomSearchModel + { + IsReserved = false + }); + ViewBag.StartDate = item.StartDate.ToString("MM/dd/yyyy").Replace(".", "/"); + ViewBag.EndDate = item.EndDate.ToString("MM/dd/yyyy").Replace(".", "/"); + + return View(item); + } + + [HttpPost] + public void EditReservation(int id, + DateTime dateStart, + DateTime dateEnd) + { + if (dateEnd < dateStart || dateStart < DateTime.Now) + { + throw new Exception("Invalid arguments"); + } + _api.GetReservationLogic.Update(new ReservationBindingModel + { + Id = id, + MaitreId = _api.Maitre.Id, + StartDate = dateStart, + EndDate = dateEnd + }); + Response.Redirect("Reservations"); + } + public IActionResult CleaningInstruments() { ViewBag.Maitre = _api.Maitre; return View(_api.GetCleaningInstrumentsLogic.ReadList(null)); } + [HttpGet] + public IActionResult EditCleaningInstrument(int id) + { + ViewBag.Maitre = _api.Maitre; + var item = _api.GetCleaningInstrumentsLogic.ReadElement(new() + { + Id = id + }); + return View(item); + } + + [HttpPost] + public void EditCleaningInstrument(int id, string type) + { + if (string.IsNullOrEmpty(type)) + throw new ArgumentException("Type must be not null"); + _api.GetCleaningInstrumentsLogic.Update(new CleaningInstrumentsBindingModel + { + Id = id, + Type = type + }); + Response.Redirect("CleaningInstruments"); + } + [HttpPost] public void CreateCleaningInstrument(string type) { @@ -256,6 +377,24 @@ public class HomeController : Controller }); Response.Redirect("Cleaning"); } + + [HttpGet] + public IActionResult EditCleaning(int id) + { + ViewBag.Maitre = _api.Maitre; + return View(); + } + + [HttpPost] + public void EditCleaning(int id, DateTime dateTime) + { + _api.GetCleaningLogic.Update(new CleaningBindingModel + { + Id = id, + Date = dateTime + }); + Response.Redirect("Cleaning"); + } [HttpGet] public void DeleteReservation(int id) @@ -315,28 +454,40 @@ public class HomeController : Controller public IActionResult Report() { ViewBag.Maitre = _api.Maitre; + ViewBag.Reservations = _api.GetReservationLogic.ReadList(null); return View(); } - [HttpGet] - public void CreateWordReport() + [HttpPost] + public IActionResult CreateReport(List reservations, string options) { - _api.SendReportWord(); - Response.Redirect("Report"); - } - - [HttpGet] - public void CreateExcelReport() - { - _api.SendReportExcel(); - Response.Redirect("Report"); + switch (options) + { + case "word": + { + var file = _api.SendReportWord(reservations); + return new PhysicalFileResult(file, + "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + } + case "excel": + { + var file = _api.SendReportExcel(reservations); + return new PhysicalFileResult(file, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + } + default: + return null; + } } [HttpPost] - public void CreatePdfReport(DateTime from, DateTime to) + public IActionResult Report(DateTime from, DateTime to) { _api.SendReportPdf(from, to); - Response.Redirect("Report"); + ViewBag.Maitre = _api.Maitre; + ViewBag.Reservations = _api.GetReservationLogic.ReadList(null); + ViewBag.PreRender = _api.GetPreRenderReport(from, to); + return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] diff --git a/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.docx b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.docx new file mode 100644 index 0000000..7643efe Binary files /dev/null and b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.docx differ diff --git a/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.pdf b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.pdf new file mode 100644 index 0000000..853fdeb Binary files /dev/null and b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.pdf differ diff --git a/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.xlsx b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.xlsx new file mode 100644 index 0000000..8d4f449 Binary files /dev/null and b/Hotel/HotelView/TempDirectoryForReports/Андрей_Базунов_Игоревич_19.05.2023.xlsx differ diff --git a/Hotel/HotelView/Views/Home/Cleaning.cshtml b/Hotel/HotelView/Views/Home/Cleaning.cshtml index 0d36e44..3369eb3 100644 --- a/Hotel/HotelView/Views/Home/Cleaning.cshtml +++ b/Hotel/HotelView/Views/Home/Cleaning.cshtml @@ -39,6 +39,11 @@ class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored"> Удалить + + Изменить + diff --git a/Hotel/HotelView/Views/Home/CleaningInstruments.cshtml b/Hotel/HotelView/Views/Home/CleaningInstruments.cshtml index 1463681..1047062 100644 --- a/Hotel/HotelView/Views/Home/CleaningInstruments.cshtml +++ b/Hotel/HotelView/Views/Home/CleaningInstruments.cshtml @@ -22,6 +22,11 @@ class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored"> Удалить + + Изменить + } diff --git a/Hotel/HotelView/Views/Home/EditCleaning.cshtml b/Hotel/HotelView/Views/Home/EditCleaning.cshtml new file mode 100644 index 0000000..433a73f --- /dev/null +++ b/Hotel/HotelView/Views/Home/EditCleaning.cshtml @@ -0,0 +1,22 @@ +@{ + ViewData["Title"] = "Уборки"; + Layout = "_Layout"; +} + +
+ +

Изменение уборки

+
+
+ Дата уборки +
+ +
+
+
+ + Отмена +
+
+
+
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/EditCleaningInstrument.cshtml b/Hotel/HotelView/Views/Home/EditCleaningInstrument.cshtml new file mode 100644 index 0000000..255276e --- /dev/null +++ b/Hotel/HotelView/Views/Home/EditCleaningInstrument.cshtml @@ -0,0 +1,23 @@ +@model HotelContracts.ViewModels.CleaningInstrumentsViewModel +@{ + ViewData["Title"] = "Инструменты для уборки"; + Layout = "_Layout"; +} + +
+ +

Изменение иструмента

+
+
+
+ + +
+
+
+ + Отмена +
+
+
+
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/EditGuest.cshtml b/Hotel/HotelView/Views/Home/EditGuest.cshtml new file mode 100644 index 0000000..34f60fa --- /dev/null +++ b/Hotel/HotelView/Views/Home/EditGuest.cshtml @@ -0,0 +1,31 @@ +@model HotelContracts.ViewModels.GuestViewModel +@{ + ViewData["Title"] = "Гости"; + Layout = "_Layout"; +} + +
+ +

Изменить постояльца

+
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ + Отмена +
+
+
+
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/EditReservation.cshtml b/Hotel/HotelView/Views/Home/EditReservation.cshtml new file mode 100644 index 0000000..171292f --- /dev/null +++ b/Hotel/HotelView/Views/Home/EditReservation.cshtml @@ -0,0 +1,27 @@ +@model HotelContracts.ViewModels.ReservationViewModel +@{ + ViewData["Title"] = "Бронирования"; + Layout = "_Layout"; +} + +
+ +

Изменить бронирование

+
+
+ Дата заселения +
+ +
+ Дата выселения +
+ +
+
+
+ + Отмена +
+
+
+
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/EditRoom.cshtml b/Hotel/HotelView/Views/Home/EditRoom.cshtml new file mode 100644 index 0000000..2c42073 --- /dev/null +++ b/Hotel/HotelView/Views/Home/EditRoom.cshtml @@ -0,0 +1,35 @@ +@model HotelContracts.ViewModels.RoomViewModel + +@{ + ViewData["Title"] = "Home Page"; + Layout = "_Layout"; +} + +
+ +

Изменение номера

+
+
+
+ + +
+
+ + +
+
+
+ + Отмена +
+
+
+
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/Guests.cshtml b/Hotel/HotelView/Views/Home/Guests.cshtml index 24d04de..4dcb276 100644 --- a/Hotel/HotelView/Views/Home/Guests.cshtml +++ b/Hotel/HotelView/Views/Home/Guests.cshtml @@ -22,6 +22,11 @@ class="mdl-button mdl-js-button mdl-button--raised mdl-button--colored"> Удалить + + Изменить + } diff --git a/Hotel/HotelView/Views/Home/Index.cshtml b/Hotel/HotelView/Views/Home/Index.cshtml index 226e3b7..5988064 100644 --- a/Hotel/HotelView/Views/Home/Index.cshtml +++ b/Hotel/HotelView/Views/Home/Index.cshtml @@ -13,7 +13,7 @@
Постояльцев проживает (@ViewBag.GuestLivingCount из @ViewBag.GuestCount)
-
+
0
@ViewBag.AverageDay
@ViewBag.MaxDay
diff --git a/Hotel/HotelView/Views/Home/Report.cshtml b/Hotel/HotelView/Views/Home/Report.cshtml index c2beeef..2f1d814 100644 --- a/Hotel/HotelView/Views/Home/Report.cshtml +++ b/Hotel/HotelView/Views/Home/Report.cshtml @@ -1,49 +1,101 @@ -@model List +@using HotelContracts.ViewModels +@model List @{ ViewData["Title"] = "Отчеты"; Layout = "_Layout"; }
-
-
Создать отчет в формате (.docx) и отправить его на почту @ViewBag.Maitre.Login
- - Отправить - -
-
Создать отчет в формате (.xlsx) и отправить его на почту @ViewBag.Maitre.Login
- - Отправить - +
Создать отчет в формате (.xlsx|.docx) и скачать его @ViewBag.Maitre.Login
+
+
+ Бронирования +
+ +
+ + + +
+
Создать отчет в формате (.pdf) и отправить его на почту @ViewBag.Maitre.Login
-
- Начальная дата + + Начальная дата
- Конечная дата + Конечная дата
+ @{ + if (ViewBag.PreRender != null) + { +
+
Данный отчет отправлен на почту @ViewBag.Maitre.Login
+ + + + + + + + + + + + + @{ + @foreach (var item in ViewBag.PreRender) + { + + + + + + + + + } + } + +
ФамилияИмяОтчествоЗаселениеВыселениеНабор
@item.SecondName@item.Name@item.LastName@item.StartDate.ToShortDateString()@item.EndDate.ToShortDateString() + @item.GetCleaningInstruments() +
+
+ } + }
\ No newline at end of file diff --git a/Hotel/HotelView/Views/Home/Reservations.cshtml b/Hotel/HotelView/Views/Home/Reservations.cshtml index 3c8196e..39f6405 100644 --- a/Hotel/HotelView/Views/Home/Reservations.cshtml +++ b/Hotel/HotelView/Views/Home/Reservations.cshtml @@ -40,7 +40,12 @@ - Удалить + Удалить + + + Изменить
diff --git a/Hotel/HotelView/Views/Home/Rooms.cshtml b/Hotel/HotelView/Views/Home/Rooms.cshtml index 3ca136c..bb682da 100644 --- a/Hotel/HotelView/Views/Home/Rooms.cshtml +++ b/Hotel/HotelView/Views/Home/Rooms.cshtml @@ -1,4 +1,5 @@ @model List + @{ ViewData["Title"] = "Home Page"; Layout = "_Layout"; @@ -46,14 +47,20 @@ Забронирована } } - - @item.GetTypeRoom() - - Удалить - + + + @item.GetTypeRoom() + + Удалить + + + Изменить + } diff --git a/Hotel/HotelView/wwwroot/css/site.css b/Hotel/HotelView/wwwroot/css/site.css index 2d850cb..961a249 100644 --- a/Hotel/HotelView/wwwroot/css/site.css +++ b/Hotel/HotelView/wwwroot/css/site.css @@ -249,8 +249,8 @@ body { dialog { position: absolute; - top: 30%; - left: 20px; + top: 50px; + left: 40%; } .mdl-list__item-avatar {