public async Task <PagedList <Message> > GetMessageForUser(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); break; case "Outbox": messages = messages.Where(u => u.SenderId == messageParams.UserId); break; default: messages = messages.Where(u => u.RecipientId == messageParams.UserId && u.IsRead == false); break; } messages = messages.OrderByDescending(d => d.MessageSent); return(await PagedList <Message> .CreatedAsync(messages, messageParams.PageNumber, messageParams.PageSize)); }
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); if (!string.IsNullOrEmpty(userParams.Gender)) { 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> .CreatedAsync(users, userParams.PageNumber, userParams.PageSize)); }
public async Task <PagedList <User> > GetUsers(UserParams userParams) { //var usuarios = _context.Users.Include(p => p.Fotos).OrderByDescending(u => u.UltimaVezActivo).AsQueryable(); var usuarios = _context.Users.OrderByDescending(u => u.UltimaVezActivo).AsQueryable(); usuarios = usuarios.Where(u => u.Id != userParams.UserId); usuarios = usuarios.Where(u => u.Genero == userParams.Genero); if (userParams.Likers) { var userLikers = await GetUserLikes(userParams.UserId, userParams.Likers); usuarios = usuarios.Where(u => userLikers.Contains(u.Id)); } if (userParams.Likees) { var userLikees = await GetUserLikes(userParams.UserId, userParams.Likers); usuarios = usuarios.Where(u => userLikees.Contains(u.Id)); } if (userParams.EdadMin != 18 || userParams.EdadMax != 95) { var minDate = DateTime.Today.AddYears(-userParams.EdadMax - 1); var maxDate = DateTime.Today.AddYears(-userParams.EdadMin); usuarios = usuarios.Where(u => u.FechaNacimiento >= minDate && u.FechaNacimiento <= maxDate); } if (!string.IsNullOrEmpty(userParams.OrderBy)) { switch (userParams.OrderBy) { case "FechaRegistro": usuarios = usuarios.OrderByDescending(u => u.FechaRegistro); break; default: usuarios = usuarios.OrderByDescending(u => u.UltimaVezActivo); break; } } return(await PagedList <User> .CreatedAsync(usuarios, userParams.PageNumber, userParams.PageSize)); }