Esempio n. 1
0
        public NewsFeedViewModel(AspNetUser user)
        {
            var isAdmin = RoleHandler.isAdmin(user.Id);
            var groups  = user.Groups;
            ICollection <Post> posts = new List <Post>();

            //TODO TBD posts are shown twice
            foreach (var group in groups)
            {
                posts = posts.Union(group.Posts, new PostComparator()).ToList();
            }
            posts = posts.Union(user.Posts, new PostComparator()).ToList();
            FacebookDatabaseEntities entities = new FacebookDatabaseEntities();
            var friends = user.AspNetUsers;

            foreach (var friend in friends)
            {
                posts = posts.Union(friend.Posts.Where(x => groups.Where(y => y.group_id == x.group_id).Any() || x.group_id == null), new PostComparator()).ToList();
            }
            posts = posts.OrderByDescending(x => x.date).Distinct().ToList();

            this.posts = new List <PostViewModel>();
            foreach (var post in posts)
            {
                this.posts.Add(new PostViewModel(post, "Newsfeed", isAdmin));
            }
        }
Esempio n. 2
0
        public GroupsViewModel(string selectedId, string userId)
        {
            var databaseEntities = new FacebookDatabaseEntities();
            var user             = databaseEntities.AspNetUsers.Find(userId);
            var groups           = user.Groups;

            myGroups = groups.Union(user.Groups1, new GroupComparator()).ToList();

            if (selectedId != null)
            {
                selectedGroup = databaseEntities.Groups.Find(int.Parse(selectedId));
            }
            else
            {
                selectedGroup = myGroups.FirstOrDefault();
            }

            //TO-DO add administrator permission
            if (selectedGroup != null)
            {
                newPost = new PostViewModel {
                    appLocation = "Groups", group_id = selectedGroup.group_id
                };
                if (selectedGroup.AspNetUsers.Contains(user))
                {
                    accesPermision = AccesPermision.readPermissions;
                }
                else
                {
                    accesPermision = AccesPermision.noPermission;
                }
            }
            isAdmin = RoleHandler.isAdmin(userId);
        }
Esempio n. 3
0
        public ActionResult Show(string id)
        {
            var databaseEntities = new FacebookDatabaseEntities();

            if (databaseEntities.AspNetUsers.Find(id) == null)
            {
                return(View("Profile", null));
            }

            var iAmaVisitor = true;

            if (User.Identity.GetUserId() == id)
            {
                iAmaVisitor = false;
            }
            var isAdmin = false;

            if (User.Identity.GetUserId() != null)
            {
                isAdmin = RoleHandler.isAdmin(User.Identity.GetUserId());
            }

            var     loggedUser = databaseEntities.AspNetUsers.Find(User.Identity.GetUserId());
            Profile profile    = databaseEntities.Profiles.Find(id);

            if (profile == null)
            {
                return(View("AddProfile", new ProfileViewModel()));
            }
            else
            {
                //TO-DO: add properties to ProfileViewModel like : albums, posts and personal informations and show them into view.
                var aspNetUser = databaseEntities.AspNetUsers.Find(id);
                var posts      = aspNetUser.Posts;
                List <PostViewModel> userPosts = new List <PostViewModel>();
                foreach (var post in posts)
                {
                    userPosts.Add(new PostViewModel(post, "Profile", isAdmin));
                }
                List <Album>          albums     = databaseEntities.Albums.Where(x => x.user_id == id).ToList();
                List <AlbumViewModel> userAlbums = new List <AlbumViewModel>();
                foreach (Album album in albums)
                {
                    userAlbums.Add(new AlbumViewModel(album.name, "Profile", album.album_id, userPosts, id));
                }

                List <AspNetUser> friends         = aspNetUser.AspNetUsers.ToList();
                List <Profile>    profiles        = databaseEntities.Profiles.ToList();
                List <Profile>    friendsProfiles = (from aspUser in friends
                                                     join friendProfile in profiles on aspUser.Id equals friendProfile.Id
                                                     select friendProfile).ToList();
                List <FriendViewModel> friendsList = new List <FriendViewModel>();
                foreach (Profile friend in friendsProfiles)
                {
                    friendsList.Add(new FriendViewModel(friend.Id, friend.Albums.Where(x => x.name == "ProfileAlbum").FirstOrDefault().Pictures.OrderByDescending(x => x.date).FirstOrDefault().path, friend.firstname + friend.lastname));
                }
                var profileViewModel = new ProfileViewModel(profile, userAlbums, userPosts, friendsList);
                profileViewModel.iAmaVisitor = iAmaVisitor;
                profileViewModel.isAdmin     = isAdmin;
                if (iAmaVisitor)
                {
                    var myID = User.Identity.GetUserId();
                    profileViewModel.profileVisitorID = myID;
                    if (friendsProfiles.Select(x => x.Id).ToList().Contains(myID))
                    {
                        profileViewModel.relationshipStatus = FriendshipStatus.friends;
                    }
                    else
                    {
                        profileViewModel.relationshipStatus = MessageHandler.GetFriendRequestStatus(User.Identity.GetUserId(), id);
                    }
                }

                if (profile.privacy == 1)
                {
                    if (profile.AspNetUser.Id != User.Identity.GetUserId() && !aspNetUser.AspNetUsers.Where(x => x.Id == User.Identity.GetUserId()).Any())
                    {
                        profileViewModel.privacy = true;
                    }
                }

                return(View("Profile", profileViewModel));
            }
        }