This commit is contained in:
Danil Markov 2023-04-09 03:08:30 +04:00
parent bc79eaad4c
commit 0d808aa2be

View File

@ -22,6 +22,8 @@ namespace UniversityDataBaseImplemet.Implements
} }
using var context = new Database(); using var context = new Database();
return context.Streams return context.Streams
.Include(record => record.StreamStudents)
.ThenInclude(record => record.Student)
.FirstOrDefault(record => record.Id == model.Id .FirstOrDefault(record => record.Id == model.Id
|| record.Name.Equals(model.Name)) || record.Name.Equals(model.Name))
?.GetViewModel; ?.GetViewModel;
@ -32,6 +34,8 @@ namespace UniversityDataBaseImplemet.Implements
if (model.Id.HasValue) if (model.Id.HasValue)
{ {
return context.Streams return context.Streams
.Include(record => record.StreamStudents)
.ThenInclude(record => record.Student)
.Where(record => record.Id.Equals(model.Id)) .Where(record => record.Id.Equals(model.Id))
.Select(record => record.GetViewModel) .Select(record => record.GetViewModel)
.ToList(); .ToList();
@ -39,6 +43,8 @@ namespace UniversityDataBaseImplemet.Implements
else if (model.UserId.HasValue) else if (model.UserId.HasValue)
{ {
return context.Streams return context.Streams
.Include(record => record.StreamStudents)
.ThenInclude(record => record.Student)
.Where(record => record.UserId == model.UserId) .Where(record => record.UserId == model.UserId)
.Select(record => record.GetViewModel) .Select(record => record.GetViewModel)
.ToList(); .ToList();
@ -52,6 +58,8 @@ namespace UniversityDataBaseImplemet.Implements
{ {
using var context = new Database(); using var context = new Database();
return context.Streams return context.Streams
.Include(record => record.StreamStudents)
.ThenInclude(record => record.Student)
.Select(record => record.GetViewModel) .Select(record => record.GetViewModel)
.ToList(); .ToList();
} }
@ -81,6 +89,7 @@ namespace UniversityDataBaseImplemet.Implements
} }
stream.Update(model); stream.Update(model);
context.SaveChanges(); context.SaveChanges();
stream.UpdateStreamStudents(context, model);
transaction.Commit(); transaction.Commit();
return stream.GetViewModel; return stream.GetViewModel;
} }