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/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/ReportDisciplineViewModel.cs b/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs new file mode 100644 index 0000000..11de287 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportDisciplineViewModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + 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/ReportStreamEducationStatusViewModel.cs b/UniversityContracts/ViewModels/ReportStreamEducationStatusViewModel.cs new file mode 100644 index 0000000..9c6512e --- /dev/null +++ b/UniversityContracts/ViewModels/ReportStreamEducationStatusViewModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportStreamEducationStatusViewModel + { + public string StreamName { get; set; } = string.Empty; + public List<(string StudentFIO, string EdStatus)> StudentEdStatus { get; set; } = new(); + // при выборе потока показывается список студентов на потоке и их статус обучения + + } +} 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;