Example #1
0
        public bool StartPoll(Poll p)
        {
            var pr = new PollRunner(_db, p);

            if (ActivePolls.TryAdd(p.GuildId, pr))
            {
                using (var uow = _db.GetDbContext())
                {
                    uow.Polls.Add(p);
                    uow.SaveChanges();
                }

                pr.OnVoted += Pr_OnVoted;
                return(true);
            }
            return(false);
        }
Example #2
0
        public bool StartPoll(Poll p)
        {
            var pr = new PollRunner(_db, p);

            if (ActivePolls.TryAdd(p.GuildId, pr))
            {
                using (var uow = _db.UnitOfWork)
                {
                    uow.Polls.Add(p);
                    uow.Complete();
                }

                pr.OnVoted += Pr_OnVoted;
                return(true);
            }
            return(false);
        }
Example #3
0
        public PollService(DbService db, IBotStrings strs)
        {
            _db   = db;
            _strs = strs;

            using (var uow = db.GetDbContext())
            {
                ActivePolls = uow.Polls.GetAllPolls()
                              .ToDictionary(x => x.GuildId, x =>
                {
                    var pr      = new PollRunner(db, x);
                    pr.OnVoted += Pr_OnVoted;
                    return(pr);
                })
                              .ToConcurrent();
            }
        }
Example #4
0
        public PollService(DiscordSocketClient client, NadekoStrings strings, DbService db,
                           NadekoStrings strs, IUnitOfWork uow)
        {
            _log     = LogManager.GetCurrentClassLogger();
            _client  = client;
            _strings = strings;
            _db      = db;
            _strs    = strs;

            ActivePolls = uow.Polls.GetAllPolls()
                          .ToDictionary(x => x.GuildId, x =>
            {
                var pr      = new PollRunner(db, x);
                pr.OnVoted += Pr_OnVoted;
                return(pr);
            })
                          .ToConcurrent();
        }