Exemple #1
0
        private void FilterGroupsBySearch()
        {
            Grouped.Clear();
            GroupedFriendModel csg = new GroupedFriendModel()
            {
                LongName = "Your Contacts", ShortName = "C"
            };
            GroupedFriendModel pg = new GroupedFriendModel()
            {
                LongName = "Pending Friend Requests", ShortName = "P"
            };
            GroupedFriendModel mg = new GroupedFriendModel()
            {
                LongName = "Mutual Friends", ShortName = "M"
            };
            GroupedFriendModel ig = new GroupedFriendModel()
            {
                LongName = "Waiting for Response", ShortName = "W"
            };

            if (String.IsNullOrEmpty(SearchEntry))
            {
                if (_includeImportedContacts)
                {
                    foreach (var mv in ContactSearchRequestFriends.OrderBy(m => m.FirstAndLastName))
                    {
                        csg.Add(mv);
                    }
                }
                foreach (var pv in PendingFriends.OrderBy(m => m.FirstAndLastName))
                {
                    pg.Add(pv);
                }
                foreach (var mv in MutualFriends.OrderBy(m => m.FirstAndLastName))
                {
                    mg.Add(mv);
                }
                foreach (var iv in InitiatedRequestFriends.OrderBy(m => m.FirstAndLastName))
                {
                    ig.Add(iv);
                }
            }
            else
            {
                if (_includeImportedContacts)
                {
                    foreach (var mv in ContactSearchRequestFriends
                             .Where(p => p.UserName
                                    .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                    p.FirstName
                                    .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                    p.LastName
                                    .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                    p.PhoneNumber
                                    .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase))
                             .OrderBy(m => m.FirstAndLastName))
                    {
                        csg.Add(mv);
                    }
                }
                foreach (var pv in PendingFriends
                         .Where(p => p.UserName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.FirstName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.LastName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.PhoneNumber
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase))
                         .OrderBy(m => m.FirstAndLastName))
                {
                    pg.Add(pv);
                }
                foreach (var mv in MutualFriends
                         .Where(p => p.UserName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.FirstName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.LastName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.PhoneNumber
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase))
                         .OrderBy(m => m.FirstAndLastName))
                {
                    mg.Add(mv);
                }
                foreach (var iv in InitiatedRequestFriends
                         .Where(p => p.UserName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.FirstName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.LastName
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase) ||
                                p.PhoneNumber
                                .StartsWith(SearchEntry, StringComparison.OrdinalIgnoreCase))
                         .OrderBy(m => m.FirstAndLastName))
                {
                    ig.Add(iv);
                }
            }
            if (_includeImportedContacts)
            {
                Grouped.Add(csg);
            }
            Grouped.Add(pg);
            Grouped.Add(mg);
            Grouped.Add(ig);
        }
Exemple #2
0
        private async Task SortDataAsync()
        {
            _userSelf = await _requestService.GetAsync <UserInfoContract>("api/UserInfoSelf");

            ContactSearchRequestFriends.Clear();
            MutualFriends.Clear();
            PendingFriends.Clear();
            InitiatedRequestFriends.Clear();

            var entire = await _friendRequestService.GetAllFriendRequestsAsync();

            var initiated = entire.Where(f => f.InitiatorId.Equals(_userSelf.Id) &&
                                         !f.TargetId.Equals(_userSelf.Id)).ToList();
            var targeted = entire.Where(f => f.TargetId.Equals(_userSelf.Id) &&
                                        !f.InitiatorId.Equals(_userSelf.Id)).ToList();

            // first scan through inbound requests,
            // if there is also an initiated request, becomes mutual,
            // otherwise, it is a pending request
            foreach (var req in targeted)
            {
                var initiatorInfo = await _userInfoService.GetUserInfoAsync(req.InitiatorId);

                if (initiated.Any(f => f.TargetId.Equals(req.InitiatorId)))
                {
                    MutualFriends.Add(new FriendViewCellModel(initiatorInfo,
                                                              req.TimeStamp,
                                                              req.Type ?? FriendRequestType.Normal,
                                                              FriendStatus.Mutual));
                }
                else
                {
                    PendingFriends.Add(new FriendViewCellModel(initiatorInfo,
                                                               req.TimeStamp,
                                                               req.Type ?? FriendRequestType.Normal,
                                                               FriendStatus.PendingRequest));
                }
            }
            // scan through the initiated requests,
            // ignoring requests that have a matching target record,
            // these should have already been placed into mutual
            foreach (var req in initiated)
            {
                if (!targeted.Any(f => f.InitiatorId.Equals(req.TargetId)))
                {
                    var targetInfo = await _userInfoService.GetUserInfoAsync(req.TargetId);

                    InitiatedRequestFriends.Add(new FriendViewCellModel(targetInfo,
                                                                        req.TimeStamp,
                                                                        req.Type ?? FriendRequestType.Normal,
                                                                        FriendStatus.Initiated));
                }
            }
            Grouped.Clear();
            GroupedFriendModel csg = new GroupedFriendModel()
            {
                LongName = "Your Contacts", ShortName = "C"
            };

            if (_includeImportedContacts)
            {
                foreach (var mv in ContactSearchRequestFriends.OrderBy(m => m.FirstAndLastName))
                {
                    csg.Add(mv);
                }
            }
            GroupedFriendModel pg = new GroupedFriendModel()
            {
                LongName = "Pending Friend Requests", ShortName = "P"
            };

            foreach (var pv in PendingFriends.OrderBy(m => m.FirstAndLastName))
            {
                pg.Add(pv);
            }
            GroupedFriendModel mg = new GroupedFriendModel()
            {
                LongName = "Mutual Friends", ShortName = "M"
            };

            foreach (var mv in MutualFriends.OrderBy(m => m.FirstAndLastName))
            {
                mg.Add(mv);
            }
            GroupedFriendModel ig = new GroupedFriendModel()
            {
                LongName = "Waiting for Response", ShortName = "W"
            };

            foreach (var iv in InitiatedRequestFriends.OrderBy(m => m.FirstAndLastName))
            {
                ig.Add(iv);
            }
            if (_includeImportedContacts)
            {
                Grouped.Add(csg);
            }
            Grouped.Add(pg);
            Grouped.Add(mg);
            Grouped.Add(ig);
        }