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