/// <summary> /// Send notification to all online users when admin change/edit/delete holiday. /// </summary> /// <param name="type">add, edit, delete</param> /// <param name="message">Holiday description.</param> /// <param name="sender">Who change/edit/delete holiday.</param> public void SendNotification(string type, string message, string sender) { NotificationService notificationService = new NotificationService(); UsersService userService = new UsersService(); User createdBy = (User)userService.FindUserByUsername(sender); int userCount = 0; foreach (User user in userService.FindAll()) { if (!user.IsUserAdmin && user.IsUserRegistered) { Notification notification = new Notification(); notification.CreatedBy = createdBy.UserId; notification.DateCreated = DateTime.Now; notification.IsRead = false; notification.SentTo = user.UserId; notification.Description = ChoseDescription(type, message, sender); notificationService.Create(notification); userCount++; } } int maxNotificationId = notificationService.FindLastNotificationId(); int minNotificationId = maxNotificationId - userCount; Clients.All.broadcastNotification(type, message, minNotificationId, maxNotificationId); }
public object FindById(int notificationId) { Notification notification = new Notification(); notification = context.Notifications.Find(notificationId); return notification; }
public void SendMessageNotification(string name, string message, string recipientName) { NotificationService notificationService = new NotificationService(); UsersService userService = new UsersService(); User createdBy = (User)userService.FindUserByUsername(name); User sentTo = (User)userService.FindUserByUsername(recipientName); Notification notification = new Notification(); notification.DateCreated = DateTime.Now; notification.CreatedBy = createdBy.UserId; notification.Description = "New message from " + name; notification.IsRead = false; notification.SentTo = sentTo.UserId; notificationService.Create(notification); int notificationId = notification.NotificationId; Clients.User(recipientName).broadcastNotification(name, message, recipientName, notificationId); }