コード例 #1
0
ファイル: EntityUser.cs プロジェクト: Soverclysm/Exurb1aBot
        public void AddAmount(CurrencyEnum cur, double amount)
        {
            var curr = Currencies?.FirstOrDefault(c => c.Currency == cur);

            if (curr == null)
            {
                if (Currencies == null)
                {
                    Currencies = new List <CurrencyUser>();
                }

                curr = new CurrencyUser(this, amount, cur);
                Currencies.Add(curr);
            }
            else
            {
                curr.Amount = curr.Amount += amount;
            }
        }
コード例 #2
0
ファイル: EntityUser.cs プロジェクト: Soverclysm/Exurb1aBot
        public void RemoveAmount(CurrencyEnum cur, double amount)
        {
            var curr = Currencies?.FirstOrDefault(c => c.Currency == cur);

            if (curr == null)
            {
                if (Currencies == null)
                {
                    Currencies = new List <CurrencyUser>();
                }

                curr = new CurrencyUser(this, 0, cur);
                RemoveAmount(cur, amount);
            }

            if (curr.Amount < amount)
            {
                throw new WouldMakeCurrencyNegative();
            }

            curr.Amount = curr.Amount -= amount;
        }