Код: Выделить всё
public async Task GetAllGroupsAsync(Guid studentId)
{
var groups = await _dbContext.ProjectGroups
.Include(x => x.StudentGroups)
.ThenInclude(x => x.Student).ThenInclude(x => x.User)
.Where(x => x.StudentGroups.Any(y => y.StudentId == studentId))
.ToListAsync();
if (groups.Count == 0)
return new ApiResponse()
{
Status = "Error",
Message = "No groups found"
};
List result = new List();
foreach (var group in groups)
{
var members = group.StudentGroups.Select(sg => new MemberOfGroupModelResponse()
{
StudentId = sg.StudentId,
UserName = sg.Student.User.UserName,
Email = sg.Student.User.Email,
Name = sg.Student.User.FirstName + " " + sg.Student.User.LastName
}).ToList();
result.Add(new GetManyGroupModelResponse()
{
GroupId = group.GroupId,
Topic = group.Topic,
GroupName = group.GroupName,
Members = members
});
}
return new ApiResponse()
{
Status = "Success",
Message = "Groups found",
Data = result!
};
}
Код: Выделить всё
public class GetManyGroupModelResponse
{
public Guid GroupId { get; set; }
public string? GroupName { get; set; }
public string? Topic { get; set; }
public List? Members { get; set; }
}
Код: Выделить всё
public class MemberOfGroupModelResponse
{
public Guid StudentId { get; set; }
public string? UserName { get; set; }
public string? Name { get; set; }
public string? Email { get; set; }
}
Как я могу гарантировать, что список StudentGroups для всех экземпляров ProjectGroup сохраняется без перезаписи?
Есть ли есть ли лучший способ загрузить эти данные без потери данных?
Заранее благодарим за любую помощь!
Подробнее здесь: https://stackoverflow.com/questions/791 ... ss-in-list
Мобильная версия