예제 #1
0
        public JsonResult UsersJson(string searchText, string userType)
        {
            string userId = User.Identity.GetUserId();

            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());

            using (var UsersContext = new ApplicationDbContext())
            {
                List<ApplicationUser> listUsers = null;

                if (searchText != null)
                {
                    listUsers = UsersContext.Users.Where(x => x.Id != userId && x.user.Contains(searchText)).ToList();
                }
                else if (!String.IsNullOrEmpty(userType))
                {
                    if (userType.Equals("All"))
                    {
                        listUsers = UsersContext.Users.Where(x => x.Id != userId).ToList();
                    }
                    else if (userType.Equals("Following"))
                    {
                        listUsers = currentUser.followList;
                    }
                    else if (userType.Equals("Followers"))
                    {
                        List<ApplicationUser> tmpList = UsersContext.Users.ToList();

                        listUsers = new List<ApplicationUser>();

                        foreach (ApplicationUser user in tmpList)
                        {
                            var tmp = user.followList.Find(u => u.Id == currentUser.Id);

                            if (tmp != null)
                                listUsers.Add(user);
                        }
                    }
                    else if (userType.Equals("Blocked"))
                    {
                        listUsers = currentUser.blockedList;
                    }
                }
                else
                    listUsers = UsersContext.Users.Where(x => x.Id != userId).ToList();

                //including additional information if the users are blocked/followed
                List<ExploreUsersViewModel> exploreList = new List<ExploreUsersViewModel>();

                foreach (var user in listUsers)
                {
                    ExploreUsersViewModel tmp = new ExploreUsersViewModel();

                    var follow = currentUser.followList.Find(u => u.Id == user.Id);
                    var block = currentUser.blockedList.Find(u => u.Id == user.Id);

                    tmp.isFollowed = (follow != null) ? "Unfollow" : "Follow";
                    tmp.isBlocked = (block != null) ? "Unblock" : "Block";
                    tmp.Id = user.Id;
                    tmp.user = user.user;
                    tmp.UserName = user.UserName;
                    tmp.isChat = false;
                    tmp.isDisabled = false;

                    exploreList.Add(tmp);

                }

                return Json(exploreList);
            }
        }
예제 #2
0
        public JsonResult UsersJson(string searchText, string userType)
        {
            string userId = User.Identity.GetUserId();

            var manager     = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());

            using (var UsersContext = new ApplicationDbContext())
            {
                List <ApplicationUser> listUsers = null;

                if (searchText != null)
                {
                    listUsers = UsersContext.Users.Where(x => x.Id != userId && x.user.Contains(searchText)).ToList();
                }
                else if (!String.IsNullOrEmpty(userType))
                {
                    if (userType.Equals("All"))
                    {
                        listUsers = UsersContext.Users.Where(x => x.Id != userId).ToList();
                    }
                    else if (userType.Equals("Following"))
                    {
                        listUsers = currentUser.followList;
                    }
                    else if (userType.Equals("Followers"))
                    {
                        List <ApplicationUser> tmpList = UsersContext.Users.ToList();

                        listUsers = new List <ApplicationUser>();

                        foreach (ApplicationUser user in tmpList)
                        {
                            var tmp = user.followList.Find(u => u.Id == currentUser.Id);

                            if (tmp != null)
                            {
                                listUsers.Add(user);
                            }
                        }
                    }
                    else if (userType.Equals("Blocked"))
                    {
                        listUsers = currentUser.blockedList;
                    }
                }
                else
                {
                    listUsers = UsersContext.Users.Where(x => x.Id != userId).ToList();
                }

                //including additional information if the users are blocked/followed
                List <ExploreUsersViewModel> exploreList = new List <ExploreUsersViewModel>();

                foreach (var user in listUsers)
                {
                    ExploreUsersViewModel tmp = new ExploreUsersViewModel();

                    var follow = currentUser.followList.Find(u => u.Id == user.Id);
                    var block  = currentUser.blockedList.Find(u => u.Id == user.Id);

                    tmp.isFollowed = (follow != null) ? "Unfollow" : "Follow";
                    tmp.isBlocked  = (block != null) ? "Unblock" : "Block";
                    tmp.Id         = user.Id;
                    tmp.user       = user.user;
                    tmp.UserName   = user.UserName;
                    tmp.isChat     = false;
                    tmp.isDisabled = false;

                    exploreList.Add(tmp);
                }


                return(Json(exploreList));
            }
        }