/// <summary>Set the total balance attributed to the fund 'fund_id'</summary> public void AssignFundBalance(Fund fund, Unit <decimal> total, bool notify = true) { // Notes: // - Don't throw if the nett total becomes negative, that probably just means a fund // has been assigned too much. Allow the user to reduce the allocations. // Get the balance info for 'fund_id', create if necessary var balance = (Balance)Funds.FirstOrDefault(x => x.Fund == fund) ?? m_funds.Add2(new Balance(this, fund)); balance.Total = total; // The main fund changes with each update. Other funds don't. // Notify *after* 'LastUpdated' and 'CheckHolds' have been set if (notify) { Invalidate(); } }
/// <summary>Add or subtract an amount from a fund</summary> public void ChangeFundBalance(Fund fund, Unit <decimal> change_amount, bool notify = true) { // Get the balance info for 'fund_id', create if necessary var balance = (Balance)Funds.FirstOrDefault(x => x.Fund == fund); // ?? m_funds.Add2(new Balance(this, fund)); if (balance == null) { return; } // Apply the balance change to the total balance.Total += change_amount; // Changing the total for a fund effects the balance of the main fund. if (notify) { Invalidate(); } }
/// <summary>Access balances associated with the given fund. Unknown fund ids return an empty balance</summary> public IBalance this[Fund fund] => Funds.FirstOrDefault(x => x.Fund == fund) ?? new Balance(this, fund);