diff --git a/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs index a7978ce..05a18c3 100644 --- a/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/DisciplineStorage.cs @@ -98,7 +98,6 @@ namespace UniversityDatabaseImplement.Implements { query = query.Where(x => model.DateFrom.Value <= x.Date && x.Date <= model.DateTo.Value); } - return query.Select(x => x.GetViewModel).ToList(); } diff --git a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs index d95f42b..6924782 100644 --- a/University/UniversityDatabaseImplement/Implements/StudentStorage.cs +++ b/University/UniversityDatabaseImplement/Implements/StudentStorage.cs @@ -27,16 +27,29 @@ namespace UniversityDatabaseImplement.Implements { if (model == null) { - return new(); + return new List(); } using var context = new UniversityDatabase(); - return context.Students + // Начальный запрос без фильтрации + var query = context.Students .Include(x => x.User) .Include(x => x.PlanOfStudy) + .AsQueryable(); + + // Если в модели поиска указан Id, добавляем условие фильтрации + if (model.Id.HasValue) + { + query = query.Where(x => x.Id == model.Id.Value); + } + + // Выполняем запрос и получаем результаты + var results = query .Select(x => x.GetViewModel) .ToList(); + + return results; } public StudentViewModel? GetElement(StudentSearchModel model)