public void EnsureAccount(AccountData account, PrivilegeConfig usage, int operation, int karma, string message, string ip) { if (account == null) { throw new InvalidOperationException("Account Not Found"); } if (!usage.IsSatisfied(account.PrivilegeLevelNavigation)) { throw new InvalidOperationException("Account Insufficient Privilege"); } if (account.PrivilegeLevel == GlobalConfig.ACCOUNT_BLOCKED_LEVEL) { throw new InvalidOperationException("Account Blacklisted"); } if (account.HasSuspended() && account.SuspendUntil >= _time.UtcNow) { throw new InvalidOperationException("Account Suspended"); } if (!account.PrivilegeLevelNavigation.IgnoreKarma && karma != 0) { var before = account.Karma; var after = account.Karma + karma; if (after < 0 && GlobalConfig.USER_ENABLE_KARMA) { throw new InvalidOperationException("Account Insufficient Karma"); } account.Karma = after; _context.AccountData.Update(account); _context.KarmaLog.Add(new KarmaLog { ReportTime = _time.UtcNow, AccountId = account.AccountId, Reason = operation, Before = before, After = after }); } _context.AccountLog.Add(new AccountLog { ReportTime = _time.UtcNow, AccountId = account.AccountId, Message = operation, Detail = message, IpAddress = ip }); _context.SaveChanges(); }