Exemplo n.º 1
0
        private async Task CreateNotificationForHoliday(string holidayName)
        {
            var admin = await userServices
                        .GetUsersInRole(Enum.GetName(typeof(Role), Role.Administrator))
                        .FirstOrDefaultAsync();

            NotificationCreateViewModel notification = new NotificationCreateViewModel
            {
                NotificationTypeId = (int)NotificationType.Holiday,
                NotificationText   = "Днес се празнува - " + holidayName
            };

            if (admin != null)
            {
                await notificationServices.CreateGlobalNotification(notification, admin.Id);
            }
            else
            {
                var agentIds = await dbContext.Users.OfType <AgentUsers>()
                               .Select(a => a.Id)
                               .ToListAsync();

                foreach (var agentId in agentIds)
                {
                    await notificationServices.CreateIndividualNotification(notification, agentId);
                }
            }
        }