Exemple #1
0
        protected override async Task OnActivate(bool isFromReload)
        {
            using (var context = new UconomyDbContext(this))
            {
                await context.Database.MigrateAsync();
            }

            EventBus.AddEventListener(this, this);
        }
Exemple #2
0
        public async Task <decimal> GetBalanceAsync(IUser user)
        {
            using (var db = new UconomyDbContext(Plugin))
            {
                var account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == user.Id);

                return(account.Balance);
            }
        }
Exemple #3
0
        public async Task SetBalanceAsync(IUser owner, decimal amount)
        {
            using (var db = new UconomyDbContext(Plugin))
            {
                var account = await db.Accounts.FirstOrDefaultAsync(a => a.Id == owner.Id);

                account.Balance     = amount;
                account.LastUpdated = DateTime.Now;
                await db.SaveChangesAsync();
            }
        }
Exemple #4
0
        public async Task CreateAccountAsync(IUser user)
        {
            using (var db = new UconomyDbContext(Plugin))
            {
                if (!await db.Accounts.AnyAsync(a => a.Id == user.Id))
                {
                    var account = new Account(user.Id, Plugin.ConfigurationInstance.InitialBalance);
                    await db.Accounts.AddAsync(account);

                    await db.SaveChangesAsync();
                }
            }
        }