protected void MessageDelete_Click(object sender, EventArgs e)
    {
        BusiBlocks.CommsBlock.Forums.Message  msg   = BusiBlocks.CommsBlock.Forums.ForumsManager.GetMessage(IdMessage);
        BusiBlocks.CommsBlock.Forums.Topic    topic = msg.Topic;
        BusiBlocks.CommsBlock.Forums.Category forum = topic.Category;

        if (!BusiBlocks.SecurityHelper.CanUserEdit(Page.User.Identity.Name, forum.Id))
        {
            throw new BusiBlocks.InvalidPermissionException("delete message");
        }

        //If there isn't a parent it is because it is the root message, in this case I delete directly the topic
        if (string.IsNullOrEmpty(msg.IdParentMessage))
        {
            BusiBlocks.CommsBlock.Forums.ForumsManager.DeleteTopic(topic);

            Navigation.Forum_ViewForum(forum.Name).Redirect(this);
        }
        else
        {
            BusiBlocks.CommsBlock.Forums.ForumsManager.DeleteMessage(msg);

            Navigation.Communication_ForumViewTopic(topic.Id).Redirect(this);
        }
    }
    private void LoadMessage(BusiBlocks.CommsBlock.Forums.Message msg)
    {
        linkNew.HRef    = "javascript:__doPostBack('reply','" + msg.Id + "')";
        linkDelete.HRef = "javascript:if(confirm('Are you sure to delete the message?')) __doPostBack('delete','" + msg.Id + "')";

        BusiBlocks.CommsBlock.Forums.Topic    topic = msg.Topic;
        BusiBlocks.CommsBlock.Forums.Category forum = topic.Category;


        if (!BusiBlocks.SecurityHelper.CanUserView(Page.User.Identity.Name, forum.Id))
        {
            throw new BusiBlocks.InvalidPermissionException("read message");
        }

        //if (!BusiBlocks.SecurityHelper.CanUserView(Page.User.Identity.Name, Profile.Locations, msg.Id))
        //    throw new BusiBlocks.InvalidGroupMembershipException();

        //Create a link (a element) that can be used for anchor (vertical navigation), note that I cannot use ASP.NET element because ASP.NET automatically change the ID adding the container id (containerid:controlid)
        string anchorId = "msg" + msg.Id; //Note: this is the format that you must use when you want to navigate to a message: es. ViewTopic.aspx?id=xxx#msgYYY

        messageTitle.InnerHtml = string.Format("<a id=\"{0}\">{1}</a>", anchorId, HttpUtility.HtmlEncode(msg.Title));


        lblAuthor.InnerText = Utilities.GetDisplayUser(msg.Owner);
        lblDate.InnerText   = Utilities.GetDateTimeForDisplay(msg.InsertDate);

        sectionBody.InnerHtml = msg.Body;

        bool visible = BusiBlocks.SecurityHelper.CanUserEdit(Page.User.Identity.Name, forum.Id);

        linkNew.Visible    = linkNew.Visible && ReplyLinkVisible;
        linkDelete.Visible = linkDelete.Visible && DeleteLinkVisible;


        //sectionDelete.Visible = (&& BusiBlocks.SecurityHelper.CanUserEdit(Page.User.Identity.Name, forum.Id));
        //sectionNew.Visible = (ReplyLinkVisible && BusiBlocks.SecurityHelper.CanUserEdit(Page.User.Identity.Name, forum.Id));

        if (msg.Attachment != null)
        {
            sectionAttachment.Visible = true;

            linkAttach.InnerHtml = HttpUtility.HtmlEncode(msg.Attachment.Name);
            linkAttach.HRef      = Navigation.Communication_ForumAttach(msg.Id, true).GetServerUrl(true);
        }
        else
        {
            sectionAttachment.Visible = false;
        }

        //Flag the control as loaded
        mMessageLoaded = true;
    }
    protected string GetLastPost(BusiBlocks.CommsBlock.Forums.Topic topic)
    {
        IList <BusiBlocks.CommsBlock.Forums.Message> messages = BusiBlocks.CommsBlock.Forums.ForumsManager.GetMessagesByTopic(topic);

        string status = "{1}<br />&nbsp;&nbsp;by {2}";

        DateTime lastReply = messages[messages.Count - 1].InsertDate;
        string   lastUser  = messages[messages.Count - 1].Owner;

        status = string.Format(status,
                               messages.Count,
                               Utilities.GetDateTimeForDisplay(lastReply),
                               Utilities.GetDisplayUser(lastUser));

        return(status);
    }
    private void ExploreMessages(BusiBlocks.CommsBlock.Forums.Category forum, BusiBlocks.CommsBlock.Forums.Topic topic,
                                 IList <BusiBlocks.CommsBlock.Forums.Message> messages, string filterParent, int level)
    {
        foreach (BusiBlocks.CommsBlock.Forums.Message msg in messages)
        {
            if (string.Equals(msg.IdParentMessage, filterParent, StringComparison.InvariantCultureIgnoreCase))
            {
                Communication_ViewMessage ctlMessage = (Communication_ViewMessage)LoadControl("~/Communication/Forum/ViewMessage.ascx");
                ctlMessage.SetMessage(msg);
                ctlMessage.SetIndentLevel(level);

                Controls.Add(ctlMessage);

                ExploreMessages(forum, topic, messages, msg.Id, level + 1);
            }
        }
    }
    private void LoadTopic(string IdTopic)
    {
        BusiBlocks.CommsBlock.Forums.Topic    topic = BusiBlocks.CommsBlock.Forums.ForumsManager.GetTopic(IdTopic);
        BusiBlocks.CommsBlock.Forums.Category forum = topic.Category;


        if (!BusiBlocks.SecurityHelper.CanUserView(Page.User.Identity.Name, topic.Category.Id))
        {
            throw new BusiBlocks.InvalidGroupMembershipException();
        }

        //if (!BusiBlocks.SecurityHelper.HasGroupAccess(Page.User.Identity.Name, topic))
        //    throw new BusiBlocks.InvalidGroupMembershipException();

        //if (BusiBlocks.SecurityHelper.CanRead(Page.User, forum, null) == false)
        //    throw new BusiBlocks.InvalidPermissionException("read forum");

        IList <BusiBlocks.CommsBlock.Forums.Message> messages = BusiBlocks.CommsBlock.Forums.ForumsManager.GetMessagesByTopic(topic);

        ExploreMessages(forum, topic, messages, null, 0);
    }
Exemple #6
0
    protected void btSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            BusiBlocks.CommsBlock.Forums.Topic    topic = GetParentMessage().Topic;
            BusiBlocks.CommsBlock.Forums.Category forum = topic.Category;

            var xhtml = new BusiBlocks.XHTMLText();
            xhtml.Load(newMessage.MessageBodyHtml);

            Exception validateError;
            if (xhtml.IsValid(forum.XHtmlMode, out validateError) == false)
            {
                throw new BusiBlocks.TextNotValidException(validateError);
            }

            BusiBlocks.Attachment.FileInfo attachment = null;
            //Create attachment
            if (newMessage.AttachmentFile.HasFile)
            {
                attachment = new BusiBlocks.Attachment.FileInfo(newMessage.AttachmentFile.FileName,
                                                                newMessage.AttachmentFile.PostedFile.ContentType,
                                                                newMessage.AttachmentFile.FileBytes);
            }

            //Insert the message
            BusiBlocks.CommsBlock.Forums.ForumsManager.CreateMessage(topic, IdParentMessage, Page.User.Identity.Name,
                                                                     newMessage.MessageSubject,
                                                                     xhtml.Xhtml,
                                                                     attachment);

            Navigation.Communication_ForumViewTopic(topic.Id).Redirect(this);
        }
        catch (Exception ex)
        {
            throw ex;
            ((IFeedback)Page.Master).SetException(GetType(), ex);
        }
    }
    private void NewMessage(string ParentId)
    {
        try
        {
            BusiBlocks.CommsBlock.Forums.Message  msg   = BusiBlocks.CommsBlock.Forums.ForumsManager.GetMessage(ParentId);
            BusiBlocks.CommsBlock.Forums.Topic    topic = msg.Topic;
            BusiBlocks.CommsBlock.Forums.Category forum = topic.Category;

            if (BusiBlocks.SecurityHelper.CanUserEdit(Page.User.Identity.Name, forum.Id))
            {
                Navigation.Communication_ForumNewMessage(ParentId).Redirect(this);
            }
            else
            {
                throw new BusiBlocks.InvalidPermissionException("insert new message");
            }
        }
        catch (Exception ex)
        {
            throw ex;
            ((IFeedback)Page.Master).SetException(GetType(), ex);
        }
    }
 protected string GetViewUrl(BusiBlocks.CommsBlock.Forums.Topic topic)
 {
     return(Navigation.Communication_ForumViewTopic(topic.Id).GetClientUrl(Page, true));
 }
 protected int GetRepliesCount(BusiBlocks.CommsBlock.Forums.Topic topic)
 {
     //Remove 1 because it is the topic message
     return(BusiBlocks.CommsBlock.Forums.ForumsManager.MessageCountByTopic(topic) - 1);
 }