public void NewPostEmail(IEnumerable<Subscription> Subs, Post ThePost, Thread thread, string PostURL)
        {
            ListDictionary replacements = new ListDictionary();
            string AutoFromEmail = SiteConfig.AutomatedFromEmail.Value;

            MailDefinition md = new MailDefinition();

            md.BodyFileName = EmailTemplates.GenerateEmailPath(EmailTemplates.NewThreadReply);
            md.IsBodyHtml = true;
            md.From = AutoFromEmail;
            md.Subject = "Reply to Thread '" + thread.Title + "' - " + SiteConfig.BoardName.Value;

            replacements.Add("{REPLY_USERNAME}", ThePost.User.Username);
            replacements.Add("{REPLY_TEXT}", ThePost.Text);
            replacements.Add("{THREAD_TITLE}", thread.Title);
            replacements.Add("{POST_URL}", PostURL);
            replacements.Add("{BOARD_URL}", SiteConfig.BoardURL.Value);
            replacements.Add("{BOARD_NAME}", SiteConfig.BoardName.Value);

            System.Web.UI.Control ctrl = new System.Web.UI.Control { ID = "Something" };

            MailMessage message = md.CreateMailMessage("*****@*****.**", replacements, ctrl);

            //Send the message
            SmtpClient client = Settings.GetSmtpClient();

            foreach (Subscription s in Subs)
            {
                if (s.UserID == ThePost.UserID) continue;
                User u = s.User;
                message.To.Clear();
                message.To.Add(u.Email);
                try
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(state => client.Send(message));
                }
                catch
                {
                }
            }
        }
        public Thread CreateThread(
            int forumID,
            int userID,
            string threadTitle,
            ThreadType threadType,
            string threadImage,
            string message,
            string pollText,
            string[] pollOptions,
            HttpPostedFileBase[] files)
        {
            Thread thread = new Thread
            {
                ForumID = forumID,
                Type = (int)threadType,
                Image = threadImage,
                Title = threadTitle,
                HasPoll = false
            };

            string parsedMessage = _parseServices.ParseBBCodeText(message);

            var firstPost = new Post()
            {
                UserID = userID,
                Date = DateTime.UtcNow,
                ThreadID = thread.ThreadID,
                TextOnly = _parseServices.GetTextOnly(message),
                Text = message,
                ParsedText = parsedMessage
            };

            thread.Posts.Add(firstPost);

            if (!string.IsNullOrWhiteSpace(pollText))
            {
                Poll poll = new Poll
                {
                    Question = pollText,
                    PollID = thread.ThreadID
                };

                thread.Poll = poll;

                var options = new System.Data.Objects.DataClasses.EntityCollection<PollOption>();
                foreach (string po in pollOptions)
                {
                    poll.PollOptions.Add(new PollOption
                    {
                        Text = po
                    });
                }
                thread.HasPoll = true;
            }

            if (files != null)
            {
                foreach (var file in files)
                {
                    string savedName = _fileServices.UploadFile(file);
                    firstPost.Attachments.Add(new Attachment()
                    {
                        Downloaded = 0,
                        SavedName = savedName,
                        DownloadName = file.FileName,
                        Size = file.ContentLength,
                        Type = file.ContentType
                    });
                }
            }
            _threadRepository.Add(thread);
            _unitOfWork.Commit();
            return thread;
        }
Example #3
0
        public Post CreatePost(int threadID, int userID, string message, bool useSignature, HttpPostedFileBase[] files)
        {
            string parsedText = _parseServices.ParseBBCodeText(message);
            Post post = new Post()
            {
                Date = DateTime.UtcNow,
                ParsedText = parsedText,
                Text = message,
                TextOnly = _parseServices.GetTextOnly(message),
                ThreadID = threadID,
                UserID = userID,
                UseSignature = useSignature
            };

            _postRepository.Add(post);
            if (files != null)
                _fileServices.CreateAttachments(files, post.PostID);
            _unitOfWork.Commit();
            return post;
        }
        private PostEditorViewModel GeneratePostEditorViewModel(int threadID, EditorType editorType, Post post = null)
        {
            if (editorType == EditorType.Edit && post == null)
                throw new InvalidOperationException("postID is required to generate an edit PostViewModel");

            var model = new PostEditorViewModel();

            if (editorType == EditorType.Edit)
            {
                model.Message = post.Text;
                model.ShowSignature = post.UseSignature;
                model.PostID = post.PostID;
                model.SubscribeToThread = _threadServices.IsSubscribed(threadID, _currentUser.UserID);
                model.Attachments = _fileServices.GetPostAttachments(post.PostID);
            }

            return model;
        }