diff --git a/TravelAgency/TravelAgencyBusinessLogic/BusinessLogics/ReportLogic.cs b/TravelAgency/TravelAgencyBusinessLogic/BusinessLogics/ReportLogic.cs index 2d32b04..62e96e6 100644 --- a/TravelAgency/TravelAgencyBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/TravelAgency/TravelAgencyBusinessLogic/BusinessLogics/ReportLogic.cs @@ -117,7 +117,7 @@ namespace TravelAgencyBusinessLogic.BusinessLogics { _saveToWord.CreateDoc(new WordInfo { - FileName = model.FileName, + FileStream = model.FileStream, Title = "Список мест для посещения по выбранным турам.", TourPlaces = GetTourPlaces(model) }); @@ -127,7 +127,7 @@ namespace TravelAgencyBusinessLogic.BusinessLogics { _saveToExcel.CreateReport(new ExcelInfo { - FileName = model.FileName, + FileStream = model.FileStream, Title = "Список мест", TourPlaces = GetTourPlaces(model) }); diff --git a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index efc4430..9bfdd85 100644 --- a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -4,7 +4,7 @@ namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels { public class ExcelInfo { - public string FileName { get; set; } = string.Empty; + public Stream FileStream { get; set; } = new MemoryStream(); public string Title { get; set; } = string.Empty; diff --git a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index 8c04d59..5e89b4b 100644 --- a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -4,7 +4,7 @@ namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels { public class WordInfo { - public string FileName { get; set; } = string.Empty; + public Stream FileStream { get; set; } = new MemoryStream(); public string Title { get; set; } = string.Empty; diff --git a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index a2f1012..8a79db8 100644 --- a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -152,7 +152,7 @@ namespace TravelAgencyBusinessLogic.OfficePackage.Implements protected override void CreateExcel(ExcelInfo info) { - _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); + _spreadsheetDocument = SpreadsheetDocument.Create(info.FileStream, SpreadsheetDocumentType.Workbook); // Создаем книгу (в ней хранятся листы) var workbookpart = _spreadsheetDocument.AddWorkbookPart(); workbookpart.Workbook = new Workbook(); diff --git a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToWord.cs b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToWord.cs index fbb54f4..ecd4417 100644 --- a/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToWord.cs +++ b/TravelAgency/TravelAgencyBusinessLogic/OfficePackage/Implements/SaveToWord.cs @@ -83,7 +83,7 @@ namespace TravelAgencyBusinessLogic.OfficePackage.Implements protected override void CreateWord(WordInfo info) { - _wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document); + _wordDocument = WordprocessingDocument.Create(info.FileStream, WordprocessingDocumentType.Document); MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart(); mainPart.Document = new Document(); _docBody = mainPart.Document.AppendChild(new Body()); diff --git a/TravelAgency/TravelAgencyContracts/BindingModels/ReportBindingModel.cs b/TravelAgency/TravelAgencyContracts/BindingModels/ReportBindingModel.cs index 9fb526e..5f213da 100644 --- a/TravelAgency/TravelAgencyContracts/BindingModels/ReportBindingModel.cs +++ b/TravelAgency/TravelAgencyContracts/BindingModels/ReportBindingModel.cs @@ -2,7 +2,7 @@ { public class ReportBindingModel { - public string FileName { get; set; } = string.Empty; + public Stream FileStream { get; set; } = new MemoryStream(); public DateTime? DateFrom { get; set; } diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Implements/UserStorage.cs b/TravelAgency/TravelAgencyDatabaseImplement/Implements/UserStorage.cs index 3129fc9..c685d67 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Implements/UserStorage.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Implements/UserStorage.cs @@ -44,6 +44,12 @@ namespace TravelAgencyDatabaseImplement.Implements .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) ?.GetViewModel; } + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.PhoneNumber)) + { + return context.Users + .FirstOrDefault(x => x.Email.Equals(model.Email) || x.PhoneNumber.Equals(model.PhoneNumber)) + ?.GetViewModel; + } if (!string.IsNullOrEmpty(model.Email)) { return context.Users diff --git a/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs b/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs index 1de1854..8016b2d 100644 --- a/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs +++ b/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs @@ -26,17 +26,20 @@ namespace TravelAgencyWebApp.Controllers private readonly IGuideLogic _guideLogic; + private readonly IExcursionGroupLogic _excursionGroupLogic; + private readonly AbstractSaveToPdf _pdfLogic; private readonly AbstractMailWorker _mailLogic; - public HomeController(ILogger logger, IUserLogic userLogic, IReportLogic reportLogic, ITourLogic tourLogic, IGuideLogic guideLogic, AbstractSaveToPdf pdfLogic, AbstractMailWorker mailLogic) + public HomeController(ILogger logger, IUserLogic userLogic, IReportLogic reportLogic, ITourLogic tourLogic, IGuideLogic guideLogic, IExcursionGroupLogic excursionGroupLogic, AbstractSaveToPdf pdfLogic, AbstractMailWorker mailLogic) { _logger = logger; _userLogic = userLogic; _reportLogic = reportLogic; _tourLogic = tourLogic; _guideLogic = guideLogic; + _excursionGroupLogic = excursionGroupLogic; _pdfLogic = pdfLogic; _mailLogic = mailLogic; } @@ -246,20 +249,31 @@ namespace TravelAgencyWebApp.Controllers if (type.Equals("docx")) { - _reportLogic.SaveTourPlacesToWordFile(new ReportBindingModel + + using (var stream = new MemoryStream()) { - FileName = $@"C:\Users\User\Downloads\Список мест по турам{DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx", - UserId = LoggedinUser.User.Id, - Tours = tours - }); + _reportLogic.SaveTourPlacesToWordFile(new ReportBindingModel + { + FileStream = stream, + UserId = LoggedinUser.User.Id, + Tours = tours + }); + stream.Seek(0, SeekOrigin.Begin); + return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "wordfile.docx"); + } } else if (type.Equals("xlsx")) { - _reportLogic.SaveTourPlacesToExcelFile(new ReportBindingModel + using (var stream = new MemoryStream()) { - FileName = $@"C:\Users\User\Downloads\Список мест по турам{DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx", - UserId = LoggedinUser.User.Id, - Tours = tours - }); + _reportLogic.SaveTourPlacesToExcelFile(new ReportBindingModel + { + FileStream = stream, + UserId = LoggedinUser.User.Id, + Tours = tours + }); + stream.Seek(0, SeekOrigin.Begin); + return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "excelfile.xlsx"); + } } ViewBag.Tours = _tourLogic.ReadList(new TourSearchModel @@ -313,5 +327,69 @@ namespace TravelAgencyWebApp.Controllers byte[] report = stream.GetBuffer(); _mailLogic.MailSendAsync(new() { MailAddress = LoggedinUser.User.Email, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report }); } + + [HttpGet] + public IActionResult Diagrams() + { + if (LoggedinUser.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + ViewBag.RevenuePerMonth = Newtonsoft.Json.JsonConvert.SerializeObject(getRevenues()); + + ViewBag.TourPopularity = Newtonsoft.Json.JsonConvert.SerializeObject(getTourPopularity()); + + return View(); + } + + private Dictionary getRevenues() + { + var tours = _tourLogic.ReadList(new TourSearchModel { UserId = LoggedinUser.User.Id, DateFrom = new DateTime(DateTime.Today.Year, 1, 1), DateTo = DateTime.Today }); + var excursionGroups = _excursionGroupLogic.ReadList(new ExcursionGroupSearchModel { UserId = LoggedinUser.User.Id }); + + var revenuePerMonth = new Dictionary(); + + foreach (var tour in tours) + { + var month = tour.TourDate.Month; + if (!revenuePerMonth.ContainsKey(month)) + { + revenuePerMonth[month] = 0; + } + foreach (var eg in excursionGroups) + { + if (eg.ExcursionGroupTours.ContainsKey(tour.Id)) + { + revenuePerMonth[month] += tour.Price * eg.ParticipantsAmount; + } + } + } + return revenuePerMonth; + } + + private Dictionary getTourPopularity() + { + var tours = _tourLogic.ReadList(new TourSearchModel { UserId = LoggedinUser.User.Id }); + var excursionGroups = _excursionGroupLogic.ReadList(new ExcursionGroupSearchModel { UserId = LoggedinUser.User.Id }); + + var participantsPerTour = new Dictionary(); + + foreach (var tour in tours) + { + if (!participantsPerTour.ContainsKey(tour.TourName)) + { + participantsPerTour[tour.TourName] = 0; + } + foreach (var eg in excursionGroups) + { + if (eg.ExcursionGroupTours.ContainsKey(tour.Id)) + { + participantsPerTour[tour.TourName] += eg.ParticipantsAmount; + } + } + } + return participantsPerTour; + } } } diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/Diagrams.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/Diagrams.cshtml new file mode 100644 index 0000000..73c40ff --- /dev/null +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/Diagrams.cshtml @@ -0,0 +1,98 @@ +@{ + ViewData["Title"] = "Diagrams"; + var revenuePerMonthJson = ViewBag.RevenuePerMonth; + var tourPopularityJson = ViewBag.TourPopularity; +} + +
+

Диаграммы

+

Прибыль

+ +

Популярность туров

+ +
+ + + diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/Enter.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/Enter.cshtml index aebdfb2..f0bec66 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Home/Enter.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/Enter.cshtml @@ -6,16 +6,15 @@

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

-
-
Логин:
-
+
+
Логин:
+
-
-
Пароль:
-
+
+
Пароль:
+
-
-
-
+
+
\ No newline at end of file diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/Register.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/Register.cshtml index 622955d..e1bfa48 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Home/Register.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/Register.cshtml @@ -6,24 +6,23 @@

Регистрация

-
-
Логин:
-
+
+
Логин:
+
-
-
Пароль:
-
+
+
Пароль:
+
-
-
Номер телефона:
-
+
+
Номер телефона:
+
-
-
ФИО:
-
+
+
ФИО:
+
-
-
-
+
+
\ No newline at end of file diff --git a/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml index 66e16aa..a928f0f 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml @@ -21,9 +21,6 @@