コード例 #1
0
        public async Task GetUserGroups()
        {
            var user           = fillTestDbHelper.Users.FirstOrDefault();
            var expectedGroups = GroupConverter.GetGroupsDto(fillTestDbHelper.Groups.Where(opt => opt.UserId == user.Id).ToList());
            var actualGroups   = await groupsService.GetUserGroupsAsync(user.Id);

            Assert.Equal(expectedGroups.Select(opt => opt.GroupId).OrderBy(opt => opt), actualGroups.Select(opt => opt.GroupId).OrderBy(opt => opt));
        }
コード例 #2
0
        public async Task <List <GroupDto> > GetUserGroupsAsync(long userId)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var groups = await context.Groups.Where(opt => opt.UserId == userId).ToListAsync().ConfigureAwait(false);

                return(GroupConverter.GetGroupsDto(groups));
            }
        }
コード例 #3
0
        public async Task <List <GroupDto> > GetGroupsAsync(List <Guid> groupsId)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var groupsCondition = PredicateBuilder.New <Group>();
                groupsCondition = groupsId.Aggregate(groupsCondition,
                                                     (current, value) => current.Or(opt => opt.GroupId == value).Expand());
                var groups = await context.Groups
                             .Include(opt => opt.ContactGroups)
                             .ThenInclude(opt => opt.Contact)
                             .Where(groupsCondition)
                             .ToListAsync()
                             .ConfigureAwait(false);

                return(GroupConverter.GetGroupsDto(groups));
            }
        }