private IForumPost CreatePost()
        {
            var dataAdapter = CreateForumThreadDataAdapter();

            var postedOn = DateTime.UtcNow;
            var author   = new ForumAuthorReference(_portal.Value.User.ToEntityReference());
            var thread   = dataAdapter.Select();

            var postSubmission = new HtmlForumPostSubmission(string.Format("RE: {0}", thread.Name), NewForumPostContent.Text, postedOn, author);

            if (NewForumPostAttachment.HasFiles)
            {
                foreach (var postedFile in NewForumPostAttachment.PostedFiles)
                {
                    using (var reader = new BinaryReader(postedFile.InputStream))
                    {
                        postSubmission.Attachments.Add(new ForumPostAttachment(
                                                           postedFile.FileName,
                                                           postedFile.ContentType,
                                                           reader.ReadBytes(postedFile.ContentLength)));
                    }
                }
            }

            return(dataAdapter.CreatePost(postSubmission));
        }
Пример #2
0
        private IForumThread CreateThread()
        {
            Guid threadTypeId;

            if (!Guid.TryParse(NewForumThreadType.SelectedValue, out threadTypeId))
            {
                throw new InvalidOperationException("Unable to parse forum thread type ID.");
            }

            var postedOn   = DateTime.UtcNow;
            var author     = new ForumAuthorReference(_portal.Value.User.ToEntityReference());
            var threadType = new ForumThreadTypeReference(new EntityReference("adx_forumthreadtype", threadTypeId));

            var threadSubmission = new ForumThreadSubmission(NewForumThreadName.Text, postedOn, author, threadType);
            var postSubmission   = new HtmlForumPostSubmission(NewForumThreadName.Text, NewForumThreadContent.Text, postedOn, author);

            if (NewForumThreadAttachment.HasFiles)
            {
                foreach (var postedFile in NewForumThreadAttachment.PostedFiles)
                {
                    using (var reader = new BinaryReader(postedFile.InputStream))
                    {
                        postSubmission.Attachments.Add(new ForumPostAttachment(
                                                           postedFile.FileName,
                                                           postedFile.ContentType,
                                                           reader.ReadBytes(postedFile.ContentLength)));
                    }
                }
            }

            var dataAdapter = CreateForumDataAdapter();

            return(dataAdapter.CreateThread(threadSubmission, postSubmission));
        }