Example #1
0
        private void InitGuideUpdate(string src)
        {
            lastGuideUpdateId = GetNewId(db.GuideUpdates);

            GuideUpdate new_gu = new GuideUpdate()
            {
                Id      = lastGuideUpdateId,
                Started = DateTime.Now,
                Source  = src
            };

            db.GuideUpdates.Add(new_gu);
            LogService.Log($"entry added");
            db.SaveChanges();
        }
Example #2
0
        public List <ProgrammeDTO> SendNotifications()
        {
            var users = db.Users.Include(u => u.Subscriptions);
            List <ProgrammeDTO> notificationsToSend = new List <ProgrammeDTO>();

            foreach (User user in users)
            {
                foreach (ProgrammeDTO notification in service.GetNotificationsFor(user.Login))
                {
                    string sending  = "sending";
                    string too_soon = "too soon";
                    LogService.Log($"{notification.Title} at {notification.Emissions.First().Start} - {(notification.Emissions.First().Start < DateTime.Now.AddMinutes(30) ? sending : too_soon)}");

                    if (notification.Emissions.First().Start < DateTime.Now.AddMinutes(30))
                    {
                        notificationsToSend.Add(notification);
                        var time_diff = notification.Emissions.First().Start - DateTime.Now;
                        if (time_diff > TimeSpan.Zero)
                        {
                            push.Notify(user,
                                        $"Twój program zaczyna się za {Math.Floor(time_diff.TotalMinutes)} minut",
                                        $"{notification.Title} na {notification.Emissions.First().Channel.Name}: {notification.Emissions.First().Start.TimeOfDay}"
                                        );
                        }
                        var notificationEntity = db.Notifications.First(not => not.EmissionId == notification.Emissions.First().Id&& not.UserLogin == user.Login);
                        db.Notifications.Remove(notificationEntity);
                    }
                }
            }
            db.SaveChanges();
            return(notificationsToSend);
        }