Exemplo n.º 1
0
        public void ProcessPurchase(Purchase p, Account a, IList <Transaction> tt)
        {
            Factory factory = Factory.GetInstance();



            IAccountSvc AccountSvc =
                (IAccountSvc)factory.GetService(typeof(IAccountSvc).Name);
            ITransactionSvc TransactionSvc =
                (ITransactionSvc)factory.GetService(typeof(ITransactionSvc).Name);

            TransactionSvc.ProcessTransaction(p, tt);



            var entry = from e in a.Entries
                        where e.Currency == p.Currency
                        select e;

            //Subtract cost
            if (entry.FirstOrDefault() != null)
            {
                entry.FirstOrDefault().Amount -= p.Cost;
            }

            //Display message if for some reason we don't have any of the currency
            else
            {
                Console.WriteLine("ERROR: CANNOT EXCHANGE CURRENCY: " + p.Currency);
            }

            AccountSvc.GenerateJSON(a);
        }
Exemplo n.º 2
0
        public void Clear()
        {
            Factory     factory    = Factory.GetInstance();
            IAccountSvc AccountSvc =
                (IAccountSvc)factory.GetService(typeof(IAccountSvc).Name);

            Account account = new Account();

            AccountSvc.GenerateJSON(account);
        }
Exemplo n.º 3
0
        public void ProcessExchange(Exchange d, Account a, IList <Transaction> tt)
        {
            Factory factory = Factory.GetInstance();



            IAccountSvc AccountSvc =
                (IAccountSvc)factory.GetService(typeof(IAccountSvc).Name);
            ITransactionSvc TransactionSvc =
                (ITransactionSvc)factory.GetService(typeof(ITransactionSvc).Name);

            TransactionSvc.ProcessTransaction(d, tt);



            var entry = from e in a.Entries
                        where e.Currency == d.OutCurr
                        select e;

            //Add to the currency if it's already there
            if (entry.FirstOrDefault() != null)
            {
                entry.FirstOrDefault().Amount += d.OutAmt;
            }
            //If the currency isn't there yet, we must add it
            else
            {
                CurrEntry c = new CurrEntry(d.OutAmt, d.OutCurr);
                a.AddCurrency(c);
            }

            var entry2 = from e2 in a.Entries
                         where e2.Currency == d.InCurr
                         select e2;

            if (entry2.FirstOrDefault() != null)
            {
                entry2.FirstOrDefault().Amount -= d.InAmt;
            }
            //Display message if for some reason we don't have any of the input currency
            else
            {
                Console.WriteLine("ERROR: CANNOT EXCHANGE CURRENCY: " + d.InCurr);
            }

            AccountSvc.GenerateJSON(a);
        }
Exemplo n.º 4
0
        public void ProcessDeposit(Deposit d, Account a, IList <Transaction> tt)
        {
            Factory     factory    = Factory.GetInstance();
            IAccountSvc AccountSvc =
                (IAccountSvc)factory.GetService(typeof(IAccountSvc).Name);


            ITransactionSvc TransactionSvc =
                (ITransactionSvc)factory.GetService(typeof(ITransactionSvc).Name);


            TransactionSvc.ProcessTransaction(d, tt);



            var entry = from e in a.Entries
                        where e.Currency == d.Currency
                        select e;

            //Add to the currency if it's already there
            if (entry.FirstOrDefault() != null)
            {
                entry.FirstOrDefault().Amount += d.Amt;
            }
            //If the currency isn't there yet, we must add it
            else
            {
                CurrEntry c = new CurrEntry(d.Amt, d.Currency);
                a.AddCurrency(c);
            }

            AccountSvc.GenerateJSON(a);
            Console.WriteLine();
            Console.WriteLine(d.ToString());
            Console.WriteLine();
        }