Example #1
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);
            }
        }
        public static bool MoveFolderToAnotherFolder(Guid ownerId, long folderId, long parentFolderId)
        {
            try
            {
                var dc = new ManagementContext();

                var docs = dc.LeagueDocumentFolders.Where(x => x.League.LeagueId == ownerId && x.CategoryId == folderId).FirstOrDefault();
                bool isMem = MemberCache.IsMemberApartOfLeague(RDN.Library.Classes.Account.User.GetMemberId(), docs.League.LeagueId);
                if (isMem)
                {
                    if (docs != null)
                    {
                        if (parentFolderId == 0 || parentFolderId == folderId)
                        {
                            dc.Entry(docs).Reference(x => x.ParentFolder).CurrentValue = null;
                            dc.Entry(docs).Reference(x => x.Group).CurrentValue = null;
                        }
                        else
                            docs.ParentFolder = dc.LeagueDocumentFolders.Where(x => x.CategoryId == parentFolderId).FirstOrDefault();
                        int c = dc.SaveChanges();

                        return c > 0;
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
Example #3
0
        public static bool UpdateTopicCategoryAndGroup(Guid forumId, long topicId, long groupId, long categoryId)
        {
            try
            {
                var dc = new ManagementContext();
                var topic = dc.ForumTopics.Include("Category").Where(x => x.Forum.ForumId == forumId && x.TopicId == topicId).FirstOrDefault();
                topic.LastPostByMember = topic.LastPostByMember;
                if (topic.CreatedByMember != null)
                    topic.CreatedByMember = topic.CreatedByMember;
                else
                    topic.CreatedByMember = topic.LastPostByMember;
                topic.Forum = topic.Forum;
                topic.GroupId = groupId;

                if (categoryId == 0)
                {
                    dc.Entry(topic).Reference(x => x.Category).CurrentValue = null;
                }
                else
                {
                    topic.Category = dc.ForumCetegories.Where(x => x.CategoryId == categoryId && x.Forum.ForumId == forumId).FirstOrDefault();
                    topic.Category.CreatedByMember = topic.Category.CreatedByMember;
                    topic.Category.Forum = topic.Category.Forum;
                    dc.Entry(topic.Category).State = System.Data.Entity.EntityState.Modified;
                }


                int c = dc.SaveChanges();
                return c > 0;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }
        public static bool MoveDocumentToGroup(Guid ownerId, long groupId, long docId)
        {
            try
            {
                Document doc = new Document();
                var dc = new ManagementContext();
                var docs = dc.LeagueDocuments.Where(x => x.League.LeagueId == ownerId && x.DocumentId == docId).FirstOrDefault();
                bool isMem = MemberCache.IsMemberApartOfLeague(RDN.Library.Classes.Account.User.GetMemberId(), docs.League.LeagueId);
                if (isMem)
                {
                    if (docs != null)
                    {
                        docs.Document = docs.Document;
                        docs.Group = dc.LeagueGroups.Where(x => x.Id == groupId).FirstOrDefault();
                        dc.Entry(docs).Reference(x => x.Category).CurrentValue = null;
                        int c = dc.SaveChanges();

                        return c > 0;
                    }
                }
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());
            }
            return false;
        }