コード例 #1
0
        /// <summary>
        /// creates a new forum topic and post.
        /// </summary>
        /// <param name="forumId"></param>
        /// <param name="forumType"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public static long CreateNewForumTopicAndPost(Guid forumId, ForumOwnerTypeEnum forumType, string subject, string message, Guid memberId, long groupId, bool emailGroupAboutPost, bool pinMessage, bool lockMessage, long chosenCategory)
        {
            try
            {
                var dc = new ManagementContext();
                var forum = dc.Forums.Where(x => x.ForumId == forumId).FirstOrDefault();
                if (forum != null)
                {
                    var member = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
                    member.TotalForumPosts = member.TotalForumPosts + 1;
                    DataModels.Forum.ForumMessage mess = new DataModels.Forum.ForumMessage();
                    mess.Member = member;
                    if (!String.IsNullOrEmpty(message))
                    {
                        message = message.Replace(Environment.NewLine, "<br/>");
                        message = message.Replace("\r", "<br/>");
                    }
                    mess.MessageHTML = message;
                    if (!String.IsNullOrEmpty(message))
                        mess.MessagePlain = _htmlRegex.Replace(message, " ");
                    else
                        mess.MessagePlain = message;
                    mess.LastModified = DateTime.UtcNow;

                    RDN.Library.DataModels.Forum.ForumTopic topic = new DataModels.Forum.ForumTopic();
                    topic.CreatedByMember = member;
                    topic.LastPostDateTime = DateTime.UtcNow;
                    topic.LastPostByMember = member;
                    if (groupId > 0)
                        topic.GroupId = groupId;
                    topic.Forum = forum;
                    topic.Messages.Add(mess);
                    topic.TopicTitle = subject;
                    topic.LastModified = DateTime.UtcNow;
                    topic.IsSticky = pinMessage;
                    topic.IsLocked = lockMessage;
                    if (chosenCategory > 0)
                        topic.Category = forum.Categories.Where(x => x.CategoryId == chosenCategory).FirstOrDefault();

                    forum.Topics.Add(topic);
                    int c = dc.SaveChanges();
                    UpdateForumInbox(dc, topic, memberId);

                    string groupName = "Forum";
                    if (topic.Forum.LeagueOwner != null)
                        groupName = topic.Forum.LeagueOwner.Name;
                    if (topic.GroupId > 0)
                    {
                        try
                        {
                            var group = SiteCache.GetAllGroups().Where(x => x != null && x.Id == topic.GroupId).FirstOrDefault();
                            if (group != null)
                                groupName = group.GroupName;
                        }
                        catch (Exception exception)
                        {
                            ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: forumId.ToString() + ":" + forumType + ":" + subject + ":" + message + ":" + memberId.ToString() + ":" + groupId + ":" + emailGroupAboutPost + ":" + pinMessage + ":" + lockMessage + ":" + chosenCategory);
                        }
                    }
                    if (topic.Forum.LeagueOwner != null)
                    {
                        var notify = new ForumNotificationFactory(forumId, topic.Forum.LeagueOwner.LeagueId, true, emailGroupAboutPost, topic.GroupId, topic.TopicId, groupName, topic.TopicTitle, mess.MessageHTML, member.MemberId, member.DerbyName)
                        .LeagueEmailAboutForumPost()
                        .EmailMembersOnWatchList();

                        //notify.MembersSent.Add(new MemberDisplayBasic() { MemberId = member.MemberId, UserId = member.AspNetUserId });
                        var fact = new MobileNotificationFactory()
                            .Initialize("Forum Post:", topic.TopicTitle, Mobile.Enums.NotificationTypeEnum.Forum)
                            .AddId(topic.TopicId)
                            .AddMembers(notify.membersAlreadyEmailed)
                            .SendNotifications();


                    }
                    return topic.TopicId;
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: forumId.ToString() + ":" + forumType + ":" + subject + ":" + message + ":" + memberId.ToString() + ":" + groupId + ":" + emailGroupAboutPost + ":" + pinMessage + ":" + lockMessage + ":" + chosenCategory);
            }
            return 0;
        }
コード例 #2
0
        public static void ReplyToPost(Guid forumId, long topicId, string message, Guid memberId, bool emailGroupAboutPost)
        {
            try
            {

                var dc = new ManagementContext();
                var topic = dc.ForumTopics.Where(x => x.Forum.ForumId == forumId).Where(x => x.TopicId == topicId).FirstOrDefault();
                if (topic != null)
                {
                    var member = dc.Members.Where(x => x.MemberId == memberId).FirstOrDefault();
                    member.TotalForumPosts = member.TotalForumPosts + 1;
                    DataModels.Forum.ForumMessage mess = new DataModels.Forum.ForumMessage();
                    mess.Member = member;
                    if (!String.IsNullOrEmpty(message))
                    {
                        message = message.Replace(Environment.NewLine, "<br/>");
                        message = message.Replace("\r", "<br/>");
                    }
                    mess.MessageHTML = message;
                    if (!String.IsNullOrEmpty(message))
                        mess.MessagePlain = _htmlRegex.Replace(message, " ");
                    mess.Topic = topic;
                    topic.Forum = topic.Forum;
                    mess.LastModified = DateTime.UtcNow;
                    topic.LastModified = DateTime.UtcNow;
                    dc.Entry(topic).Reference(c => c.LastPostByMember).Load();
                    topic.LastPostByMember = member;
                    topic.LastPostDateTime = DateTime.UtcNow;
                    topic.CreatedByMember = topic.CreatedByMember;
                    dc.ForumMessages.Add(mess);
                    int ch = dc.SaveChanges();

                    UpdateForumInbox(dc, topic, memberId);
                    string groupName = "Forum";
                    if (topic.Forum.LeagueOwner != null)
                        groupName = topic.Forum.LeagueOwner.Name;
                    if (topic.GroupId > 0)
                    {
                        try
                        {
                            var group = SiteCache.GetAllGroups().Where(x => x != null && x.Id == topic.GroupId).FirstOrDefault();
                            if (group != null)
                                groupName = group.GroupName;
                        }
                        catch (Exception exception)
                        {
                            ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: forumId + ":" + topicId + ":" + message + ":" + memberId + ":" + emailGroupAboutPost + ":" + topic.GroupId);
                        }
                    }
                    Guid ownerId = new Guid();
                    if (topic.Forum.LeagueOwner != null)
                        ownerId = topic.Forum.LeagueOwner.LeagueId;
                    var notify = new ForumNotificationFactory(forumId, ownerId, false, emailGroupAboutPost, topic.GroupId, topic.TopicId, groupName, topic.TopicTitle, message, member.MemberId, member.DerbyName)
                    .LeagueEmailAboutForumPost()
                    .EmailMembersOnWatchList();

                    var fact = new MobileNotificationFactory()
                           .Initialize("Forum Reply:", topic.TopicTitle, Mobile.Enums.NotificationTypeEnum.Forum)
                           .AddId(topic.TopicId)
                           .AddMembers(notify.membersAlreadyEmailed)
                           .SendNotifications();
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType(), additionalInformation: forumId + ":" + topicId + ":" + message + ":" + memberId + ":" + emailGroupAboutPost);
            }
        }