예제 #1
0
        /// <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>
        ///Show all registered users.
        ///</summary>
        public ActionResult ShowAllUsers(int? page)
        {
            UsersService users = new UsersService();
            List<User> model = users.FindAll().ToList();
            List<User> withoutAdmin = new List<User>();

            foreach (User user in model)
            {
                if (!user.IsUserAdmin)
                {
                    withoutAdmin.Add(user);
                }
            }
            int? currentPage = ReturnPaginationPage(withoutAdmin, page);
            return View("ShowAllUsers", withoutAdmin.ToList().ToPagedList(currentPage ?? 1, 6));
        }
        ///<summary>
        ///Show only approved registered users.
        ///</summary>
        public ActionResult showRegOnly()
        {
            UsersService users = new UsersService();
            List<User> model = users.FindAll().ToList();
            List<User> withoutAdmin = new List<User>();

            foreach (User user in model)
            {
                if (!user.IsUserAdmin && user.IsUserRegistered)
                {
                    withoutAdmin.Add(user);
                }
            }

            return View(withoutAdmin);
        }
        /// <summary>
        /// Reset all vacation days for registered users to 20.
        /// </summary>
        public ActionResult ResetVacationDays()
        {
            UsersService userService = new UsersService();
            List<User> users = userService.FindAll();

            foreach (User user in users)
            {
                user.VacationDays = 20;
                userService.Edit(user);
            }

            return RedirectToAction("ShowAllUsers");
        }