コード例 #1
0
        public void UnSubscribe(long chatId)
        {
            var found = _repository.Find(p => p.ChatId == chatId).LastOrDefault();

            if (found == null)
            {
                var settings = new TelegramSetting {
                    ChatId = chatId, Subscribe = false, DateCreated = DateTime.Now
                };
                _repository.Add(settings);
            }
            else
            {
                found.Subscribe   = false;
                found.DateUpdated = DateTime.Now;
                _repository.Update(found);
            }
        }
コード例 #2
0
        public void Subscribe(long chatId)
        {
            var found = _repository.Find(p => p.ChatId == chatId).ToList();

            if (!found.Any())
            {
                var settings = new TelegramSetting {
                    ChatId = chatId, Subscribe = true, DateCreated = DateTime.Now
                };
                _repository.Add(settings);
            }
            else
            {
                var settings = found.LastOrDefault();
                settings.Subscribe   = true;
                settings.DateUpdated = DateTime.Now;
                _repository.Update(settings);
            }
        }
コード例 #3
0
        static TelegramService ConnectToTelegram(TelegramSetting setting)
        {
            TelegramService telegram;

            try
            {
                telegram = new Services.TelegramService(setting);
            }
            catch
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Could not connect to telegram, please check your network connection or your VPN...");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Trying again in 10 second...");
                Thread.Sleep(TimeSpan.FromSeconds(10));
                return(ConnectToTelegram(setting));
            }


            return(telegram);
        }
コード例 #4
0
 public BasesViewModel(WorkplaceContext db)
 {
     Bases           = db.GetBasesLocal();
     this.db         = db;
     TelegramSetting = db.TelegramSetting;
 }