I have a mobile app that uses DNN which sends messages/journal posts on certain actions. Here is the code I use -
When I add a new game on the mobile app it posts the link to the Journal and sends a Notification to the game creator. This will have a link in it. It will also send an email to the user containing a link (using the PM Template)
private void ProcessNewGame(bool isEditGame, Game game)
{
string gameUrl = String.Format("http://www.pokerdiy.com/poker-game/home-poker/view/poker-game/{0}.aspx", game.GameId);
//From game Author
UserInfo gameHostUserInfo = UserController.GetUserById(PortalSettings.Current.PortalId, game.HostUserId);
//notifiy game host
string notificationGameSubject = String.Format(Localization.GetString("NewGameHostNotificationSubject", localResourceFile), game.Title);
StringBuilder notificationGameBody = new StringBuilder(String.Format(Localization.GetString("NewGameHostNotificationBody", localResourceFile), game.Summary, gameUrl));
Notifications.CreateJournalMentionNotification(notificationGameSubject, notificationGameBody.ToString(), gameHostUserInfo, new List { gameHostUserInfo });
if (!isEditGame)
{
//only do this for new games
Journal.CreateGameJournalPost(game, gameHostUserInfo, null, String.Format(Localization.GetString("NewGameJournalBody.Text", localResourceFile), gameUrl, game.City, game.Title, game.Summary), gameUrl);
}
}
public class Notifications
{
internal static void CreateJournalMentionNotification(string notificationSubject, string body, UserInfo fromUser, List<UserInfo> toUserList)
{
var notification = new Notification();
notification.NotificationTypeID = 15; //JournalMention
notification.Subject = notificationSubject;
notification.Body = body;
notification.IncludeDismissAction = true;
notification.SenderUserID = fromUser.UserID; //this is the person who it is listed as from
notification.Context = "";
NotificationsController.Instance.SendNotification(notification, Constants.PortalId, null, toUserList);
}
}
internal static void CreateGameJournalPost(Game game, UserInfo hostUser, string subject, string body, string gameUrl)
{
//http://www.dnnsoftware.com/wiki/page/journal
//https://github.com/DNN-Connect/kickstart/blob/master/Components/Integration/JournalController.vb
//https://github.com/DNN-Connect/DNN-Blog/blob/master/Components/Integration/JournalController.vb
//SELECT TOP 50 * FROM Journal ORDER BY JournalId Desc
var journalItem = new JournalItem();
journalItem.PortalId = Constants.PortalId;
journalItem.UserId = hostUser.UserID;
journalItem.ProfileId = hostUser.UserID;
journalItem.Title = subject;
journalItem.Summary = body;
journalItem.Body = null;
journalItem.ContentItemId = game.GameId;
journalItem.ItemData = new ItemData { Url = gameUrl };
journalItem.JournalTypeId = 1; //Status Update = 1 and new game ad, 18 is game comment
journalItem.ObjectKey = String.Format("Ventrian_Article_{0}:{1}", game.GameId, "-1");
journalItem.SecuritySet = "E";
JournalController.Instance.SaveJournalItem(journalItem, 1);
}