From f855a03cba2805146c9802fdf8a0fbeee1755a7b Mon Sep 17 00:00:00 2001 From: ker73rus Date: Sat, 8 Apr 2023 22:25:55 +0400 Subject: [PATCH 1/2] need report --- .../ViewModels/ReportDiscipline.cs | 13 +++ .../ViewModels/ReportStreamEducationGroup.cs | 13 +++ UniversityDataBaseImplemet/Database.cs | 7 ++ .../Implements/DisciplineStorage.cs | 106 +++++++++++++++++ .../Implements/EducationGroupStorage.cs | 105 +++++++++++++++++ .../Implements/StreamStorage.cs | 107 ++++++++++++++++++ .../Implements/UserStorage.cs | 7 -- 7 files changed, 351 insertions(+), 7 deletions(-) create mode 100644 UniversityContracts/ViewModels/ReportDiscipline.cs create mode 100644 UniversityContracts/ViewModels/ReportStreamEducationGroup.cs create mode 100644 UniversityDataBaseImplemet/Implements/DisciplineStorage.cs create mode 100644 UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs create mode 100644 UniversityDataBaseImplemet/Implements/StreamStorage.cs diff --git a/UniversityContracts/ViewModels/ReportDiscipline.cs b/UniversityContracts/ViewModels/ReportDiscipline.cs new file mode 100644 index 0000000..45a25c8 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportDiscipline.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportDiscipline + { + //выбираем дисциплину, выбираем период, отображаются студенты зачисленные через приказ в этот период со статусами обучения + } +} diff --git a/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs b/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs new file mode 100644 index 0000000..9373391 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportStreamEducationGroup + { + // при выборе потока показывается список студентов на потоке и их статус обучения + } +} diff --git a/UniversityDataBaseImplemet/Database.cs b/UniversityDataBaseImplemet/Database.cs index af816dd..3ec12e1 100644 --- a/UniversityDataBaseImplemet/Database.cs +++ b/UniversityDataBaseImplemet/Database.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityDataBaseImplemet.Models; +using Stream = UniversityDataBaseImplemet.Models.Stream; namespace UniversityDataBaseImplemet { @@ -20,9 +21,15 @@ namespace UniversityDataBaseImplemet } public virtual DbSet User { get; set; } public virtual DbSet Documents { get; set; } + public virtual DbSet Discipline { get; set; } public virtual DbSet EducationStatuses { get; set; } + public virtual DbSet EducationGroups { get; set; } + public virtual DbSet EducationGroupsDocuments { get; set; } + public virtual DbSet EducationGroupsStreams { get; set; } + public virtual DbSet Streams { get; set; } public virtual DbSet Students { get; set; } public virtual DbSet StudentDocuments { get; set; } + public virtual DbSet StudentStreams { get; set; } public virtual DbSet Roles { get; set; } } } diff --git a/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs b/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs new file mode 100644 index 0000000..0040889 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/DisciplineStorage.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class DisciplineStorage:IDisciplineStorage + { + public DisciplineViewModel? GetElement(DisciplineSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Discipline + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(DisciplineSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Discipline + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Discipline + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Discipline + .Select(record => record.GetViewModel) + .ToList(); + } + public DisciplineViewModel? Insert(DisciplineBindingModel model) + { + var newDiscipline = Discipline.Create(model); + if (newDiscipline == null) + { + return null; + } + using var context = new Database(); + context.Discipline.Add(newDiscipline); + context.SaveChanges(); + return newDiscipline.GetViewModel; + } + public DisciplineViewModel? Update(DisciplineBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var stream = context.Discipline + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + stream.Update(model); + context.SaveChanges(); + transaction.Commit(); + return stream.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public DisciplineViewModel? Delete(DisciplineBindingModel model) + { + using var context = new Database(); + var stream = context.Discipline + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + context.Discipline.Remove(stream); + context.SaveChanges(); + return stream.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs b/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs new file mode 100644 index 0000000..644cb19 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/EducationGroupStorage.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; +using UniversityDataBaseImplemet.Models; + +namespace UniversityDataBaseImplemet.Implements +{ + public class EducationGroupStorage + { + public EducationGroupViewModel? GetElement(EducationGroupSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.EducationGroups + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(EducationGroupSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.EducationGroups + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.EducationGroups + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.EducationGroups + .Select(record => record.GetViewModel) + .ToList(); + } + public EducationGroupViewModel? Insert(EducationGroupBindingModel model) + { + var newEducationGroup = EducationGroup.Create(model); + if (newEducationGroup == null) + { + return null; + } + using var context = new Database(); + context.EducationGroups.Add(newEducationGroup); + context.SaveChanges(); + return newEducationGroup.GetViewModel; + } + public EducationGroupViewModel? Update(EducationGroupBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var educationgroup = context.EducationGroups + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationgroup == null) + { + return null; + } + educationgroup.Update(model); + context.SaveChanges(); + transaction.Commit(); + return educationgroup.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public EducationGroupViewModel? Delete(EducationGroupBindingModel model) + { + using var context = new Database(); + var educationgroup = context.EducationGroups + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (educationgroup == null) + { + return null; + } + context.EducationGroups.Remove(educationgroup); + context.SaveChanges(); + return educationgroup.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/StreamStorage.cs b/UniversityDataBaseImplemet/Implements/StreamStorage.cs new file mode 100644 index 0000000..cdcc7d1 --- /dev/null +++ b/UniversityDataBaseImplemet/Implements/StreamStorage.cs @@ -0,0 +1,107 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; +using Stream = UniversityDataBaseImplemet.Models.Stream; + +namespace UniversityDataBaseImplemet.Implements +{ + public class StreamStorage:IStreamStorage + { + public StreamViewModel? GetElement(StreamSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using var context = new Database(); + return context.Streams + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; + } + public List GetFilteredList(StreamSearchModel model) + { + using var context = new Database(); + if (model.Id.HasValue) + { + return context.Streams + .Where(record => record.Id.Equals(model.Id)) + .Select(record => record.GetViewModel) + .ToList(); + } + else if (model.UserId.HasValue) + { + return context.Streams + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) + .ToList(); + } + else + { + return new(); + } + } + public List GetFullList() + { + using var context = new Database(); + return context.Streams + .Select(record => record.GetViewModel) + .ToList(); + } + public StreamViewModel? Insert(StreamBindingModel model) + { + var newStream = Stream.Create(model); + if (newStream == null) + { + return null; + } + using var context = new Database(); + context.Streams.Add(newStream); + context.SaveChanges(); + return newStream.GetViewModel; + } + public StreamViewModel? Update(StreamBindingModel model) + { + using var context = new Database(); + using var transaction = context.Database.BeginTransaction(); + try + { + var stream = context.Streams + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + stream.Update(model); + context.SaveChanges(); + transaction.Commit(); + return stream.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public StreamViewModel? Delete(StreamBindingModel model) + { + using var context = new Database(); + var stream = context.Streams + .FirstOrDefault(record => record.Id.Equals(model.Id)); + if (stream == null) + { + return null; + } + context.Streams.Remove(stream); + context.SaveChanges(); + return stream.GetViewModel; + } + } +} diff --git a/UniversityDataBaseImplemet/Implements/UserStorage.cs b/UniversityDataBaseImplemet/Implements/UserStorage.cs index 658a5ca..0c310b1 100644 --- a/UniversityDataBaseImplemet/Implements/UserStorage.cs +++ b/UniversityDataBaseImplemet/Implements/UserStorage.cs @@ -1,11 +1,4 @@ using Microsoft.EntityFrameworkCore; -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading.Tasks; using UniversityContracts.BindingModels; using UniversityContracts.SearchModels; using UniversityContracts.StoragesContracts; From 9f23e791863f150e8d3cf606ec5c813e4cbf0f9e Mon Sep 17 00:00:00 2001 From: ker73rus Date: Sun, 9 Apr 2023 00:48:03 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B2=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5?= =?UTF-8?q?=D1=81=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/ReportCustomerLogic.cs | 90 +++++++++++++++++++ .../BusinessLogics/ReportProviderLogic.cs | 42 --------- .../BindingModels/ReportBindingModel.cs | 1 + .../IReportCustomerLogic.cs | 22 +++++ ...ipline.cs => ReportDisciplineViewModel.cs} | 4 +- ...> ReportStreamEducationStatusViewModel.cs} | 5 +- .../ViewModels/StreamViewModel.cs | 3 + 7 files changed, 123 insertions(+), 44 deletions(-) create mode 100644 UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs delete mode 100644 UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs create mode 100644 UniversityContracts/BusinessLogicContracts/IReportCustomerLogic.cs rename UniversityContracts/ViewModels/{ReportDiscipline.cs => ReportDisciplineViewModel.cs} (64%) rename UniversityContracts/ViewModels/{ReportStreamEducationGroup.cs => ReportStreamEducationStatusViewModel.cs} (60%) diff --git a/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs new file mode 100644 index 0000000..9290c29 --- /dev/null +++ b/UniversityBusinessLogic/BusinessLogics/ReportCustomerLogic.cs @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.ViewModels; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityBusinessLogic.OfficePackage; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class ReportCustomerLogic : IReportCustomerLogic + { + private readonly IDocumentStorage _documentStorage; + private readonly IStudentStorage _studentStorage; + private readonly IEducationStatusStorage _educationStatusStorage; + private readonly IEducationGroupStorage _educationGroupStorage; + private readonly IDisciplineStorage _disciplineStorage; + private readonly IStreamStorage _streamStorage; + private readonly AbstractSaveToExcelProvider _saveToExcel; + private readonly AbstractSaveToWordProvider _saveToWord; + private readonly AbstractSaveToPdfProvider _saveToPdf; + + public ReportCustomerLogic(IDocumentStorage documentStorage, + IStudentStorage studentStorage, + IEducationStatusStorage educationStatusStorage, + IEducationGroupStorage educationGroupStorage, + IDisciplineStorage disciplineStorage, + IStreamStorage streamStorage, + AbstractSaveToExcelProvider saveToExcel, + AbstractSaveToWordProvider saveToWord, + AbstractSaveToPdfProvider saveToPdf) + { + _documentStorage = documentStorage; + _studentStorage = studentStorage; + _educationStatusStorage = educationStatusStorage; + _educationGroupStorage = educationGroupStorage; + _disciplineStorage = disciplineStorage; + _streamStorage = streamStorage; + _saveToExcel = saveToExcel; + _saveToWord = saveToWord; + _saveToPdf = saveToPdf; + } + + public List GetDisciplineReport(List students) + { + throw new NotImplementedException(); + } + + public List GetStreamEdStat(ReportBindingModel model) + { + + var result = _streamStorage + .GetFilteredList(new StreamSearchModel { UserId = model.UserId }) + .Select(stream => new ReportStreamStudentEdStatPeriodViewModel + { + StreamName = stream.Name, + StudentEdStatus = stream.StudentStream + .Where(student => _documentStorage.GetFilteredList(new DocumentSearchModel + { + UserId = model.UserId, + }) + .Select(student => ( + StudentFIO: $"{student.Value.Name} {student.Value.Surname}", + EdStatus: _educationStatusStorage.GetElement(new EducationStatusSearchModel { Id = student.Value.EducationStatusId })?.Name ?? "не удалось получить")) + .ToList()) + }) + .ToList(); + return result; + } + + public void SaveBlanksToWordFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveDocumentBlankToExcelFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + + public void SaveOrdersToPdfFile(ReportBindingModel model) + { + throw new NotImplementedException(); + } + } +} diff --git a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs deleted file mode 100644 index 930ce2c..0000000 --- a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using UniversityContracts.BindingModels; -using UniversityContracts.BusinessLogicContracts; -using UniversityContracts.ViewModels; -using UniversityContracts.SearchModels; -using UniversityContracts.StoragesContracts; - -namespace UniversityBusinessLogic.BusinessLogics -{ - public class ReportProviderLogic : IReportProviderLogic - { - private readonly IDocumentStorage _documentStorage; - - public List GetStudentsDiscipline() - { - throw new NotImplementedException(); - } - public List StreamStudentEdStatPeriod(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveBlanksToWordFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveDocumentBlankToExcelFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - - public void SaveOrdersToPdfFile(ReportBindingModel model) - { - throw new NotImplementedException(); - } - } -} diff --git a/UniversityContracts/BindingModels/ReportBindingModel.cs b/UniversityContracts/BindingModels/ReportBindingModel.cs index e1bcee0..f626497 100644 --- a/UniversityContracts/BindingModels/ReportBindingModel.cs +++ b/UniversityContracts/BindingModels/ReportBindingModel.cs @@ -11,5 +11,6 @@ namespace UniversityContracts.BindingModels public string FileName { get; set; } = string.Empty; public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? UserId { get; set; } } } diff --git a/UniversityContracts/BusinessLogicContracts/IReportCustomerLogic.cs b/UniversityContracts/BusinessLogicContracts/IReportCustomerLogic.cs new file mode 100644 index 0000000..98db3f7 --- /dev/null +++ b/UniversityContracts/BusinessLogicContracts/IReportCustomerLogic.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.ViewModels; + +namespace UniversityContracts.BusinessLogicContracts +{ + public interface IReportCustomerLogic + { + List GetStudentsDiscipline(List students); + List StreamStudentEdStatPeriod(ReportBindingModel model); + + void SaveBlanksToWordFile(ReportBindingModel model); + + void SaveDocumentBlankToExcelFile(ReportBindingModel model); + + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/UniversityContracts/ViewModels/ReportDiscipline.cs b/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs similarity index 64% rename from UniversityContracts/ViewModels/ReportDiscipline.cs rename to UniversityContracts/ViewModels/ReportDisciplineViewModel.cs index 45a25c8..11de287 100644 --- a/UniversityContracts/ViewModels/ReportDiscipline.cs +++ b/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs @@ -6,8 +6,10 @@ using System.Threading.Tasks; namespace UniversityContracts.ViewModels { - public class ReportDiscipline + public class ReportDisciplineViewModel { + public string DisciplineName { get; set; } = string.Empty; + public List<(string StudentFIO, string DocumentDate, string EdStatus)> StudentEdStatus { get; set; } = new(); //выбираем дисциплину, выбираем период, отображаются студенты зачисленные через приказ в этот период со статусами обучения } } diff --git a/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs b/UniversityContracts/ViewModels/ReportStreamEducationStatusViewModel.cs similarity index 60% rename from UniversityContracts/ViewModels/ReportStreamEducationGroup.cs rename to UniversityContracts/ViewModels/ReportStreamEducationStatusViewModel.cs index 9373391..9c6512e 100644 --- a/UniversityContracts/ViewModels/ReportStreamEducationGroup.cs +++ b/UniversityContracts/ViewModels/ReportStreamEducationStatusViewModel.cs @@ -6,8 +6,11 @@ using System.Threading.Tasks; namespace UniversityContracts.ViewModels { - public class ReportStreamEducationGroup + public class ReportStreamEducationStatusViewModel { + public string StreamName { get; set; } = string.Empty; + public List<(string StudentFIO, string EdStatus)> StudentEdStatus { get; set; } = new(); // при выборе потока показывается список студентов на потоке и их статус обучения + } } diff --git a/UniversityContracts/ViewModels/StreamViewModel.cs b/UniversityContracts/ViewModels/StreamViewModel.cs index 412e6e5..e42a73e 100644 --- a/UniversityContracts/ViewModels/StreamViewModel.cs +++ b/UniversityContracts/ViewModels/StreamViewModel.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; +using UniversityModels.Models; namespace UniversityContracts.ViewModels { @@ -15,5 +16,7 @@ namespace UniversityContracts.ViewModels public string Name { get; set; } = string.Empty; [DisplayName("Номер курса")] public int Course { get; set; } + public Dictionary StudentStream { get; set; } = new(); + } }