Ejemplo n.º 1
0
        public async Task <PageListed <Messages> > GetMessagesForUser(MessageParams messageParams)
        {
            var messages = _dataContext.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.RecipientDeleted == false &&
                                          u.IsRead == false);
                break;
            }
            messages = messages.OrderByDescending(d => d.MessageSent);
            return(await PageListed <Messages> .
                   CreateAsync(messages, messageParams.PageNumber, messageParams.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <PageListed <User> > GetUsers(UserParams userParams)
        {
            /*
             * var user = await _context.Users.Include(p=> p.Photos).ToListAsync();
             * //var user = await _context.Users.ToListAsync();
             * return user;*/

            //nuevos cambios fase 14 , paginando
            var users = _context.Users.Include(p => p.Photos)
                        .OrderByDescending(u => u.LastActivity)
                        .AsQueryable();

            //omitir al usuario actual de la consulta
            users = users.Where(u => u.Id != userParams.UserId);
            //filtrando los usuarios por el genero
            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));
            }

            //adicionales filtros
            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.LastActivity);
                    break;
                }
            }
            return(await PageListed <User> .CreateAsync(users, userParams.PageNumber, userParams.PageSize));
        }
Ejemplo n.º 3
0
        public async Task <PageListed <Users> > GetUsers(UserParams userParams)
        {
            var users = _dataContext.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) // Users That Have Liked ME!
            {
                var userIveLiked = await GetUserLikes(userParams.UserId, userParams.Likers);

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

            if (userParams.Likees) // Users That I Have Liked
            {
                var usersHavelikedme = await GetUserLikes(userParams.UserId, userParams.Likers);

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

            if (userParams.MinAge != 18 || userParams.MaxAge != 99)
            {
                var minDateOb = DateTime.Today.AddYears(-userParams.MaxAge - 1);
                var maxDateOb = DateTime.Today.AddYears(-userParams.MinAge);

                users = users.Where(u => u.DateofBirth >= minDateOb && u.DateofBirth <= maxDateOb);
            }

            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 PageListed <Users> .CreateAsync(users, userParams.PageNumber, userParams.PageSize));
        }