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