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

View File

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