Exemplo n.º 1
0
        public FullViewPostDTO ViewPostCollectionDataDL(int postID)
        {
            try
            {
                var         fullViewPost = new FullViewPostDTO();
                ViewPostDTO viewPost     = this.ViewPostAjaxCollectionDataDL(postID);
                fullViewPost.PostSection   = viewPost.PostSection;
                fullViewPost.RepliesToPost = viewPost.RepliesToPost;

                using (var context = new MiniBirdEntities())
                {
                    var person = context.Person.Find(fullViewPost.PostSection.CreatedBy);
                    fullViewPost.ProfileInformation.Birthdate           = (person.Birthdate.HasValue) ? BirthDatePhrase(person.Birthdate) : "";
                    fullViewPost.ProfileInformation.NickName            = person.NickName;
                    fullViewPost.ProfileInformation.PersonalDescription = person.PersonalDescription;
                    fullViewPost.ProfileInformation.ProfileAvatar       = (person.ProfileAvatar != null) ? ByteArrayToBase64(person.ProfileAvatar, person.ProfileAvatar_MimeType) : defaultAvatar;
                    fullViewPost.ProfileInformation.ProfileHeader       = (person.ProfileHeader != null) ? ByteArrayToBase64(person.ProfileHeader, person.ProfileHeader_MimeType) : defaultHeader;
                    fullViewPost.ProfileInformation.RegistrationDate    = person.RegistrationDate;
                    fullViewPost.ProfileInformation.UserName            = person.UserName;
                    fullViewPost.ProfileInformation.WebSiteURL          = person.WebSiteURL;

                    return(fullViewPost);
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 2
0
        public ViewPostDTO ViewPostAjaxCollectionDataDL(int postID)
        {
            try
            {
                using (var context = new MiniBirdEntities())
                {
                    var post      = context.Post.Find(postID);
                    var createdBy = context.Person.Find(post.ID_Person);

                    var ViewPost = new ViewPostDTO();
                    ViewPost.PostSection.PostID          = post.PostID;
                    ViewPost.PostSection.Comment         = post.Comment;
                    ViewPost.PostSection.GIFImage        = post.GIFImage;
                    ViewPost.PostSection.VideoFile       = post.VideoFile;
                    ViewPost.PostSection.Thumbnails      = GetPostedThumbnails(post.PostID);
                    ViewPost.PostSection.PublicationDate = post.PublicationDate;
                    ViewPost.PostSection.CreatedBy       = createdBy.PersonID;
                    ViewPost.PostSection.NickName        = createdBy.NickName;
                    ViewPost.PostSection.UserName        = createdBy.UserName;
                    ViewPost.PostSection.ProfileAvatar   = (createdBy.ProfileAvatar != null) ? ByteArrayToBase64(createdBy.ProfileAvatar, createdBy.ProfileAvatar_MimeType) : defaultAvatar;
                    ViewPost.PostSection.InteractButtons = GetInteractsCountDL(post.PostID, ActiveSession.GetPersonID());

                    if (post.InReplyTo > 0)
                    {
                        var toProfile = context.Post.Find(post.InReplyTo).ID_Person;

                        ViewPost.IsReply              = true;
                        ViewPost.ReplyData.ToProfile  = toProfile;
                        ViewPost.ReplyData.ToUsername = context.Person.Find(toProfile).UserName;
                        ViewPost.ReplyData.ToPost     = Convert.ToInt32(post.InReplyTo);
                    }
                    else
                    {
                        ViewPost.IsReply = false;
                    }

                    var replies = context.Post.Where(r => r.InReplyTo == postID).OrderByDescending(r => r.PublicationDate);

                    foreach (var reply in replies)
                    {
                        var replyCreatedBy = context.Person.Find(reply.ID_Person);

                        ViewPost.RepliesToPost.Add(new PostSectionDTO()
                        {
                            PostID          = reply.PostID,
                            Comment         = reply.Comment,
                            GIFImage        = reply.GIFImage,
                            VideoFile       = reply.VideoFile,
                            Thumbnails      = GetPostedThumbnails(reply.PostID),
                            PublicationDate = reply.PublicationDate,
                            CreatedBy       = replyCreatedBy.PersonID,
                            NickName        = replyCreatedBy.NickName,
                            UserName        = replyCreatedBy.UserName,
                            ProfileAvatar   = (replyCreatedBy.ProfileAvatar != null) ? ByteArrayToBase64(replyCreatedBy.ProfileAvatar, replyCreatedBy.ProfileAvatar_MimeType) : defaultAvatar,
                            InteractButtons = GetInteractsCountDL(reply.PostID, ActiveSession.GetPersonID())
                        });
                    }

                    return(ViewPost);
                }
            }
            catch
            {
                throw;
            }
        }