Example #1
0
        /// <summary>
        /// Sends the user notification.
        /// </summary>
        /// <param name="who">The username of recipient (user's email).</param>
        /// <param name="title">The title of the notification.</param>
        /// <param name="message">The message.</param>
        /// <param name="url">The URL (if any).</param>
        /// <param name="linkText">The link text (if any url).</param>
        /// <param name="type">The notification type.</param>
        public static void SendUserNotification(string who, string title,
                                                string message, string url = null, string linkText = null, NotificationType type = NotificationType.Info)
        {
            if (string.IsNullOrEmpty(who))
            {
                return;
            }
            if (string.IsNullOrEmpty(message))
            {
                return;
            }

            var notifyRepo = new NotificationsRepository();

            var notification = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = string.IsNullOrEmpty(title) ? string.Empty : title,
                Message    = message,
                Url        = string.IsNullOrEmpty(url) ? string.Empty : url,
                LinkText   = string.IsNullOrEmpty(linkText) ? string.Empty : linkText,
                NotifyType = type
            };

            notifyRepo.AddNotification(notification);
        }
Example #2
0
        public static void AddSentNotification(string who, string title, string message)
        {
            if (string.IsNullOrEmpty(who))
            {
                return;
            }

            var notifyRepo   = new NotificationsRepository(sentNotifications: true);
            var notification = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title   = string.IsNullOrEmpty(title) ? string.Empty : title,
                Message = message,
            };

            notifyRepo.AddNotification(notification);
        }
        /// <summary>
        /// Adds dummy notifications for testing.
        /// </summary>
        /// <param name="who">The who.</param>
        public static bool AddDummyNotifications(string who)
        {
            var repository = new NotificationsRepository();

            if (!repository.Init())
            {
                return(false);
            }

            var dummyNotifications = new List <NotificationModel>();
            var notification1      = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Lorem ipsum dolor",
                Message    = "Duis aute irure dolor in reprehenderit in voluptate",
                NotifyType = NotificationType.Warning
            };

            var notification2 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title   = "Excepteur sint occaecat",
                Message = "Excepteur sint occaecat cupidatat non proident," +
                          "sunt in culpa qui officia deserunt mollit",
                NotifyType = NotificationType.Warning
            };

            var notification3 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Mauris ipsum arcu",
                Message    = "Mauris ipsum arcu, feugiat non tempor tincidunt sit amet turpis",
                Url        = "/Home/Contact",
                LinkText   = "ipsum arcu!",
                NotifyType = NotificationType.Info
            };

            var notification4 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Ut a diam magna",
                Message    = "Nulla convallis, orci in sodales blandit",
                NotifyType = NotificationType.Success
            };

            var notification5 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title   = "lorem augue feugiat",
                Message = "vitae dapibus mi ligula quis ligula." +
                          "Aenean mattis pulvinar est quis bibendum.",
                NotifyType = NotificationType.Success
            };

            var notification6 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Donec posuere pulvinar",
                Message    = "nec sagittis lacus pharetra ac",
                NotifyType = NotificationType.Failure
            };

            var notification7 = new NotificationModel(who, Guid.NewGuid().ToString())
            {
                Title      = "Pellentesque et magna",
                Message    = "Donec velit vulputate nec tristique vitae",
                NotifyType = NotificationType.Info
            };

            dummyNotifications.Add(notification1);
            dummyNotifications.Add(notification2);
            dummyNotifications.Add(notification3);
            dummyNotifications.Add(notification4);
            dummyNotifications.Add(notification5);
            dummyNotifications.Add(notification6);
            dummyNotifications.Add(notification7);


            foreach (var notification in dummyNotifications)
            {
                repository.AddNotification(notification);
            }

            return(true);
            //var notifications = repository.GetNotificationsByUserId(who);
        }