Example #1
0
        public async Task GetGroupContacts()
        {
            var user             = fillTestDbHelper.Users.FirstOrDefault(opt => opt.Groups.Any());
            var group            = fillTestDbHelper.Groups.FirstOrDefault(opt => opt.UserId == user.Id);
            var expectedContacts = ContactConverter.GetContactsDto(group.ContactGroups.Select(opt => opt.Contact).ToList());
            var actualContacts   = await groupsService.GetGroupContactsAsync(group.GroupId, user.Id);

            Assert.Equal(expectedContacts.Select(opt => opt.ContactId), actualContacts.Select(opt => opt.ContactId));
        }
Example #2
0
        public async Task <List <ContactDto> > GetUsersContactsAsync(long userId, List <long> usersId)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var contactsCondition = PredicateBuilder.New <Contact>();
                contactsCondition = usersId.Aggregate(contactsCondition,
                                                      (current, value) => current.Or(opt => opt.UserId == value).Expand());
                var contacts = await context.Contacts
                               .Include(opt => opt.ContactGroups)
                               .Where(opt => opt.ContactUserId == userId)
                               .Where(contactsCondition)
                               .ToListAsync().ConfigureAwait(false);

                return(ContactConverter.GetContactsDto(contacts));
            }
        }
Example #3
0
        public async Task <List <ContactDto> > GetGroupContactsAsync(Guid groupId, long userId, long?navigationUserId = 0)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var contacts = await context.ContactsGroups
                               .Include(opt => opt.Contact)
                               .OrderBy(opt => opt.Contact.ContactUserId)
                               .Where(opt => opt.GroupId == groupId && opt.Contact.ContactUserId > navigationUserId && opt.Contact.UserId == userId)
                               .Select(opt => opt.Contact)
                               .Include(opt => opt.ContactUser)
                               .Include(opt => opt.ContactGroups)
                               .ThenInclude(opt => opt.Group)
                               .ToListAsync()
                               .ConfigureAwait(false);

                return(ContactConverter.GetContactsDto(contacts));
            }
        }
Example #4
0
        public async Task <List <ContactDto> > GetUserContactsAsync(long userId, long navigationUserId = 0, byte?limit = null)
        {
            using (MessengerDbContext context = contextFactory.Create())
            {
                var query = context.Contacts
                            .OrderBy(opt => opt.ContactUserId)
                            .Include(opt => opt.ContactUser)
                            .Include(opt => opt.ContactGroups)
                            .Where(opt => opt.UserId == userId && opt.ContactUserId > navigationUserId);
                if (limit != null)
                {
                    query = query.Take(limit.Value);
                }

                var contacts = await query.ToListAsync().ConfigureAwait(false);

                return(ContactConverter.GetContactsDto(contacts));
            }
        }