Пример #1
0
        public void SendNotifications(IEnumerable <Notification> notifications)
        {
            // check if chat id exists
            // get all students

            var studentIds   = notifications.Select(s => s.StudentId).ToList();
            var telegramData = _repository.GetUserTelegramData(studentIds).ToList();

            if (telegramData.Count == 0)
            {
                // No students data is in table
                return;
            }
            foreach (var notification in notifications)
            {
                var studentId = notification.StudentId;
                var first     = telegramData.FirstOrDefault(s => s.StudentId == studentId);
                if (first == null)
                {
                    // it happens, when can`t find user data
                    _logger.LogError($"{notification.StudentId} don`t have telegram info, but uses telegram notification");
                    continue;
                }

                var chatId = first.TelegramChatId;
                if (chatId == null)
                {
                    // chat Id not exists
                    _logger.LogWarning($"User {studentId} not have chatId");
                }
                NotificationsAction.Send(notification, chatId.Value);
            }
        }