Exemplo n.º 1
0
        public void selectAccount()
        {
            Console.WriteLine("Choose account:");
            List <Account> list = AccountXmlLoader.pullAll();
            int            i    = 1;

            foreach (Account account in list)
            {
                Console.WriteLine($"{i++}: {account}");
            }
            int key = int.Parse(Console.ReadLine());

            try
            {
                if (key <= 0 || key > list.Count)
                {
                    throw new Exception("Wrong input");
                }
                if (list[key - 1] == null)
                {
                    throw new Exception("This account is not available");
                }
                currentAcc = list[key - 1];
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                Console.ReadKey();
            }
        }
Exemplo n.º 2
0
        public void create()
        {
            string   name;
            Currency cur;
            double   balance;
            bool     type;
            int      key;

            Console.WriteLine("Enter your name: ");
            name = Console.ReadLine();
            Console.WriteLine("Choose your currency:\n1:GRIVNA\n2:DOLLAR\n3:EURO");
            switch (int.Parse(Console.ReadLine()))
            {
            case 1: cur = Currency.GRIVNA;
                break;

            case 2: cur = Currency.DOLLAR;
                break;

            case 3: cur = Currency.EURO;
                break;

            default: cur = Currency.DOLLAR;
                break;
            }
            Console.WriteLine("Enter start balance(100$):");
            balance = double.Parse(Console.ReadLine());

            Console.WriteLine("What account you need:\n1:Default\n2:Overdraft");

            Console.WriteLine("Your base limit is 100");
            if (int.Parse(Console.ReadLine()) == 2)
            {
                currentAcc = new OverdraftAccount(name, cur, balance, 100);
            }
            else
            {
                currentAcc = new DefaultAccount(name, cur, balance);
            }
            if (!AccountXmlLoader.push(currentAcc))
            {
                currentAcc = null;
            }
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public bool showAll()
        {
            bool           emptyList = false;
            List <Account> list      = AccountXmlLoader.pullAll();

            if (list.Count <= 0)
            {
                emptyList = true;
                Console.WriteLine("Empty list");
            }
            int i = 1;

            foreach (Account account in list)
            {
                Console.WriteLine($"{i++}: {account}");
            }
            Console.ReadKey();
            return(emptyList);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
 public Transaction(string SenderID, double Sum, string purpose, string receiverId, Currency currency)
 {
     try {
         if (Sum <= 0)
         {
             throw new Exception("Invalid sum of transaction");
         }
         if (!AccountXmlLoader.checkIfExists(SenderID) || !AccountXmlLoader.checkIfExists(SenderID))
         {
             throw new Exception("Account not found");
         }
     } catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return;
     }
     this.SenderID   = SenderID;
     this.ReceiverID = receiverId;
     this.Sum        = Sum;
     this.purpose    = purpose;
     this.date       = DateTime.Now;
     this.currency   = currency;
 }
Exemplo n.º 7
0
 public static bool checkIfExists(string id)
 {
     return(AccountXmlLoader.pull(id) != null ? true : false);
 }
Exemplo n.º 8
0
        public void transact()
        {
            List <Account> list = AccountXmlLoader.pullAll();

            if (!getInfo())
            {
                return;
            }
            int i = 1;

            Console.WriteLine("\n\n");
            foreach (Account account in list)
            {
                Console.WriteLine($"{i++}: {account}");
            }
            if (list.Count <= 0)
            {
                Console.WriteLine("List is empty");
                return;
            }
            int key;

            Console.WriteLine("Set receiver");
            do
            {
                key = int.Parse(Console.ReadLine());
            } while (key > list.Count || key <= 0);

            Account receiver = list[key - 1];

            Console.WriteLine("Money: ");
            double money      = double.Parse(Console.ReadLine());
            string receiverId = receiver.AccountId;
            string senderId   = currentAcc.AccountId;

            Console.WriteLine("Enter purpose: ");
            string   purpose = Console.ReadLine();
            Currency cur;

            Console.WriteLine("Choose currency:\n1:GRIVNA\n2:DOLLAR\n3:EURO");
            switch (int.Parse(Console.ReadLine()))
            {
            case 1: cur = Currency.GRIVNA;
                break;

            case 2: cur = Currency.DOLLAR;
                break;

            case 3: cur = Currency.EURO;
                break;

            default: cur = Currency.DOLLAR;
                break;
            }

            if (currentAcc.GetType() == typeof(DefaultAccount))
            {
                (currentAcc as DefaultAccount).paymentslashtransaction(money, purpose, receiverId, cur);
            }
            if (currentAcc.GetType() == typeof(OverdraftAccount))
            {
                (currentAcc as OverdraftAccount).paymentslashtransaction(money, purpose, receiverId, cur);
            }
            Console.ReadKey();
        }