/// <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); }
/// <summary> /// Find notification by notificationId and change state isRead to true; /// </summary> /// <param name="notificationId">Current notification id</param> public void MarkAsRead(int notificationId) { NotificationService notificationService = new NotificationService(); if (notificationId == -1) { notificationId = notificationService.FindLastNotificationId(); } Notification notification = (Notification)notificationService.FindById(notificationId); if (notification != null) { notification.IsRead = true; notificationService.Edit(notification); } }