MonoX support board

Start the conversation, ask questions and share tips and solutions with fellow developers.

Non-registered users can only browse through our support boards. Please register now if you want to post your questions. It takes a second and it is completely free. Alternatively, you can log in without registration using your credentials at major sites such as Google, Microsoft Live, OpenId, Facebook, LinkedIn or Yahoo.

Programmatically add post to Discussion Board (Zatvorena) (Mono Support )

25885 put(a) pogledan, 4 odgovor(a) 4.10.2011. 15:44:35Kreirao(la) Maxim
Maxim

Maxim

4.10.2011. 15:53:14
Hi! How to programmatically add post to Discussion Board, and some comments to post...
Ovaj sadržaj još nije ocijenjen. 
319 Reputacija 30 Ukupno objava
khorvat

khorvat

5.10.2011. 6:39:53
Hi,

I suppose you meant " How to programmatically add topic to Discussion Board, and some comments to topic..." ? Below is the sample code that you can modify and create a Discussion topic and then discussion message entity.

Create a DiscussionTopicEntity
SnDiscussionTopicEntity entity = DiscussionRepository.GetInstance().EnsureTopicExists(BoardId, TopicId, UserId, title, maxTags)

Few notes:
1. You need to get the BoardId where you want to create a Topic
2. Pass in the id of the Topic as an Guid to get the proper PK
3. UserId parameter specifies the owner / creator of the Topic - you can use SecurityUtility.GetUserId() if you want to pass in the current user id

Create a DiscussionMessageEntity (Post)
SnDiscussionMessageEntity entity = DiscussionRepository.GetInstance().PostMessage(MessageId, TopicId, UserId, message);

Few notes:
1. You need to get the TopicId of the previously created topic you can do that by using the topic entity property Id
2. Pass in the id of the Message as an Guid to get the proper PK
3. UserId parameter specifies the owner / creator of the Message - you can use SecurityUtility.GetUserId() if you want to pass in the current user id

If you want to implement AntiXSS or SPAM security while posting a message you can use the following code

To implement AntiXSS security on the message html content use
HtmlFormatter.SanitizeHtml(messageContent, false)
To implement AntiXSS security on the message plain text content use
HtmlFormatter.SanitizeHtml(messageContent, true)

To implement SPAM check you can use the following
using (DiscussionRepository discussionRepository = DiscussionRepository.GetInstance())
{
    ...
    if (Message != null)
    {
        if (!IsDiscussionEditableByUser(BoardId) && this.ApprovalMode != CommentApprovalMode.None)
        {
            if (this.ApprovalMode == CommentApprovalMode.Manual)
                Message.IsApproved = false;
            else
                Message.IsApproved = true;
            MonoXSpamContentValidator validator = new MonoXSpamContentValidator();
            try
            {
                validator.ValidateComment(Message);                       
            }
            catch
            {
                Message.IsSpam = false;
                Message.IsApproved = true;                           
            }                       
        }
        else
        {
            Message.IsSpam = false;
            Message.IsApproved = true;
        }
        discussionRepository.SaveEntity(Message, true);
    }
    ...
}

I hope I have covered everything you need, let us know if you need anything else.

Regards
Ocjena 5,00, 2 glas(ova). 
15993 Reputacija 2214 Ukupno objava
Maxim

Maxim

5.10.2011. 6:58:55
Thank you,all works!
Ovaj sadržaj još nije ocijenjen. 
319 Reputacija 30 Ukupno objava
khorvat

khorvat

5.10.2011. 7:09:33
Great to hear it, I'm closing this topic.

Regards
Ovaj sadržaj još nije ocijenjen. 
15993 Reputacija 2214 Ukupno objava