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