Пример #1
0
        public FullProfileModel GetFullProfile(int profileId)
        {
            int?blockerId = friendRepo.BlockerProfileId(currentProfile.id, profileId);

            if (blockerId != null && (blockerId == currentProfile.id || blockerId == profileId))
            {
                return(null);
            }

            // Get profile by ProfileID.
            Profile profile = profileRepo.ById(profileId);

            // Get profile picture image by ImageID.
            Image image = imageRepo.ById(profile.ProfilePicture);

            // Prep profile.
            FullProfileModel fullProfileModel = new FullProfileModel
            {
                // Details from profile.
                ProfileId = profile.ProfileId,
                FirstName = profile.FirstName,
                LastName  = profile.LastName,

                // Get data for relationship button.
                RelationToUser = friendRepo.RelationToUser(currentProfile.id, profileId)
            };

            int relationshipTier = friendRepo.RelationshipTier(currentProfile.id, profileId);

            // If bio privacy level does not exceed relationship level
            if (profile.ProfileBioPrivacyLevel <= relationshipTier)
            {
                fullProfileModel.Bio = profile.Bio;
            }
            else
            {
                fullProfileModel.Bio = "";
            }

            // If current user has access to profile picture and the image is not null.
            if (profile.ProfilePicturePrivacyLevel <= relationshipTier && image.ImageId != 0)
            {
                fullProfileModel.ProfilePicture = Util.GetRawImage(image, 2);
            }
            else
            {
                fullProfileModel.ProfilePicture = Util.GetRawImage(new Models.Image(), 2);
            }

            return(fullProfileModel);
        }
Пример #2
0
        // prep comment to be sent to client
        public CommentModel GetCommentModel(int commentId)
        {
            Comment comment = commentRepo.ById(commentId); // get comment by CommentId

            if (comment == null)
            {
                return(null);                                      // if no comment was found, return null
            }
            Profile profile = profileRepo.ById(comment.ProfileId); // get handle on owner of comment

            DateTime?likeDateTime = new DateTime();
            Like     like         = likeRepo.ByTypeAndProfileId(2, commentId, currentProfile.id);

            if (like != null)
            {
                likeDateTime = like.DateTime.ToLocalTime();
            }

            LikeModel likes = new LikeModel                                       // attach info for likes
            {
                ContentId   = commentId,                                          // link like data to parent comment by CommentId
                ContentType = 2,
                Count       = likeRepo.CountByContentId(2, commentId),            // set like count by CommentId
                HasLiked    = likeRepo.HasLiked(2, commentId, currentProfile.id), // determine if user has like and assign value
                DateTime    = likeDateTime
            };

            Image    profilePicture         = imageRepo.ById(profile.ProfilePicture);
            string   relationToUser         = friendRepo.RelationToUser(currentProfile.id, profile.ProfileId);
            int      relationshipTier       = friendRepo.RelationshipTier(currentProfile.id, profile.ProfileId);
            DateTime?relationChangeDateTime = friendRepo.RelationshipChangeDatetime(currentProfile.id, profile.ProfileId);
            int?     blockerProfileId       = friendRepo.BlockerProfileId(currentProfile.id, profile.ProfileId);

            ProfileModel profileModel = Util.GetProfileModel(
                profile, profilePicture, relationToUser, relationshipTier, relationChangeDateTime, blockerProfileId);

            CommentModel commentModel = new CommentModel // fill with data from comment and likeModel
            {
                CommentId = comment.CommentId,
                Content   = comment.Content,
                HasSeen   = comment.HasSeen,

                // attach prepped ProfileModel XXX shouldn't need to enter all this data about the user
                Profile = profileModel,

                DateTime = comment.DateTime.ToLocalTime(),
                Likes    = likes,
                PostId   = comment.PostId
            };

            return(commentModel);
        }
Пример #3
0
        /*
         *  Preps a profile to be sent back to client.
         */
        public ProfileModel GetProfileModel(int?profileId)
        {
            // Get profile by ProfileID.
            Profile profile = profileRepo.ById(profileId);

            // Prep profile picture.
            Image image = imageRepo.ById(profile.ProfilePicture);

            // Return prepped profile.
            return(Util.GetProfileModel(
                       profile,
                       image,
                       friendRepo.RelationToUser(currentProfile.id, profileId),
                       friendRepo.RelationshipTier(currentProfile.id, profileId),
                       friendRepo.RelationshipChangeDatetime(currentProfile.id, profileId),
                       friendRepo.BlockerProfileId(currentProfile.id, profileId)));
        }
Пример #4
0
        //-----------------------------------------UTIL---------------------------------------------//

        /*
         *   Preps a post to be sent back to the user.
         */
        public PostModel GetPostModel(int postId)
        {
            // Get handle on post by PostID.
            Post post = postRepo.ById(postId);

            // Get handle on post owner by ProfileID
            Profile profile = profileRepo.ById(post.ProfileId);

            int relationshipTier = friendRepo.RelationshipTier(currentProfile.id, profile.ProfileId);

            if (post.PrivacyLevel <= relationshipTier)
            {
                string   relationToUser         = friendRepo.RelationToUser(currentProfile.id, profile.ProfileId);
                DateTime?relationChangeDatetime = friendRepo.RelationshipChangeDatetime(currentProfile.id, postId);
                int?     blockerProfileId       = friendRepo.BlockerProfileId(currentProfile.id, postId);

                // Get handle on profile picture of owner of post.
                Image profilePicture = imageRepo.ById(profile.ProfilePicture);

                ProfileModel profileModel = Util.GetProfileModel(
                    profile, profilePicture, relationToUser, relationshipTier, relationChangeDatetime, blockerProfileId);

                RawImage postImage = Util.GetRawImage(imageRepo.ById(post.ImageId), 2);

                int  count    = likeRepo.CountByContentId(1, postId);
                bool hasLiked = likeRepo.HasLiked(1, postId, currentProfile.id);

                Like     like     = likeRepo.ByTypeAndProfileId(1, postId, currentProfile.id);
                DateTime dateTime = new DateTime();
                if (like != null)
                {
                    dateTime = like.DateTime.ToLocalTime();
                }

                LikeModel likes = new LikeModel
                {
                    ContentId   = postId,
                    ContentType = 1,
                    Count       = count,
                    HasLiked    = hasLiked,
                    DateTime    = dateTime
                };

                // Prep post.
                PostModel postModel = new PostModel
                {
                    // Details from post record.
                    PostId   = post.PostId,
                    Caption  = post.Caption,
                    DateTime = post.DateTime.ToLocalTime(),
                    Profile  = profileModel,
                    Likes    = likes,
                    Image    = postImage
                };

                // If the post does not have an image, set the image field to null.
                if (post.ImageId == 0)
                {
                    postModel.Image = null;
                }

                // Else attach prepped image.
                else
                {
                    postModel.Image = Util.GetRawImage(imageRepo.ById(post.ImageId), 2, true);
                }

                // Return prepped post to caller.
                return(postModel);
            }
            return(null);
        }