118 lines
4.2 KiB
C#
118 lines
4.2 KiB
C#
using EnVisage.Code.Hubs.Notifications;
|
|
using EnVisage.Models;
|
|
using Microsoft.AspNet.SignalR;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Web;
|
|
using System.Web.Script.Serialization;
|
|
|
|
namespace EnVisage.Code.Hubs.Notifications
|
|
{
|
|
public class NotificationRouter
|
|
{
|
|
private enum Route{
|
|
Send=1,
|
|
Remove=2
|
|
}
|
|
public static void removeNotification(NotificationModel notification)
|
|
{
|
|
if (notification.Actions == null)
|
|
return;
|
|
foreach (NotificationControlModel ncm in notification.Actions)
|
|
{
|
|
switch (ncm.HowToSend)
|
|
{
|
|
case NotificationHowToSend.Email:
|
|
//remove notification email here
|
|
break;
|
|
case NotificationHowToSend.Text:
|
|
//remove text here
|
|
break;
|
|
case NotificationHowToSend.Web:
|
|
processClientNotification(notification, Route.Remove);
|
|
break;
|
|
default:
|
|
//remove client update as default
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
public static void sentNotification(NotificationModel notification)
|
|
{
|
|
foreach (NotificationControlModel ncm in notification.Actions) {
|
|
switch (ncm.HowToSend)
|
|
{
|
|
case NotificationHowToSend.Email:
|
|
string emailAddress = getUserEmail(notification.ParentId);
|
|
if (emailAddress != null)
|
|
MailManager.SendMessage(notification.title, emailAddress, notification.description);
|
|
break;
|
|
case NotificationHowToSend.Text:
|
|
//send text here
|
|
break;
|
|
case NotificationHowToSend.Web:
|
|
processClientNotification(notification,Route.Send);
|
|
break;
|
|
default:
|
|
//send client update as default
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
private static string getUserEmail(Guid UserID)
|
|
{
|
|
var DbContext = new EnVisageEntities();
|
|
AspNetUser User=DbContext.AspNetUsers.Find(UserID.ToString());
|
|
if (User != null)
|
|
return User.Email;
|
|
return null;
|
|
}
|
|
private static void processClientNotification(NotificationModel notification, Route task)
|
|
{
|
|
switch (notification.type)
|
|
{
|
|
case NotificationType.Task:
|
|
if (task == Route.Remove)
|
|
{
|
|
ClientNotificationHub h = new ClientNotificationHub();
|
|
h.TaskFinished(notification.Id, notification);
|
|
|
|
}
|
|
else
|
|
{
|
|
ClientNotificationHub h = new ClientNotificationHub();
|
|
h.TaskStarted(notification.Id, notification);
|
|
|
|
}
|
|
break;
|
|
case NotificationType.System:
|
|
//send client notification for system
|
|
break;
|
|
case NotificationType.User:
|
|
if (task == Route.Remove)
|
|
{
|
|
ClientNotificationHub h = new ClientNotificationHub();
|
|
h.TaskFinished(notification.Id, notification);
|
|
|
|
}
|
|
else
|
|
{
|
|
ClientNotificationHub h = new ClientNotificationHub();
|
|
h.TaskStarted(notification.Id, notification);
|
|
|
|
}
|
|
break;
|
|
case NotificationType.Workflow:
|
|
//send client notification for workflow
|
|
break;
|
|
default:
|
|
//send client update as default
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|