Exemplo n.º 1
0
        public void UpdateImagePrivacy(int imageId, int privacyLevel)
        {
            Models.Image image = imageRepo.ById(imageId);

            if (image.ProfileId != currentProfile.id)
            {
                return;
            }

            image.PrivacyLevel = privacyLevel;
            imageRepo.SaveImage(image);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public PostModel PostPost([FromBody] Post post)
        {
            // If the caption of the provided post is not too long and the attached image is owned by the current user, or there is no image, then create.
            if (post.Caption.Length <= 1000 && (imageRepo.ById(post.ImageId).ProfileId == currentProfile.id || post.ImageId == 0))
            {
                // Set up post information.
                post.DateTime  = DateTime.UtcNow;
                post.ProfileId = currentProfile.id;
                post.Caption   = Util.Sanitize(post.Caption);

                // Commit the post to the database and return a prepped version of it to the user.
                return(GetPostModel(postRepo.SavePost(post)));
            }
            // If the caption was too long, or the image was not owned by the current user, return null.
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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)));
        }