Esempio n. 1
0
        public async Task <bool> IsUserCanPostToWallAsync(string username, string WallId)
        {
            var user = await identityService.GetUserByName(username)
                       .SingleOrDefaultAsync();

            var wall = await wallService
                       .GetWallWithoutIncludables(WallId)
                       .SingleOrDefaultAsync();

            var wallOwnerId = await wallService.GetWallOwnerIdAsync(wall);

            if (wallOwnerId == null)
            {
                return(false);
            }

            if (wallOwnerId == user.Id)
            {
                return(true);
            }

            var wallUser = await identityService.GetUserById(wallOwnerId)
                           .SingleOrDefaultAsync();

            if (wallUser != null)
            {
                if (await relationsService.AreFriendsWithAsync(user.UserName, wallUser.UserName))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                var wallGroup = await this.dbContext.Groups
                                .Include(x => x.Members)
                                .SingleOrDefaultAsync(x => x.Id == wallOwnerId);

                if (wallGroup.Members.Any(x => x.User == user))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Esempio n. 2
0
        public async Task <ProfileViewModel> PrepareUserProfileForViewAsync(string actualUserName, string visitingUserName)
        {
            var visitingUser = await IncludeAllProfileDetails(identityService.GetUserByName(visitingUserName))
                               .SingleOrDefaultAsync();

            if (visitingUser == null)
            {
                return(null);
            }

            ProfileViewModel model = mapper.Map <ProfileViewModel>(visitingUser);

            model.Posts = mapper.Map <ICollection <PostViewModel> >(await wallService.GetPostsFromWallDescendingAsync(model.WallId));

            if (actualUserName != visitingUser.UserName)
            {
                var actualUser = await IncludeFriendship(identityService.GetUserByName(actualUserName))
                                 .SingleOrDefaultAsync();

                if (await relationsService.AreFriendsWithAsync(actualUserName, visitingUser.UserName))
                {
                    model.Posts = model.Posts
                                  .Where(x => x.VisibilityType == PostVisibilityType.FriendsOnly ||
                                         x.VisibilityType == PostVisibilityType.Public)
                                  .ToList();
                    model.AreFriends = true;
                }
                else
                {
                    model.Posts = model.Posts
                                  .Where(x => x.VisibilityType == PostVisibilityType.Public)
                                  .ToList();

                    if (actualUser.SentFriendships.Any(x =>
                                                       x.Recipient == visitingUser && x.AcceptedOn == null))
                    {
                        model.PendingFriendship = true;
                    }
                    if (actualUser.ReceivedFriendships.Any(x =>
                                                           x.Sender == visitingUser && x.AcceptedOn == null))
                    {
                        model.CanAcceptFriendship = true;
                    }
                }

                if (await relationsService.IsFollowingAsync(actualUser, visitingUser))
                {
                    model.IsFollowing = true;
                }
            }
            else
            {
                model.FriendSuggestions = await relationsService.GetFriendsOfFriendsAsync(actualUserName, 15);

                model.IsHimself = true;
            }

            if (model.IsHimself || model.AreFriends)
            {
                model.LastPictures = await GetLastNPicturesAsync(visitingUserName, 15);
            }

            return(model);
        }