From 13ed86ece835fb94dc5305d9b44dd4bde39c332b Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Fri, 7 Apr 2023 17:34:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D0=BF=D0=B8=D1=81=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=20(=D0=BF=D0=BE=D1=87=D1=82=D0=B8)=20=D0=B1=D0=B8=D0=B7?= =?UTF-8?q?=D0=BD=D0=B5=D1=81=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D0=9F=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D1=89?= =?UTF-8?q?=D0=B8=D0=BA.=20=D0=9D=D1=83=D0=B6=D0=BD=D0=B0=20=D0=BB=D0=BE?= =?UTF-8?q?=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D1=87=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/DocumentLogic.cs | 101 +++++++++++++++++ .../BusinessLogics/EducationStatusLogic.cs | 99 +++++++++++++++++ .../BusinessLogics/ReportProviderLogic.cs | 42 +++++++ .../BusinessLogics/StudentLogic.cs | 103 ++++++++++++++++++ UniversityBusinessLogic/Class1.cs | 5 - .../AbstractSaveToExcelProvider.cs | 12 ++ .../AbstractSaveToPdfProvider.cs | 12 ++ .../AbstractSaveToWordProvider.cs | 12 ++ .../UniversityBusinessLogic.csproj | 10 ++ .../BindingModels/ReportBindingModel.cs | 15 +++ .../BusinessLogicContracts/IDocumentLogic.cs | 2 + .../IEducationStatusLogic.cs | 2 + .../IReportProviderLogic.cs | 23 ++++ .../BusinessLogicContracts/IStudentLogic.cs | 2 + .../SearchModels/DocumentSearchModel.cs | 1 + .../SearchModels/StudentSearchModel.cs | 3 + ...eportStreamStudentEdStatPeriodViewModel.cs | 14 +++ .../ReportStudentsDisciplineViewModel.cs | 14 +++ .../Implements/DocumentStorage.cs | 19 ++-- .../Implements/EducationStatusStorage.cs | 25 +++-- .../Implements/StudentStorage.cs | 51 ++++++--- 21 files changed, 528 insertions(+), 39 deletions(-) create mode 100644 UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs create mode 100644 UniversityBusinessLogic/BusinessLogics/EducationStatusLogic.cs create mode 100644 UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs create mode 100644 UniversityBusinessLogic/BusinessLogics/StudentLogic.cs delete mode 100644 UniversityBusinessLogic/Class1.cs create mode 100644 UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs create mode 100644 UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs create mode 100644 UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs create mode 100644 UniversityContracts/BindingModels/ReportBindingModel.cs create mode 100644 UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs create mode 100644 UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs create mode 100644 UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs diff --git a/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs b/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs new file mode 100644 index 0000000..5e028f2 --- /dev/null +++ b/UniversityBusinessLogic/BusinessLogics/DocumentLogic.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class DocumentLogic : IDocumentLogic + { + private readonly IDocumentStorage _documentStorage; + + public DocumentLogic(IDocumentStorage documentStorage) + { + _documentStorage = documentStorage; + } + public bool Create(DocumentBindingModel model) + { + CheckModel(model); + if(_documentStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(DocumentBindingModel model) + { + CheckModel(model, false); + if (_documentStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(DocumentBindingModel model) + { + CheckModel(model, false); + if (_documentStorage.Delete(model) == null) + { + return false; + } + return true; + } + public DocumentViewModel? ReadElement(DocumentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var document = _documentStorage.GetElement(model); + if (document == null) + { + return null; + } + return document; + } + public List? ReadList(DocumentSearchModel? model) + { + var list = model == null ? _documentStorage.GetFullList() : _documentStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + private void CheckModel(DocumentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия документа", nameof(model.Name)); + } + if (model.Date > DateTime.Now) + { + throw new ArgumentNullException("Неверно указана дата", nameof(model.Name)); + } + + var document = _documentStorage.GetElement(new DocumentSearchModel + { + Name = model.Name, + }); + if (document != null && document.Id != model.Id) + { + throw new InvalidOperationException("Приказ с таким названием уже есть"); + } + } + } +} diff --git a/UniversityBusinessLogic/BusinessLogics/EducationStatusLogic.cs b/UniversityBusinessLogic/BusinessLogics/EducationStatusLogic.cs new file mode 100644 index 0000000..21a46b2 --- /dev/null +++ b/UniversityBusinessLogic/BusinessLogics/EducationStatusLogic.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class EducationStatusLogic : IEducationStatusLogic + { + private readonly IEducationStatusStorage _esStorage; + + public EducationStatusLogic(IEducationStatusStorage cardStorage) + { + _esStorage = cardStorage; + } + + public bool Create(EducationStatusBindingModel model) + { + CheckModel(model); + if (_esStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(EducationStatusBindingModel model) + { + CheckModel(model); + if (_esStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(EducationStatusBindingModel model) + { + CheckModel(model, false); + if (_esStorage.Delete(model) == null) + { + return false; + } + return true; + } + public EducationStatusViewModel? ReadElement(EducationStatusSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var es = _esStorage.GetElement(model); + if (es == null) + { + return null; + } + return es; + } + + public List? ReadList(EducationStatusSearchModel? model) + { + var list = model == null ? _esStorage.GetFullList() : _esStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + private void CheckModel(EducationStatusBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия статуса обучения", nameof(model.Name)); + } + + var es = _esStorage.GetElement(new EducationStatusSearchModel + { + Name = model.Name, + }); + if (es != null && es.Id != model.Id) + { + throw new InvalidOperationException("Статус с таким названием уже есть"); + } + } + } +} diff --git a/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs new file mode 100644 index 0000000..230d669 --- /dev/null +++ b/UniversityBusinessLogic/BusinessLogics/ReportProviderLogic.cs @@ -0,0 +1,42 @@ +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) + { + + } + + 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/StudentLogic.cs b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs new file mode 100644 index 0000000..4d19cb0 --- /dev/null +++ b/UniversityBusinessLogic/BusinessLogics/StudentLogic.cs @@ -0,0 +1,103 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UniversityContracts.BindingModels; +using UniversityContracts.BusinessLogicContracts; +using UniversityContracts.SearchModels; +using UniversityContracts.StoragesContracts; +using UniversityContracts.ViewModels; + +namespace UniversityBusinessLogic.BusinessLogics +{ + public class StudentLogic : IStudentLogic + { + private readonly IStudentStorage _studentStorage; + + public StudentLogic(IStudentStorage studentStorage) + { + _studentStorage = studentStorage; + } + + public bool Create(StudentBindingModel model) + { + CheckModel(model); + if (_studentStorage.Insert(model) == null) + { + return false; + } + return true; + } + public bool Update(StudentBindingModel model) + { + CheckModel(model, false); + if (_studentStorage.Update(model) == null) + { + return false; + } + return true; + } + public bool Delete(StudentBindingModel model) + { + CheckModel(model, false); + if (_studentStorage.Delete(model) == null) + { + return false; + } + return true; + } + public StudentViewModel? ReadElement(StudentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + var student = _studentStorage.GetElement(model); + if (student == null) + { + return null; + } + return student; + } + + public List? ReadList(StudentSearchModel? model) + { + var list = model == null ? _studentStorage.GetFullList() : _studentStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + private void CheckModel(StudentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.Name)) + { + throw new ArgumentNullException("Нет названия документа", nameof(model.Name)); + } + if (model.StudentCard <= 0) + { + throw new ArgumentNullException("Неверно указан номер студенческого билета", nameof(model.Name)); + } + + var student = _studentStorage.GetElement(new StudentSearchModel + { + StudentCard = model.StudentCard, + }); + if (student != null && student.Id != model.Id) + { + throw new InvalidOperationException("Приказ с таким названием уже есть"); + } + } + } +} diff --git a/UniversityBusinessLogic/Class1.cs b/UniversityBusinessLogic/Class1.cs deleted file mode 100644 index 7617f79..0000000 --- a/UniversityBusinessLogic/Class1.cs +++ /dev/null @@ -1,5 +0,0 @@ -namespace UniversityBusinessLogic; -public class Class1 -{ - -} diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs new file mode 100644 index 0000000..72e5fe5 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/AbstractSaveToExcelProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToExcelProvider + { + } +} diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs new file mode 100644 index 0000000..ecc2618 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/AbstractSaveToPdfProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToPdfProvider + { + } +} diff --git a/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs b/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs new file mode 100644 index 0000000..b94b729 --- /dev/null +++ b/UniversityBusinessLogic/OfficePackage/AbstractSaveToWordProvider.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityBusinessLogic.OfficePackage +{ + public abstract class AbstractSaveToWordProvider + { + } +} diff --git a/UniversityBusinessLogic/UniversityBusinessLogic.csproj b/UniversityBusinessLogic/UniversityBusinessLogic.csproj index 132c02c..188dc46 100644 --- a/UniversityBusinessLogic/UniversityBusinessLogic.csproj +++ b/UniversityBusinessLogic/UniversityBusinessLogic.csproj @@ -6,4 +6,14 @@ enable + + + + + + + + + + diff --git a/UniversityContracts/BindingModels/ReportBindingModel.cs b/UniversityContracts/BindingModels/ReportBindingModel.cs new file mode 100644 index 0000000..e1bcee0 --- /dev/null +++ b/UniversityContracts/BindingModels/ReportBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.BindingModels +{ + public class ReportBindingModel + { + public string FileName { get; set; } = string.Empty; + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } + } +} diff --git a/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs b/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs index ac651b1..c153311 100644 --- a/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IDocumentLogic.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.BusinessLogicContracts { diff --git a/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs b/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs index 1d339a3..5016c60 100644 --- a/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IEducationStatusLogic.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.BusinessLogicContracts { diff --git a/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs b/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs new file mode 100644 index 0000000..323f7a3 --- /dev/null +++ b/UniversityContracts/BusinessLogicContracts/IReportProviderLogic.cs @@ -0,0 +1,23 @@ +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 IReportProviderLogic + { + List GetStudentsDiscipline(); + + List StreamStudentEdStatPeriod(ReportBindingModel model); + + void SaveBlanksToWordFile(ReportBindingModel model); + + void SaveDocumentBlankToExcelFile(ReportBindingModel model); + + void SaveOrdersToPdfFile(ReportBindingModel model); + } +} diff --git a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs index 20feb08..13eef37 100644 --- a/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs +++ b/UniversityContracts/BusinessLogicContracts/IStudentLogic.cs @@ -4,6 +4,8 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using UniversityContracts.BindingModels; +using UniversityContracts.SearchModels; +using UniversityContracts.ViewModels; namespace UniversityContracts.BusinessLogicContracts { diff --git a/UniversityContracts/SearchModels/DocumentSearchModel.cs b/UniversityContracts/SearchModels/DocumentSearchModel.cs index ca97897..7ae4f19 100644 --- a/UniversityContracts/SearchModels/DocumentSearchModel.cs +++ b/UniversityContracts/SearchModels/DocumentSearchModel.cs @@ -9,6 +9,7 @@ namespace UniversityContracts.SearchModels public class DocumentSearchModel { public int? Id { get; set; } + public string? Name { get; set; } public int? UserId { get; set; } } } diff --git a/UniversityContracts/SearchModels/StudentSearchModel.cs b/UniversityContracts/SearchModels/StudentSearchModel.cs index 2c55b25..cebac82 100644 --- a/UniversityContracts/SearchModels/StudentSearchModel.cs +++ b/UniversityContracts/SearchModels/StudentSearchModel.cs @@ -9,6 +9,9 @@ namespace UniversityContracts.SearchModels public class StudentSearchModel { public int? Id { get; set; } + public int? StudentCard { get; set; } public int? UserId { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } } } diff --git a/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs b/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs new file mode 100644 index 0000000..a743e16 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportStreamStudentEdStatPeriodViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportStreamStudentEdStatPeriodViewModel + { + public string StreamName { get; set; } = string.Empty; + public List<(string StudentFIO, string EdStatus)> StudentEdStatus { get; set; } = new(); + } +} diff --git a/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs b/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs new file mode 100644 index 0000000..6d14046 --- /dev/null +++ b/UniversityContracts/ViewModels/ReportStudentsDisciplineViewModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace UniversityContracts.ViewModels +{ + public class ReportStudentsDisciplineViewModel + { + public string StudentFIO { get; set; } = string.Empty; + public List Disciplines { get; set; } = new(); + } +} diff --git a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs index 0d66be0..fc8dae7 100644 --- a/UniversityDataBaseImplemet/Implements/DocumentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/DocumentStorage.cs @@ -24,8 +24,9 @@ namespace UniversityDataBaseImplemet.Implements using var context = new Database(); return context.Documents .Include(record => record.User) - .FirstOrDefault(record => record.Id == model.Id)? - .GetViewModel; + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; } public List GetFilteredList(DocumentSearchModel model) { @@ -33,7 +34,7 @@ namespace UniversityDataBaseImplemet.Implements if (model.Id.HasValue) { return context.Documents - .Include(x => x.User) + .Include(record => record.User) .Where(record => record.Id.Equals(model.Id)) .Select(record => record.GetViewModel) .ToList(); @@ -41,11 +42,11 @@ namespace UniversityDataBaseImplemet.Implements else if (model.UserId.HasValue) { return context.Documents - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) - .Select(x => x.GetViewModel) + .Include(record => record.User) + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) .ToList(); - } + } else { return new(); @@ -78,7 +79,7 @@ namespace UniversityDataBaseImplemet.Implements try { var document = context.Documents - .Include(x => x.User) + .Include(record => record.User) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (document == null) { @@ -99,7 +100,7 @@ namespace UniversityDataBaseImplemet.Implements { using var context = new Database(); var document = context.Documents - .Include(x => x.User) + .Include(record => record.User) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (document == null) { diff --git a/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs b/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs index 204ac40..e38110e 100644 --- a/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs +++ b/UniversityDataBaseImplemet/Implements/EducationStatusStorage.cs @@ -22,9 +22,10 @@ namespace UniversityDataBaseImplemet.Implements } using var context = new Database(); return context.EducationStatuses - .Include(x => x.User) - .FirstOrDefault(record => record.Id == model.Id)? - .GetViewModel; + .Include(record => record.User) + .FirstOrDefault(record => record.Id == model.Id + || record.Name.Equals(model.Name)) + ?.GetViewModel; } public List GetFilteredList(EducationStatusSearchModel model) { @@ -32,7 +33,7 @@ namespace UniversityDataBaseImplemet.Implements if (model.Id.HasValue) { return context.EducationStatuses - .Include(x => x.User) + .Include(record => record.User) .Where(record => record.Id.Equals(model.Id)) .Select(record => record.GetViewModel) .ToList(); @@ -40,9 +41,9 @@ namespace UniversityDataBaseImplemet.Implements else if (model.UserId.HasValue) { return context.EducationStatuses - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) - .Select(x => x.GetViewModel) + .Include(record => record.User) + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) .ToList(); } else @@ -54,7 +55,7 @@ namespace UniversityDataBaseImplemet.Implements { using var context = new Database(); return context.EducationStatuses - .Include(x => x.User) + .Include(record => record.User) .Select(record => record.GetViewModel) .ToList(); } @@ -69,8 +70,8 @@ namespace UniversityDataBaseImplemet.Implements context.EducationStatuses.Add(newEducationStatus); context.SaveChanges(); return context.EducationStatuses - .Include(x => x.User) - .FirstOrDefault(x => x.Id.Equals(newEducationStatus.Id)) + .Include(record => record.User) + .FirstOrDefault(record => record.Id.Equals(newEducationStatus.Id)) ?.GetViewModel; } public EducationStatusViewModel? Update(EducationStatusBindingModel model) @@ -80,7 +81,7 @@ namespace UniversityDataBaseImplemet.Implements try { var educationStatus = context.EducationStatuses - .Include(x => x.User) + .Include(record => record.User) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (educationStatus == null) { @@ -101,7 +102,7 @@ namespace UniversityDataBaseImplemet.Implements { using var context = new Database(); var educationStatus = context.EducationStatuses - .Include(x => x.User) + .Include(record => record.User) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (educationStatus == null) { diff --git a/UniversityDataBaseImplemet/Implements/StudentStorage.cs b/UniversityDataBaseImplemet/Implements/StudentStorage.cs index 3587a93..bc98658 100644 --- a/UniversityDataBaseImplemet/Implements/StudentStorage.cs +++ b/UniversityDataBaseImplemet/Implements/StudentStorage.cs @@ -1,6 +1,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -17,7 +18,7 @@ namespace UniversityDataBaseImplemet.Implements { public StudentViewModel? GetElement(StudentSearchModel model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && model.StudentCard <= 0) { return null; } @@ -25,7 +26,8 @@ namespace UniversityDataBaseImplemet.Implements return context.Students .Include(record => record.User) .Include(record => record.EducationStatus) - .FirstOrDefault(record => record.Id.Equals(model.Id)) + .FirstOrDefault(record => record.Id.Equals(model.Id) + || record.StudentCard.Equals(model.StudentCard)) ?.GetViewModel; } public List GetFilteredList(StudentSearchModel model) @@ -35,7 +37,7 @@ namespace UniversityDataBaseImplemet.Implements { return context.Students .Include(record => record.EducationStatus) - .Include(x => x.User) + .Include(record => record.User) .Where(record => record.Id.Equals(model.Id)) .Select(record => record.GetViewModel) .ToList(); @@ -43,12 +45,35 @@ namespace UniversityDataBaseImplemet.Implements else if (model.UserId.HasValue) { return context.Students - .Include(x => x.EducationStatus) - .Include(x => x.User) - .Where(x => x.UserId == model.UserId) - .Select(x => x.GetViewModel) + .Include(record => record.EducationStatus) + .Include(record => record.User) + .Where(record => record.UserId == model.UserId) + .Select(record => record.GetViewModel) .ToList(); } + /*else if (model.DateFrom != null && model.DateTo != null) // для отчета#2 Поставщик + { + return context.Students + .Include(record => record.User) + .Include(record => record.EducationStatus) + .Join(context.StudentStreams, student => student.Id, studentStream => studentStream.StudentId, (student, studentStream) => new { Student = student, StreamId = studentStream.StreamId }) + .Join(context.Streams, studentStream => studentStream.StreamId, stream => stream.Id, (studentStream, stream) => new { Student = studentStream.Student, Stream = stream }) + .GroupBy(record => record.Stream) + .Select(result => new + { + Stream = result.Key, + Students = result.Select(record => (record.Student, record.EducationStatus)).ToList() + }) + .ToList(); + var result = context.Students + .Include(student => student.User) + .Include(student => student.StudentStreams) + .ThenInclude(studentStream => studentStream.Stream) + .ThenInclude(stream => stream.Disciplines) + .SelectMany(student => student.StudentStreams, (student, studentStream) => new { Student = student, Stream = studentStream.Stream }) + .Select(record => new { StudentName = record.Student.User.Name + " " + record.Student.User.Surname, Discipline = record.Stream.Disciplines }) + .ToList(); + }*/ else { return new(); @@ -58,8 +83,8 @@ namespace UniversityDataBaseImplemet.Implements { using var context = new Database(); return context.Students - .Include(x => x.User) - .Include(x => x.EducationStatus) + .Include(record => record.User) + .Include(record => record.EducationStatus) .Select(record => record.GetViewModel) .ToList(); } @@ -82,8 +107,8 @@ namespace UniversityDataBaseImplemet.Implements try { var student = context.Students - .Include(x => x.User) - .Include(x => x.EducationStatus) + .Include(record => record.User) + .Include(record => record.EducationStatus) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (student == null) { @@ -104,8 +129,8 @@ namespace UniversityDataBaseImplemet.Implements { using var context = new Database(); var student = context.Students - .Include(x => x.User) - .Include(x => x.EducationStatus) + .Include(record => record.User) + .Include(record => record.EducationStatus) .FirstOrDefault(record => record.Id.Equals(model.Id)); if (student == null) {