Beispiel #1
0
        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);
        }