Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(Notification notification)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(nameof(Create)));
            }
            try
            {
                await _notify.AddNotification(notification.Message, notification.UserId);

                return(RedirectToAction(nameof(Index)));
            }
            catch
            {
                return(View(nameof(HomeController.Error)));
            }
        }