Exemplo n.º 1
0
        public async Task <IActionResult> ExploreNewUsers()
        {
            ViewBag.ActivePage = "ExploreNewUsers";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowingUsers    = _context.ConnectedUsers.Where(cu => cu.FollowedById == currentUser.Id);
            List <CustomUser>          filteredCustomUsers = new List <CustomUser>();
            CustomUser duplicateUser = null;

            foreach (CustomUser customUser in _userManager.Users)
            {
                if (myFollowingUsers.Count() > 0 && customUser.Id != currentUser.Id)
                {
                    foreach (ConnectedUser myFollowingUser in myFollowingUsers)
                    {
                        if (customUser.Id != myFollowingUser.FollowingId)
                        {
                            filteredCustomUsers.Add(customUser);
                            duplicateUser = customUser;
                            //break;
                        }
                        else
                        {
                            if (duplicateUser == customUser)
                            {
                                filteredCustomUsers.Remove(duplicateUser);
                            }
                            break;
                        }
                    }
                }
                else if (myFollowingUsers.Count() == 0 && customUser.Id != currentUser.Id)
                {
                    filteredCustomUsers.Add(customUser);
                }
            }

            for (int i = 0; i < filteredCustomUsers.Count(); i++)
            {
                if (i != filteredCustomUsers.Count())
                {
                    if (filteredCustomUsers.ElementAt(i) == filteredCustomUsers.ElementAt(i + 1))
                    {
                        filteredCustomUsers.Remove(filteredCustomUsers.ElementAt(i));
                    }
                }
            }

            FollowVM followVM = new FollowVM
            {
                FilteredCustomUsers = filteredCustomUsers
            };

            return(View(followVM));
        }
Exemplo n.º 2
0
        private async Task <FollowVM> GetItemsAsync(ApplicationUser user)
        {
            string currentUser = _userManager.GetUserId(HttpContext.User);


            // 2. Connect to Azure Storage account.
            var connectionString = _configuration.GetConnectionString("AccessKey");
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

            // 3. Use container for users profile photos.
            string containerName = "profilephotos";
            BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);

            // 4. Create new blob and upload to azure storage account.
            BlobClient blobClient = containerClient.GetBlobClient("profile-" + user.Id + ".png");

            if (!blobClient.Exists())
            {
                blobClient = containerClient.GetBlobClient("profiledefault.png");
            }

            //BlobDownloadInfo download = await blobClient.DownloadAsync();

            byte[] result = null;
            using (var ms = new MemoryStream())
            {
                blobClient.DownloadTo(ms);
                result = ms.ToArray();
            }


            string base64String = Convert.ToBase64String(result);

            string image = String.Format("data:image/png;base64,{0}", base64String);

            FollowVM followVM = new FollowVM();


            var userFollow = await(from uf in _context.UserFollows
                                   where uf.UserParentId.Equals(currentUser) &&
                                   uf.UserChildId.Equals(user.Id)
                                   select uf).FirstOrDefaultAsync();

            followVM.DisplayName      = user.DisplayName;
            followVM.UserName         = user.UserName;
            followVM.ProfileBiography = user.Biography;
            followVM.AzurePhoto       = image;
            followVM.UserFollow       = userFollow;

            return(followVM);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Followers()
        {
            ViewBag.ActivePage = "Followers";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowers         = _context.ConnectedUsers.Where(cu => cu.FollowingId == currentUser.Id);
            List <CustomUser>          filteredCustomUsers = new List <CustomUser>();

            foreach (CustomUser customUser in _userManager.Users)
            {
                if (myFollowers.Count() > 0 && customUser.Id != currentUser.Id)
                {
                    foreach (ConnectedUser myFollower in myFollowers)
                    {
                        if (customUser.Id == myFollower.FollowedById)
                        {
                            filteredCustomUsers.Add(customUser);
                        }
                    }
                }
            }

            FollowVM followVM = new FollowVM
            {
                FilteredCustomUsers = filteredCustomUsers,
                PairedUsers         = new List <string>()
            };

            foreach (ConnectedUser connectedUser in _context.ConnectedUsers)
            {
                foreach (ConnectedUser myFollower in myFollowers)
                {
                    if (connectedUser.FollowingId == myFollower.FollowedById && connectedUser.FollowedById == currentUser.Id)
                    {
                        followVM.PairedUsers.Add(myFollower.FollowedById);
                        break;
                    }
                    //else
                    //{
                    //    break;
                    //}
                }
            }

            return(View(followVM));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Following()
        {
            ViewBag.ActivePage = "Following";

            currentUser = await MainUtility.FindAnActiveUser(_userManager, User.Identity.Name);

            ViewBag.CurrentUser = currentUser.Id;

            IQueryable <ConnectedUser> myFollowingUsers = _context.ConnectedUsers.Where(cu => cu.FollowedById == currentUser.Id);

            FollowVM followVM = new FollowVM
            {
                MyFollowingUsers = myFollowingUsers
            };

            return(View(followVM));
        }
Exemplo n.º 5
0
        private void FollowViewLoaded(object sender, RoutedEventArgs e)
        {
            if (NavigationMode == NavigationMode.Back && FollowVM.User != null)
            {
                if (FollowVM.User.Pk == User.Pk)
                {
                    return;
                }
                //try
                //{
                //    this.ResetPageCache();
                //    //NavigationCacheMode = NavigationCacheMode.Disabled;
                //    NavigationCacheMode = NavigationCacheMode.Enabled;
                //    First = false;
                //}
                //catch { }
            }
            else if (NavigationMode == NavigationMode.New)
            {
                GetType().RemovePageFromBackStack();
                //this.ResetPageCache();
                //NavigationCacheMode = NavigationCacheMode.Disabled;
                NavigationCacheMode = NavigationCacheMode.Enabled;
                CanLoadFirstPopUp   = false;
            }
            SetFollowersLV();
            SetFollowingsLV();
            FollowVM.SetUser(User);

            try
            {
                if (!CanLoadFirstPopUp)
                {
                    FollowingsSearchText.Text = "";
                    FollowersSearchText.Text  = "";
                    //if (User.Pk == Helper.CurrentUser.Pk)
                    //{
                    //    if (MainPivot.Items.Count > 2)
                    //    {
                    //        try
                    //        {
                    //            MainPivot.Items.RemoveAt(MainPivot.Items.Count - 1);
                    //        }
                    //        catch { }
                    //    }
                    //    try
                    //    {
                    //        var pItem = GetPivotItem();
                    //        MainPivot.Items.Add(pItem);
                    //    }
                    //    catch { }
                    //}
                    //else
                    //{
                    //    if (MainPivot.Items.Count > 2)
                    //    {
                    //        try
                    //        {
                    //            MainPivot.Items.RemoveAt(MainPivot.Items.Count - 1);
                    //        }
                    //        catch { }
                    //    }
                    //}
                    try
                    {
                        MainPivot.SelectedIndex = SelectIndex;
                    }
                    catch { }



                    try
                    {
                        if (SelectIndex == 1)
                        {
                            FollowVM.FollowersGenerator.RunLoadMore(true);
                            FollowVM.FollowingsGenerator.RunLoadMore(true);
                        }
                        else if (SelectIndex == 2)
                        {
                            FollowVM.FollowingsGenerator.RunLoadMore(true);
                            FollowVM.FollowersGenerator.RunLoadMore(true);
                        }
                    }
                    catch { }
                    //if (User.Pk == Helper.CurrentUser.Pk)
                    FollowVM.MutualFriendsGenerator.RunLoadMore(true);
                    CanLoadFirstPopUp = true;
                }
            }
            catch { }
        }
Exemplo n.º 6
0
        private void FollowViewLoaded(object sender, RoutedEventArgs e)
        {
            RefreshControl.RefreshRequested -= RefreshControlRefreshRequested;
            RefreshControl.RefreshRequested += RefreshControlRefreshRequested;


            RefreshControl2.RefreshRequested -= RefreshControl2RefreshRequested;
            RefreshControl2.RefreshRequested += RefreshControl2RefreshRequested;


            RefreshControl3.RefreshRequested -= RefreshControl3RefreshRequested;
            RefreshControl3.RefreshRequested += RefreshControl3RefreshRequested;
            if (NavigationMode == NavigationMode.Back && FollowVM.User != null)
            {
                if (FollowVM.User.Pk == User.Pk)
                {
                    return;
                }
            }
            else if (NavigationMode == NavigationMode.New)
            {
                GetType().RemovePageFromBackStack();
                NavigationCacheMode = NavigationCacheMode.Enabled;
                CanLoadFirstPopUp   = false;
            }
            SetFollowersLV();
            SetFollowingsLV();
            FollowVM.SetUser(User);

            try
            {
                if (!CanLoadFirstPopUp)
                {
                    FollowingsSearchText.Text = "";
                    FollowersSearchText.Text  = "";
                    try
                    {
                        MainPivot.SelectedIndex = SelectIndex;
                    }
                    catch { }



                    try
                    {
                        if (SelectIndex == 1)
                        {
                            FollowVM.FollowersGenerator.RunLoadMore(true);
                            FollowVM.FollowingsGenerator.RunLoadMore(true);
                        }
                        else if (SelectIndex == 2)
                        {
                            FollowVM.FollowingsGenerator.RunLoadMore(true);
                            FollowVM.FollowersGenerator.RunLoadMore(true);
                        }
                    }
                    catch { }
                    FollowVM.MutualFriendsGenerator.RunLoadMore(true);
                    CanLoadFirstPopUp = true;
                }
            }
            catch { }
        }
Exemplo n.º 7
0
        public async Task <IViewComponentResult> InvokeAsync(ApplicationUser user)
        {
            FollowVM followVM = await GetItemsAsync(user);

            return(View(followVM));
        }