Beispiel #1
0
        public async Task SendSchedule()
        {
            var day = DateTime.Now.DayOfWeek;

            if (day == DayOfWeek.Sunday || day == DayOfWeek.Saturday)
            {
                return;
            }

            var grouped = _db.GetScheduleUsers().GroupBy(x => x.Group);

            foreach (var group in grouped)
            {
                var schedule = _db.TimeTable.FirstOrDefault(x => x.Group == group.Key);

                if (schedule is null || string.IsNullOrWhiteSpace(schedule.Schedule))
                {
                    continue;
                }

                var ids = group.Select(x => x.Vk.Value).ToArray();

                await _vkApi.Messages.SendToUserIdsAsync(new MessagesSendParams
                {
                    RandomId = new DateTime().Millisecond + Guid.NewGuid().ToByteArray().Sum(x => x),
                    UserIds  = ids,
                    Message  = schedule.Schedule
                });
            }
        }