Ejemplo n.º 1
0
        public virtual void paymentslashtransaction(double money, string purpose, string receiverId, Currency currency = Currency.DOLLAR)
        {
            double      defaultBalance = this.Balance * (double)CurrencyProcessor.convertCoeficient(this.currency);
            double      defaultMoney   = money * (double)CurrencyProcessor.convertCoeficient(currency);
            Transaction transaction;

            try
            {
                //default currency is DOLLAR
                if (defaultBalance < defaultMoney)
                {
                    throw new Exception("Your balance has not money for this transaction");
                }


                transaction = new Transaction(this.AccountId, money, purpose, receiverId, currency);
                this.bt    += transaction.transact;
                if (!bt.Invoke())
                {
                    throw new Exception("Something went wrong");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
            if (this.currency == currency)
            {
                this.Balance -= money;
            }
            else
            {
                this.Balance -= defaultMoney / (double)CurrencyProcessor.convertCoeficient(this.currency);
            }
            transaction.Verified = true;

            this.journal.Add(transaction);

            AccountXmlLoader.update(this);
        }
Ejemplo n.º 2
0
        public bool transact()
        {
            try
            {
                if (!AccountXmlLoader.checkIfExists(this.ReceiverID))
                {
                    throw new Exception("Receiver not found");
                }

                Account sender   = AccountXmlLoader.pull(this.SenderID);
                Account receiver = AccountXmlLoader.pull(this.ReceiverID);


                //no commision
                if (receiver.currency == this.currency)
                {
                    receiver.Balance += this.Sum;
                }
                else
                {
                    double defaultvalue          = this.Sum * (double)CurrencyProcessor.convertCoeficient(this.currency);
                    double receiverCurrencyValue =
                        defaultvalue / (double)CurrencyProcessor.convertCoeficient(receiver.currency);
                    receiver.Balance += receiverCurrencyValue;
                }
                AccountXmlLoader.update(receiver);
                this.Verified = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                this.Verified = false;
            }
            finally
            {
                TransactionXmlLoader.push(this);
            }
            return(this.Verified);
        }