/// <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); }
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); }
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))); } }