Example #1
0
        public async Task <PagedList <Message> > GetMessagesForUser(MessageParams messageParams)
        {
            var messages = _context.Messages.Include(u => u.Sender).ThenInclude(p => p.Photos)
                           .Include(u => u.Recipient).ThenInclude(p => p.Photos)
                           .AsQueryable();

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

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

            default:
                messages = messages.Where(u => u.RecipientId == messageParams.userId && u.IsRead == false && u.RecipientDeleted == false);
                break;
            }

            messages = messages.OrderByDescending(d => d.MessageSent);

            return(await PagedList <Message> .CreateAsnc(messages, messageParams.PageNumber, messageParams.PageSize));
        }
Example #2
0
        public async Task <PagedList <User> > GetUsers(UserParams userParams)
        {
            var users = _context.Users.Include(p => p.Photos).OrderByDescending(u => u.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(u => u.DateOfBirth >= minDob && u.DateOfBirth <= maxDob);
            }

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

                default:
                    users = users.OrderByDescending(u => u.LastActive);
                    break;
                }
            }

            return(await PagedList <User> .CreateAsnc(users, userParams.PageNumber, userParams.PageSize));
        }