public async Task <PagedList <User> > GetUsers(UserParams userParams)
        {
            var users = _context.Users.Include(p => p.photos).AsQueryable();

            users = users.Where(u => u.Id != userParams.UserId);
            users = users.Where(u => u.Gender == userParams.Gender);

            if (userParams.Likers)
            {
                var userLikers = await GetUserLikes(userParams.UserId, userParams.Likers);

                users = users.Where(user => userLikers.Contains(user.Id));
            }
            if (userParams.Likees)
            {
                var userLikees = await GetUserLikes(userParams.UserId, userParams.Likers);

                users = users.Where(user => userLikees.Contains(user.Id));
            }

            if (userParams.MinAge != 18 || userParams.MaxAge != 99)
            {
                var minDob = DateTime.Today.AddYears(-userParams.MaxAge - 1);
                var maxDob = DateTime.Today.AddYears(-userParams.MinAge);
                users = users.Where(u => u.DateOfBirth >= minDob && u.DateOfBirth <= maxDob);
            }

            return(await PagedList <User> .createAsync(users, userParams.PageNumber, userParams.PageSize));
        }
Exemplo n.º 2
0
        public async Task <PagedList <Message> > GetMessagesForUser(MessageParams messageParams)
        {
            var messages = _context.Messages
                           .Include(u => u.Sender).ThenInclude(u => u.Photos)
                           .Include(u => u.Recipient).ThenInclude(u => u.Photos)
                           .AsQueryable();

            switch (messageParams.MessageContainer)
            {
            case "Inbox":
                messages = messages.Where(x => x.RecipientId == messageParams.UserId && x.RecipientDeleted == false);
                break;

            case "Outbox":
                messages = messages.Where(x => x.SenderId == messageParams.UserId && x.SenderDeleted == false);
                break;

            default:
                messages = messages.Where(x => x.RecipientId == messageParams.UserId && x.RecipientDeleted == false && !x.IsRead);
                break;
            }

            messages.OrderByDescending(x => x.DateSent);
            return(await PagedList <Message> .createAsync(messages, messageParams.PageNumber, messageParams.PageSize));
        }
Exemplo n.º 3
0
        public async Task <PagedList <User> > GetUsers(UserParams userParams)
        {
            var users = _context.Users.Include(p => p.Photos).OrderByDescending(x => x.LastActive).AsQueryable();

            users = users.Where(u => u.Id != userParams.UserId);
            users = users.Where(u => u.Gender == userParams.Gender);

            if (userParams.Likers)
            {
                var userLikers = await GetUserLikes(userParams.UserId, userParams.Likers);

                users = users.Where(u => userLikers.Contains(u.Id));
            }

            if (userParams.Likees)
            {
                var userLikees = await GetUserLikes(userParams.UserId, userParams.Likers);

                users = users.Where(u => userLikees.Contains(u.Id));
            }

            if (userParams.MinAge != 18 || userParams.MaxAge != 99)
            {
                var minDOB = DateTime.Today.AddYears(-userParams.MaxAge - 1);
                var maxDOB = DateTime.Today.AddYears(-userParams.MinAge);
                users = users.Where(a => a.DateOfBirth >= minDOB && a.DateOfBirth <= maxDOB);
            }

            if (!string.IsNullOrEmpty(userParams.OrderBy))
            {
                switch (userParams.OrderBy)
                {
                case "created":
                    users = users.OrderByDescending(x => x.Created);
                    break;

                default:
                    users = users.OrderByDescending(x => x.LastActive);
                    break;
                }
            }
            return(await PagedList <User> .createAsync(users, userParams.PageNumber, userParams.PageSize));
        }