Exemple #1
0
        public async Task <Result <IEnumerable <UserInfoSmallDTO> > > GetPendingFriends(string userId)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Result <IEnumerable <UserInfoSmallDTO> > .CreateFailed(
                           HttpStatusCode.NotFound, "User not found"));
            }
            var friendlist = await _context.Friends
                             .Where(x => (x.FromUser == user && !x.FromUserAccepted) || (x.ToUser == user && !x.ToUserAccepted))
                             .Include(x => x.FromUser)
                             .Include(x => x.ToUser)
                             .ToListAsync();

            if (friendlist == null)
            {
                return(Result <IEnumerable <UserInfoSmallDTO> > .CreateFailed(
                           HttpStatusCode.NotFound, "User not found"));
            }

            var friends = new List <User>();

            foreach (var friend in friendlist)
            {
                if (friend.ToUser == user)
                {
                    friends.Add(friend.FromUser);
                    continue;
                }
                friends.Add(friend.ToUser);
            }
            return(Result <IEnumerable <UserInfoSmallDTO> > .CreateSuccessful(UserInfoSmallDTO.ToUserInfoSmallDTOList(friends)));
        }
Exemple #2
0
        public async Task <Result <IEnumerable <UserInfoSmallDTO> > > SearchFriends(string userId, string query)
        {
            var user = await _userManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Result <IEnumerable <UserInfoSmallDTO> > .CreateFailed(
                           HttpStatusCode.NotFound, "User not found"));
            }

            query = query.ToLower();

            var array = query.Split(' ');

            var result = await _context.Users.Where(x =>
                                                    array.Contains(x.FirstName.ToLower()) ||
                                                    array.Contains(x.LastName.ToLower()) ||
                                                    array.Contains(x.Email.ToLower())).ToListAsync();

            return(Result <IEnumerable <UserInfoSmallDTO> > .CreateSuccessful(UserInfoSmallDTO.ToUserInfoSmallDTOList(result)));
        }