diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index 128157c..aca66b1 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -31,11 +31,13 @@ public class ReportLogic : IReportLogic private readonly AbstractSaveToWordWorker _saveToWordWorker; //private readonly AbstractSaveToPdfWorker _saveToPdfWorker; + private readonly AbstractSaveToExcelWorker _saveToExcelStorekeeper; + //private readonly AbstractSaveToPdfWorker _saveToPdfWorker; private readonly AbstractSaveToWordStorekeeper _saveToWordStorekeeper; public ReportLogic (ITeacherStorage teacherStorage, IDisciplineStorage disciplineStorage, IStudentStorage studentStorage, IStatementStorage statementStorage, IPlanOfStudyStorage planOfStudyStorage, AbstractSaveToExcelWorker saveToExcelWorker, AbstractSaveToWordWorker saveToWordWorker - /* , AbstractSaveToPdfWorker saveToPdfWorker */) + /* , AbstractSaveToPdfWorker saveToPdfWorker */, AbstractSaveToWordStorekeeper saveToWordStorekeeper) { _teacherStorage = teacherStorage; _disciplineStorage = disciplineStorage; @@ -46,10 +48,15 @@ public class ReportLogic : IReportLogic _saveToExcelWorker = saveToExcelWorker; _saveToWordWorker = saveToWordWorker; // _saveToPdfWorker = saveToPdfWorker; + + _saveToWordStorekeeper = saveToWordStorekeeper ; } - public List GetTeachers() + public List GetTeachers(int userId) { - var teachers = _teacherStorage.GetFullList(); + var teachers = _teacherStorage.GetFilteredList(new TeacherSearchModel + { + UserId = userId + }); // Создаем список для результатов var result = new List(); @@ -235,8 +242,8 @@ public class ReportLogic : IReportLogic _saveToWordStorekeeper.CreateDoc(new WordInfoStorekeeper { FileName = option.FileName, - Title = "Список пакетов документов", - TeacherInfo = GetTeachers() + Title = "Список преподавателей", + TeacherInfo = GetTeachers(0) }); } diff --git a/University/UniversityClientApp/Controllers/HomeController.cs b/University/UniversityClientApp/Controllers/HomeController.cs index b830eeb..9928c54 100644 --- a/University/UniversityClientApp/Controllers/HomeController.cs +++ b/University/UniversityClientApp/Controllers/HomeController.cs @@ -174,12 +174,50 @@ namespace UniversityClientApp.Controllers }); Response.Redirect("Teachers"); } - - public IActionResult Report() { - return View(); + [HttpGet] + public IActionResult Report() { + if (APIStorekeeper.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View("Report", APIStorekeeper.GetRequest>($"api/teacher/getteachersreport?userId={APIStorekeeper.Client.Id}")); } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + [HttpPost] + public void Report(string type) + { + if (APIStorekeeper.Client == null) + { + Redirect("~/Home/Enter"); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception("Error, wrong type"); + } + + if (type == "docx") + { + APIStorekeeper.PostRequest("api/teacher/loadreporttoword", new ReportBindingModel + { + FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\TeachersAndStudents{Environment.TickCount}.docx" + }); + Response.Redirect("Report"); + return; + } + + if (type == "xlsx") + { + APIStorekeeper.PostRequest("api/teacher/loadreporttoexcel", new ReportBindingModel + { + FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\TeachersAndStudents{Environment.TickCount}.xlsx" + }); + Response.Redirect("Report"); + return; + } + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); diff --git a/University/UniversityClientApp/Views/Home/Report.cshtml b/University/UniversityClientApp/Views/Home/Report.cshtml index 45d00c0..be78992 100644 --- a/University/UniversityClientApp/Views/Home/Report.cshtml +++ b/University/UniversityClientApp/Views/Home/Report.cshtml @@ -1,5 +1,7 @@ -@{ - ViewData["Title"] = "Student List by Teacher"; +@using UniversityContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Report by teachers and students"; }
@@ -8,33 +10,59 @@
-
Teachers:
-
- +
+
+ + + + + +
+ + +
+
+
-
-
File Format:
-
- -
-
-
-
File Name:
-
- -
-
-
-
File Location:
-
- -
-
-
-
-
- -
-
- + + + + + + + + + + + @foreach (var item in Model) + { + + + + + @foreach (var student in item.Students) + { + + + } + + } + +
IdTeacher nameStudentStudent
+ @Html.DisplayFor(modelItem => item.TeacherId) + + @Html.DisplayFor(modelItem => item.TeacherName) + + @foreach (var st in item.Students) + { +
+ @Html.DisplayFor(modelItem => st) +
+ } +
+ @student.Name + + @student.PhoneNumber +
+ \ No newline at end of file diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 6794c77..66dc224 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -16,7 +16,7 @@ namespace UniversityContracts.BusinessLogicContracts /// /// /// - List GetTeachers(); + List GetTeachers(int userId); List GetDisciplines(ReportBindingModel model); List GetPlanOfStudyAndDisciplines(int userId); List GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model); diff --git a/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs index 270bdcc..04dc959 100644 --- a/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs +++ b/University/UniversityContracts/ViewModels/ReportTeacherViewModel.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace University.ViewModels +namespace UniversityContracts.ViewModels { public class ReportTeacherViewModel { diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 2b73bad..07213d0 100644 --- a/University/UniversityDatabaseImplement/UniversityDatabase.cs +++ b/University/UniversityDatabaseImplement/UniversityDatabase.cs @@ -11,7 +11,7 @@ namespace UniversityDatabaseImplement if (optionsBuilder.IsConfigured == false) { //Возможно понадобится писать вместо (localdb) название пк, вот пк Егора: DESKTOP-N8BRIPR; other-name: LAPTOP-DYCTATOR; other-name: DyCTaTOR - optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/TeacherController.cs b/University/UniversityRestApi/Controllers/TeacherController.cs index 3fe232c..90beb0f 100644 --- a/University/UniversityRestApi/Controllers/TeacherController.cs +++ b/University/UniversityRestApi/Controllers/TeacherController.cs @@ -88,11 +88,11 @@ namespace UniversityRestApi.Controllers } [HttpGet] - public List? GetDisciplinesReport() + public List? GetTeachersReport(int userId) { try { - return _reportLogic.GetTeachers(); + return _reportLogic.GetTeachers(userId); } catch (Exception ex) { @@ -100,5 +100,32 @@ namespace UniversityRestApi.Controllers throw; } } + + [HttpPost] + public void LoadReportToWord(ReportBindingModel model) + { + try + { + _reportLogic.SaveTeachersToWord(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void LoadReportToExcel(ReportBindingModel model) + { + try + { + _reportLogic.SaveTeachersToExcel(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } } } diff --git a/University/UniversityRestApi/Program.cs b/University/UniversityRestApi/Program.cs index 5edf8c1..7e4ee7c 100644 --- a/University/UniversityRestApi/Program.cs +++ b/University/UniversityRestApi/Program.cs @@ -26,6 +26,9 @@ 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();