Пример #1
0
 public IEnumerable <Group> GetAll()
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var groups = _context.Groups.AsNoTracking()
                      .Include(g => g.Invitations)
                      .Include(g => g.Members)
                      .Include(g => g.Messages)
                      .Include(g => g.Tags)
                      .Include(g => g.GroupMessages)
                      .Include(g => g.Kicked)
                      .Where(g => !g.IsDeleted)
                      .ToList();
         var allGroups = new List <Group>();
         groups.ForEach(g => allGroups.Add(GroupExtensions.ParseFromGroupDto(g)));
         return(allGroups);
     }
 }
Пример #2
0
 public Group GetGroupById(int id)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var currentGroupDto = _context.Groups
                               .Include(g => g.Invitations)
                               .Include(g => g.Messages)
                               .Include(g => g.Members)
                               .Include(g => g.GroupMessages)
                               .Include(g => g.Kicked)
                               .Include(g => g.Tags)
                               .FirstOrDefault(g => g.Id == id && !g.IsDeleted);
         Ensure.Any.IsNotNull(currentGroupDto, nameof(currentGroupDto),
                              opt => opt.WithException(new GroupNotFoundException()));
         var result = GroupExtensions.ParseFromGroupDto(currentGroupDto);
         return(result);
     }
 }
Пример #3
0
 public IEnumerable <Group> GetGroupsByMemberId(int memberId)
 {
     using (var _context = new EduhubContext(_connectionString))
     {
         var foundValues = _context.Groups
                           .Include(g => g.Invitations)
                           .Include(g => g.Members)
                           .Include(g => g.Kicked)
                           .Include(g => g.Messages)
                           .Include(g => g.GroupMessages)
                           .Include(g => g.Tags)
                           .Where(g => g.Members.Any(m => m.Id == memberId) && !g.IsDeleted)
                           .ToList();
         var result = new List <Group>();
         foundValues.ForEach(groupDto => result.Add(GroupExtensions.ParseFromGroupDto(groupDto)));
         return(result);
     }
 }