diff --git a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs index d970a4e..128157c 100644 --- a/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs +++ b/University/UniversityBusinessLogic/BusinessLogics/ReportLogic.cs @@ -149,7 +149,7 @@ public class ReportLogic : IReportLogic return reportDisciplineViewModels; } - public List GetPlanOfStudyAndDisciplines() + public List GetPlanOfStudyAndDisciplines(int userId) { var planOfStudies = _planOfStudyStorage.GetFullList(); var reportPlanOfStudyViewModels = new List(); @@ -157,11 +157,12 @@ public class ReportLogic : IReportLogic foreach (var planOfStudy in planOfStudies) { // Получаем список дисциплин для текущего плана обучения - var disciplines = _planOfStudyStorage.GetDisciplineFromStudentsFromPlanOfStudys(new PlanOfStudySearchModel { Id = planOfStudy.Id }); + var disciplines = _planOfStudyStorage.GetDisciplineFromStudentsFromPlanOfStudys(new PlanOfStudySearchModel { Id = planOfStudy.Id, UserId = userId }); // Создаем ReportPlanOfStudyViewModel и добавляем его в список reportPlanOfStudyViewModels.Add(new ReportPlanOfStudyViewModel { + Id = planOfStudy.Id, PlanOfStudyName = planOfStudy.Profile, FormOfStudy = planOfStudy.FormOfStudy, Disciplines = disciplines.Select(d => d.Name).ToList() // Получаем только имена дисциплин @@ -211,10 +212,12 @@ public class ReportLogic : IReportLogic } public void SavePlanOfStudyToExcel(ReportBindingModel option) { - /*_saveToExcelWorker.CreateReport(new ExcelInfoWorker + _saveToExcelWorker.CreateReport(new ExcelInfoWorker { - - });*/ + FileName = option.FileName, + Title = "Список дисциплин и планов обучения", + PlanOfStudys = GetPlanOfStudyAndDisciplines(0) + }); } public void SavePlanOfStudyToWord(ReportBindingModel option) @@ -222,8 +225,8 @@ public class ReportLogic : IReportLogic _saveToWordWorker.CreateDoc(new WordInfoWorker { FileName = option.FileName, - Title = "Список планов обучения", - PlanOfStudys = GetPlanOfStudyAndDisciplines() + Title = "Список дисциплин и планов обучения", + PlanOfStudys = GetPlanOfStudyAndDisciplines(0) }); } diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs index e1edd8c..043f483 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelWorker.cs @@ -10,7 +10,7 @@ namespace UniversityBusinessLogic.OfficePackage { public abstract class AbstractSaveToExcelWorker { - /*public void CreateReport(ExcelInfoWorker info) + public void CreateReport(ExcelInfoWorker info) { CreateExcel(info); InsertCellInWorksheet(new ExcelCellParameters @@ -26,23 +26,23 @@ namespace UniversityBusinessLogic.OfficePackage CellToName = "C1" }); uint rowIndex = 2; - foreach (var wk in info.WorkComponents) + foreach (var ps in info.PlanOfStudys) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "A", RowIndex = rowIndex, - Text = wk.WorkName, + Text = ps.PlanOfStudyName, StyleInfo = ExcelStyleInfoType.Text - }); + }); ; rowIndex++; - foreach (var (Component, Count) in wk.Components) + foreach (var discipline in ps.Disciplines) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = Component, + Text = ps.FormOfStudy, StyleInfo = ExcelStyleInfoType.TextWithBroder }); @@ -50,30 +50,16 @@ namespace UniversityBusinessLogic.OfficePackage { ColumnName = "C", RowIndex = rowIndex, - Text = Count.ToString(), + Text = discipline, StyleInfo = ExcelStyleInfoType.TextWithBroder }); rowIndex++; } - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "A", - RowIndex = rowIndex, - Text = "Итого", - StyleInfo = ExcelStyleInfoType.Text - }); - InsertCellInWorksheet(new ExcelCellParameters - { - ColumnName = "C", - RowIndex = rowIndex, - Text = wk.TotalCount.ToString(), - StyleInfo = ExcelStyleInfoType.Text - }); rowIndex++; } SaveExcel(info); - }*/ + } protected abstract void CreateExcel(ExcelInfoWorker info); protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams); protected abstract void MergeCells(ExcelMergeParameters excelParams); diff --git a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs index 54d262b..e46e402 100644 --- a/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordWorker.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using DocumentFormat.OpenXml.Wordprocessing; namespace UniversityBusinessLogic.OfficePackage { @@ -28,14 +29,29 @@ namespace UniversityBusinessLogic.OfficePackage CreateParagraph(new WordParagraph { Texts = new List<(string, WordTextProperties)> { - (planOfStudys.PlanOfStudyName + " - ", new WordTextProperties { Size = "24", Bold = true, }), - (planOfStudys.FormOfStudy, new WordTextProperties { Size = "24", }) }, + (planOfStudys.PlanOfStudyName + " :", new WordTextProperties { Size = "24", Bold = true, }), + }, TextProperties = new WordTextProperties { Size = "24", JustificationType = WordJustificationType.Both } }); + foreach(var discipline in planOfStudys.Disciplines) + { + CreateParagraph(new WordParagraph + { + Texts = new List<(string, WordTextProperties)> { + (planOfStudys.FormOfStudy + " : ", new WordTextProperties { Size = "24", }), + (discipline, new WordTextProperties { Size = "24", }), + }, + TextProperties = new WordTextProperties + { + Size = "24", + JustificationType = WordJustificationType.Both + } + }); + } } SaveWord(info); } diff --git a/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfoWorker.cs b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfoWorker.cs index 804afb4..49a9464 100644 --- a/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfoWorker.cs +++ b/University/UniversityBusinessLogic/OfficePackage/HelperModels/ExcelInfoWorker.cs @@ -1,4 +1,6 @@ -namespace UniversityBusinessLogic.OfficePackage.HelperModels +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.OfficePackage.HelperModels { public class ExcelInfoWorker { @@ -12,7 +14,7 @@ get; set; } = new(); - + public List PlanOfStudys { get; set; } = new(); public List Headers { get; set; } = new(); } } diff --git a/University/UniversityClientAppWorker/APIClient.cs b/University/UniversityClientAppWorker/APIClient.cs index c05be52..57f9a5f 100644 --- a/University/UniversityClientAppWorker/APIClient.cs +++ b/University/UniversityClientAppWorker/APIClient.cs @@ -15,7 +15,7 @@ namespace PlumbingRepairClientApp public static void Connect(IConfiguration configuration) { _client.BaseAddress = new Uri(configuration["IPAddress"]); - _client.DefaultRequestHeaders.Accept.Clear(); + _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); } public static T? GetRequest(string requestUrl) @@ -48,6 +48,20 @@ namespace PlumbingRepairClientApp throw new Exception(result); } } + + public static async Task GetRequestAsync(string requestUrl) + { + var response = await _client.GetAsync(requestUrl); + var result = await response.Content.ReadAsStringAsync(); + if (response.IsSuccessStatusCode) + { + return JsonConvert.DeserializeObject(result); + } + else + { + throw new Exception(result); + } + } public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); diff --git a/University/UniversityClientAppWorker/Controllers/HomeController.cs b/University/UniversityClientAppWorker/Controllers/HomeController.cs index f3e6244..d1347dd 100644 --- a/University/UniversityClientAppWorker/Controllers/HomeController.cs +++ b/University/UniversityClientAppWorker/Controllers/HomeController.cs @@ -82,13 +82,14 @@ namespace UniversityClientAppWorker.Controllers { throw new Exception("id 0"); } + var planOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null); APIClient.PostRequest("api/planofstudys/updateplanofstudy", new PlanOfStudyBindingModel { Id = id, Profile = profile, FormOfStudy = formOfStudy, - PlanOfStudyTeachers = teacherIds.ToDictionary(id => id, id => (ITeacherModel)null) - }); + PlanOfStudyTeachers = planOfStudyTeachers + }); Response.Redirect("Index"); } [HttpGet] @@ -133,7 +134,8 @@ namespace UniversityClientAppWorker.Controllers } ViewBag.Students = APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}"); ViewBag.AttestationScore = Enum.GetValues(typeof(AttestationScore)).Cast(); - return View(APIClient.GetRequest>($"api/attestation/getattestations?userId={APIClient.User.Id}")); + var obj = APIClient.GetRequest>($"api/attestation/getattestations?userId={APIClient.User.Id}"); + return View(obj); } [HttpPost] public void CreateAttestation(string formOfEvaluation, int student, AttestationScore score) @@ -156,14 +158,15 @@ namespace UniversityClientAppWorker.Controllers Response.Redirect("Attestations"); } [HttpGet] - public IActionResult Students() + public async Task Students() { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } - ViewBag.PlanOfStudys = APIClient.GetRequest> + var planOfStudys = await APIClient.GetRequestPlanOfStudyAsync> ($"api/planofstudys/getplanofstudys?userId={APIClient.User.Id}"); + ViewBag.PlanOfStudys = planOfStudys; return View(APIClient.GetRequest>($"api/student/getstudents?userId={APIClient.User.Id}")); } [HttpPost] @@ -234,13 +237,47 @@ namespace UniversityClientAppWorker.Controllers return; } [HttpGet] - public IActionResult ReportPlanOfStudyViewModel() + public IActionResult ReportPlanOfStudys() { if (APIClient.User == null) { return Redirect("~/Home/Enter"); } - return View(APIClient.GetRequest>($"api/planofstudys/GetPlanOfStudyAndDisciplines")); + return View("ReportPlanOfStudys", APIClient.GetRequest>($"api/planofstudys/getplanofstudyanddisciplines?userId={APIClient.User.Id}")); + } + [HttpPost] + public void ReportPlanOfStudys(string type) + { + if (APIClient.User == null) + { + Redirect("~/Home/Enter"); + throw new Exception(" "); + } + + if (string.IsNullOrEmpty(type)) + { + throw new Exception(" "); + } + + if (type == "docx") + { + APIClient.PostRequest("api/planofstudys/loadreporttoword", new ReportBindingModel + { + FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\ .docx" + }); + Response.Redirect("Index"); + return; + } + + if (type == "xlsx") + { + APIClient.PostRequest("api/planofstudys/loadreporttoexcel", new ReportBindingModel + { + FileName = $"C:\\Users\\{Environment.UserName}\\Desktop\\ .xlsx" + }); + Response.Redirect("Index"); + return; + } } } } diff --git a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml index 0795e61..fb2d3c5 100644 --- a/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Attestations.cshtml @@ -77,6 +77,4 @@ } - - - + \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Home/Index.cshtml b/University/UniversityClientAppWorker/Views/Home/Index.cshtml index 0964dec..efd37c1 100644 --- a/University/UniversityClientAppWorker/Views/Home/Index.cshtml +++ b/University/UniversityClientAppWorker/Views/Home/Index.cshtml @@ -24,6 +24,7 @@
Преподаватели:
+
@foreach (var teacher in ViewBag.Teachers) {
@@ -33,6 +34,7 @@
} +
diff --git a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndDisciplines.cshtml b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndDisciplines.cshtml deleted file mode 100644 index 516892f..0000000 --- a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudyAndDisciplines.cshtml +++ /dev/null @@ -1,49 +0,0 @@ -@using UniversityContracts.ViewModels -@model List -@{ - ViewData["Title"] = "Отчёт по планам обучения"; -} - -
-

@ViewData["Title"]

-
- -
-
-
-
- -
-
-
- - - - - - - - - - - @foreach (var item in Model) - { - - - - - - } - -
План обученияФорма обученияДисциплины
- @Html.DisplayFor(modelItem => item.PlanOfStudyName) - - @Html.DisplayFor(modelItem => item.FormOfStudy) - - @foreach (var discipline in item.Disciplines) - { - @Html.DisplayFor(modelItem => discipline) - } -
- - diff --git a/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudys.cshtml b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudys.cshtml new file mode 100644 index 0000000..7b87175 --- /dev/null +++ b/University/UniversityClientAppWorker/Views/Home/ReportPlanOfStudys.cshtml @@ -0,0 +1,62 @@ +@using UniversityContracts.ViewModels +@model List +@{ + ViewData["Title"] = "Отчёт по планам обучения"; +} + +
+

@ViewData["Title"]

+
+ +
+
+
+
+ + + + + +
+ + +
+
+
+
+
+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
IdПлан обученияФорма обученияДисциплины
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.PlanOfStudyName) + + @Html.DisplayFor(modelItem => item.FormOfStudy) + + @foreach (var discipline in item.Disciplines) + { +
+ @Html.DisplayFor(modelItem => discipline) +
+ } +
+ \ No newline at end of file diff --git a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml index e957baf..e1cc0bb 100644 --- a/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml +++ b/University/UniversityClientAppWorker/Views/Shared/_Layout.cshtml @@ -39,7 +39,7 @@
diff --git a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs index 1c93372..6794c77 100644 --- a/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs +++ b/University/UniversityContracts/BusinessLogicsContracts/IReportLogic.cs @@ -18,7 +18,7 @@ namespace UniversityContracts.BusinessLogicContracts /// List GetTeachers(); List GetDisciplines(ReportBindingModel model); - List GetPlanOfStudyAndDisciplines(); + List GetPlanOfStudyAndDisciplines(int userId); List GetPlanOfStudyAndStudents(ReportDateRangeBindingModel model); void SaveTeachersToWord(ReportBindingModel option); diff --git a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs index 45f8c92..e22ef52 100644 --- a/University/UniversityContracts/SearchModels/AttestationSearchModel.cs +++ b/University/UniversityContracts/SearchModels/AttestationSearchModel.cs @@ -9,7 +9,7 @@ namespace UniversityContracts.SearchModels public class AttestationSearchModel { public int? Id { get; set; } - public int UserId { get; set; } - public int? StudentId { get; set; } + public int? UserId { get; set; } + public int StudentId { get; set; } } } diff --git a/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs b/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs index 15e04e0..7db3563 100644 --- a/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs +++ b/University/UniversityContracts/ViewModels/ReportPlanOfStudyViewModel.cs @@ -8,6 +8,7 @@ namespace UniversityContracts.ViewModels { public class ReportPlanOfStudyViewModel { + public int Id { get; set; } public string PlanOfStudyName { get; set; } = string.Empty; public string FormOfStudy { get; set; } = string.Empty; public List Disciplines { get; set; } = new(); diff --git a/University/UniversityDataModels/Models/IAttestationModel.cs b/University/UniversityDataModels/Models/IAttestationModel.cs index 9c2ea2e..084cdfb 100644 --- a/University/UniversityDataModels/Models/IAttestationModel.cs +++ b/University/UniversityDataModels/Models/IAttestationModel.cs @@ -5,6 +5,7 @@ namespace UniversityDataModels.Models public interface IAttestationModel : IId { int UserId { get; } + string StudentName { get; } string FormOfEvaluation { get; } AttestationScore Score { get; } int StudentId { get; } diff --git a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs index d3efe1e..32fd224 100644 --- a/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/AttestationStorage.cs @@ -30,11 +30,18 @@ namespace UniversityDatabaseImplement.Implements using var context = new UniversityDatabase(); - return context.Attestations - .Include(x => x.Student) - .Include(x => x.User) - .Select(x => x.GetViewModel) - .ToList(); + var query = context.Attestations + .Include(x => x.Student) + .ThenInclude(s => s.User) // Загружаем данные пользователя студента + .Include(x => x.User) + .AsQueryable(); + + if (model.UserId.HasValue) + { + query = query.Where(x => x.UserId == model.UserId.Value); + } + + return query.Select(x => x.GetViewModel).ToList(); } public AttestationViewModel? GetElement(AttestationSearchModel model) diff --git a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs index 49a9833..3285805 100644 --- a/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/PlanOfStudyStorage.cs @@ -115,14 +115,20 @@ namespace UniversityDatabaseImplement.Implements public PlanOfStudyViewModel? Update(PlanOfStudyBindingModel model) { using var context = new UniversityDatabase(); - var order = context.PlanOfStudys.FirstOrDefault(x => x.Id == model.Id); - if (order == null) + var planOfStudy = context.PlanOfStudys.FirstOrDefault(x => x.Id == model.Id); + if (planOfStudy == null) { return null; } - order.Update(model); + planOfStudy.Update(model); + planOfStudy.UpdateTeachers(context, model); context.SaveChanges(); - return context.PlanOfStudys.Include(x => x.User).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.PlanOfStudys + .Include(x => x.User) + .Include(x => x.Teachers) + .ThenInclude(x => x.Teacher) + .FirstOrDefault(x => x.Id == model.Id)? + .GetViewModel; } public PlanOfStudyViewModel? Delete(PlanOfStudyBindingModel model) { diff --git a/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.Designer.cs b/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.Designer.cs new file mode 100644 index 0000000..91a7b43 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.Designer.cs @@ -0,0 +1,471 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using UniversityDatabaseImplement; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + [DbContext(typeof(UniversityDatabase))] + [Migration("20240528222736_newFieldForAttestationViewModel")] + partial class newFieldForAttestationViewModel + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("FormOfEvaluation") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Score") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.Property("StudentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("StudentId"); + + b.HasIndex("UserId"); + + b.ToTable("Attestations"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.HasIndex("UserId"); + + b.ToTable("Disciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("date"); + + b.Property("FormOfStudy") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Profile") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("PlanOfStudys"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("TeacherId"); + + b.ToTable("PlanOfStudyTeachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Date") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("TeacherId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TeacherId"); + + b.HasIndex("UserId"); + + b.ToTable("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PhoneNumber") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("PlanOfStudyId") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("PlanOfStudyId"); + + b.HasIndex("UserId"); + + b.ToTable("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("DisciplineId") + .HasColumnType("int"); + + b.Property("StudentId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("DisciplineId"); + + b.HasIndex("StudentId"); + + b.ToTable("StudentDisciplines"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AcademicDegree") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Position") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Login") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Role") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Attestation", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("Attestations") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Attestations") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Student"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Disciplines") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Disciplines") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("PlanOfStudys") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudyTeacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Teachers") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("PlanOfStudyTeachers") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("Teacher"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Statement", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Teacher", "Teacher") + .WithMany("Statements") + .HasForeignKey("TeacherId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Statements") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Teacher"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.HasOne("UniversityDatabaseImplement.Models.PlanOfStudy", "PlanOfStudy") + .WithMany("Students") + .HasForeignKey("PlanOfStudyId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Students") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("PlanOfStudy"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.StudentDiscipline", b => + { + b.HasOne("UniversityDatabaseImplement.Models.Discipline", "Discipline") + .WithMany("Students") + .HasForeignKey("DisciplineId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("UniversityDatabaseImplement.Models.Student", "Student") + .WithMany("StudentDiscipline") + .HasForeignKey("StudentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Discipline"); + + b.Navigation("Student"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.HasOne("UniversityDatabaseImplement.Models.User", "User") + .WithMany("Teachers") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Discipline", b => + { + b.Navigation("Students"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.PlanOfStudy", b => + { + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Student", b => + { + b.Navigation("Attestations"); + + b.Navigation("StudentDiscipline"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.Teacher", b => + { + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudyTeachers"); + + b.Navigation("Statements"); + }); + + modelBuilder.Entity("UniversityDatabaseImplement.Models.User", b => + { + b.Navigation("Attestations"); + + b.Navigation("Disciplines"); + + b.Navigation("PlanOfStudys"); + + b.Navigation("Statements"); + + b.Navigation("Students"); + + b.Navigation("Teachers"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.cs b/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.cs new file mode 100644 index 0000000..1c3c060 --- /dev/null +++ b/University/UniversityDatabaseImplement/Migrations/20240528222736_newFieldForAttestationViewModel.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace UniversityDatabaseImplement.Migrations +{ + /// + public partial class newFieldForAttestationViewModel : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "StudentName", + table: "Attestations", + type: "nvarchar(max)", + nullable: false, + defaultValue: ""); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "StudentName", + table: "Attestations"); + } + } +} diff --git a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs index b595910..579bc8c 100644 --- a/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs +++ b/University/UniversityDatabaseImplement/Migrations/UniversityDatabaseModelSnapshot.cs @@ -40,6 +40,10 @@ namespace UniversityDatabaseImplement.Migrations b.Property("StudentId") .HasColumnType("int"); + b.Property("StudentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + b.Property("UserId") .HasColumnType("int"); diff --git a/University/UniversityDatabaseImplement/UniversityDatabase.cs b/University/UniversityDatabaseImplement/UniversityDatabase.cs index 07213d0..2b73bad 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=DESKTOP-N8BRIPR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + optionsBuilder.UseSqlServer(@"Data Source=DyCTaTOR\SQLEXPRESS;Initial Catalog=UniversityDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); } base.OnConfiguring(optionsBuilder); } diff --git a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs index b2ab712..a5e36ce 100644 --- a/University/UniversityRestApi/Controllers/PlanOfStudysController.cs +++ b/University/UniversityRestApi/Controllers/PlanOfStudysController.cs @@ -48,11 +48,11 @@ namespace UniversityRestApi.Controllers } } [HttpGet] - public List? GetPlanOfStudyAndDisciplines() + public List? GetPlanOfStudyAndDisciplines(int userId) { try { - return _reportLogic.GetPlanOfStudyAndDisciplines(); + return _reportLogic.GetPlanOfStudyAndDisciplines(userId); } catch (Exception ex) { @@ -61,6 +61,32 @@ namespace UniversityRestApi.Controllers } } [HttpPost] + public void LoadReportToWord(ReportBindingModel model) + { + try + { + _reportLogic.SavePlanOfStudyToWord(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void LoadReportToExcel(ReportBindingModel model) + { + try + { + _reportLogic.SavePlanOfStudyToExcel(model); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] public void CreatePlanOfStudy(PlanOfStudyBindingModel model) { try