public void CreatePoll(string pollQuestion, string[] pollOptions, int threadID) { System.Data.Objects.DataClasses.EntityCollection<PollOption> toadd = new System.Data.Objects.DataClasses.EntityCollection<PollOption>(); foreach (string po in pollOptions) { toadd.Add(new PollOption { Text = po, PollID = threadID }); } Poll ThePoll = new Poll { PollOptions = toadd, Question = pollQuestion, PollID = threadID }; _pollRepository.Add(ThePoll); Thread thread = _threadRepository.Get(threadID); thread.HasPoll = true; _threadRepository.Update(thread); _unitOfWork.Commit(); }
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; }