Example #1
0
        public async Task <IActionResult> OnGetAsync(string userName, bool?invitation = null)
        {
            var user = await _userManager.GetUserAsync(User);

            var otherUser = await _userManager.FindByNameAsync(userName);

            NameOtherUser = otherUser.UserName;
            if (user == null || otherUser == null)
            {
                return(NotFound());
            }
            MyFriends = await _context.Friends.Where(m => m.ApplicationUserId == user.Id).ToListAsync();

            FriendsOtherUser = await _context.Friends.Where(m => m.ApplicationUserId == otherUser.Id).ToListAsync();

            //Amizade em comum
            foreach (var friend in MyFriends)
            {
                var mutualFriends = FriendsOtherUser
                                    .FirstOrDefault(f => f.ApplicationUserId == friend.ApplicationUserId);
                if (mutualFriends != null)
                {
                    MutualFriends.Add(mutualFriends);
                }
            }

            // Verificar se já são amigos
            IsFriend = MyFriends.Exists(a => a.FriendUserId == otherUser.Id);

            TryInvitation = invitation;

            ReviewBooks = await _context.CommentsBook
                          .Include(u => u.Book)
                          .AsNoTracking()
                          .Where(c => c.UserName == otherUser.UserName)
                          .ToListAsync();

            ReviewSeries = await _context.CommentsSerie
                           .Include(u => u.Serie)
                           .AsNoTracking()
                           .Where(c => c.UserName == otherUser.UserName)
                           .ToListAsync();

            ReviewMovies = await _context.CommentsMovie
                           .Include(u => u.Movie)
                           .AsNoTracking()
                           .Where(c => c.UserName == otherUser.UserName)
                           .ToListAsync();

            return(Page());
        }
Example #2
0
        private async Task PendingRequestButtonTask(FriendViewCellModel fvcm)
        {
            await Task.Delay(10);

            var contract = new FriendRequestContract()
            {
                InitiatorId = _userSelf.Id,
                TargetId    = fvcm.UserId,
                TimeStamp   = DateTime.Now,
                Type        = FriendRequestType.Normal
            };
            await _friendRequestService.PostFriendRequestAsync(contract);

            PendingFriends.Remove(fvcm);
            fvcm.Status = FriendStatus.Mutual;
            MutualFriends.Add(fvcm);
            FilterGroupsBySearch();
        }
Example #3
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);
        }