/// <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 in range when someone change holiday(send one message to n peole, in range),
 /// and with his username, change isReady to true.
 /// </summary>
 /// <param name="currentUsername">Username of user who clicked.</param>
 /// <param name="minNotificationId">min range notification.</param>
 /// <param name="maxNotificationId">max range notification.</param>
 public void MarkAsReadHolidayNotifications(string currentUsername, int minNotificationId, int maxNotificationId)
 {
     NotificationService notificationService = new NotificationService();
     Notification notification = (Notification)notificationService.FindCurrentUserNotificationInRange(currentUsername, minNotificationId, maxNotificationId);
     if (notification != null)
     {
         notification.IsRead = true;
         notificationService.Edit(notification);
     }
 }
        /// <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);
            }
        }
 /// <summary>
 /// Initialization method to fill all notification for user.
 /// </summary>
 public void SendNotification()
 {
     NotificationService notificationService = new NotificationService();
     notificationService.FixNotificationSpam();
     List<NotificationModel> previousNotification = notificationService.AllUnreadNotification();
     Clients.All.loadNotificationList(previousNotification);
 }
Example #5
0
        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);
        }