예제 #1
0
        public List <Account> GetAccountsWithCF(string collectionsId, int count)
        {
            CFClassification        classification  = new CFClassification();
            List <CFClassification> classifications = classification.GetList();
            List <Account>          accounts        = GetAccountsEmpty(collectionsId);
            Institution             institution     = new Institution();
            List <Institution>      institutions    = institution.GetInstitutions();
            AccountType             type            = new AccountType();
            List <AccountType>      types           = type.GetAccountTypes();
            ManualCashFlow          manual          = new ManualCashFlow();
            AutomatedCashFlow       automated       = new AutomatedCashFlow();
            Collections             collection      = new Collections();

            foreach (Account item in accounts)
            {
                item.Institution = institutions
                                   .Where(x => x.Id == item.InstitutionId)
                                   .FirstOrDefault();
                item.AccountType = types
                                   .Where(x => x.AccountTypeId == item.AccountTypeId)
                                   .FirstOrDefault();
                item.AccountType.Accounts = null;
                item.ManualCashFlows      = manual.GetManualCashFlows(item.Id, count);
                item.AutomatedCashFlows   = automated.GetAutomatedCashFlows(item.Id, count);
                foreach (ManualCashFlow flow in item.ManualCashFlows)
                {
                    flow.CFClassification = classifications.Where(x => x.Id == flow.CFClassificationId).FirstOrDefault();;
                    flow.CFClassification.ManualCashFlows = null;
                }
                foreach (AutomatedCashFlow flow in item.AutomatedCashFlows)
                {
                    flow.CFClassification = classifications.Where(x => x.Id == flow.CFClassificationId).FirstOrDefault();;
                    flow.CFClassification.ManualCashFlows = null;
                }
                item.Collections = collection.GetCollections(collectionsId);
                //foreach(ManualCashFlow flow in item.ManualCashFlows)
                //{
                //	flow.Account.ManualCashFlows = null;
                //}
            }
            return(accounts);
        }
예제 #2
0
        public List <ReportedTransaction> GetTransactions(string AccountId)
        {
            AutomatedCashFlow          automatedCashFlows   = new AutomatedCashFlow();
            ManualCashFlow             manualCashFlow       = new ManualCashFlow();
            List <ReportedTransaction> reportedTransactions = new List <ReportedTransaction>();
            List <AutomatedCashFlow>   auto = automatedCashFlows.GetAutomatedCashFlows(AccountId, 10000);
            Account account = new Account();

            account = account.GetAccount(AccountId, false);
            List <ManualCashFlow> manual = manualCashFlow.GetManualCashFlows(AccountId);

            manual = manual.Where(x => x.AutomatedCashFlowId == null).ToList();
            foreach (AutomatedCashFlow automated in auto)
            {
                reportedTransactions.Add(new ReportedTransaction(automated, account));
            }
            foreach (ManualCashFlow man in manual)
            {
                reportedTransactions.Add(new ReportedTransaction(man, account));
            }
            return(reportedTransactions);
        }
예제 #3
0
        public async Task <bool> UpdateTransactions()
        {
            //Invoke Classes
            CFClassification       classification    = new CFClassification();
            YodleeTransactionModel transactionModel  = new YodleeTransactionModel();
            Collections            collection        = new Collections();
            YodleeTransactionType  transactionType   = new YodleeTransactionType();
            ManualCashFlow         manualCash        = new ManualCashFlow();
            AutomatedCashFlow      automatedCashFlow = new AutomatedCashFlow();
            //Get Static Lists
            List <Collections>      collections     = collection.GetCollections("", "");
            List <CFClassification> classifications = classification.GetList();

            foreach (Collections item in collections.Where(x => x.Accounts.Any()))
            {
                AutomateReturnList returnList = new AutomateReturnList();
                returnList.automateReturns = new List <AutomateReturn>();
                if (item.Accounts.Where(x => x.AccountIdentifier != null).Any())
                {
                    YodleeModel yodlee = new YodleeModel();
                    string      token  = await yodlee.getToken(item.CollectionsId, "");

                    List <YodleeTransactionLevel> transactions = await transactionModel.GetYodleeTransactions(item.CollectionsId, token);

                    if (transactions != null)
                    {
                        DateTime smallest = transactions.Select(x => x.transactionDate).Min();
                        if (smallest > DateTime.MinValue)
                        {
                            smallest = smallest.AddDays(-3);
                        }
                        List <CFType> yodleeTypes = await transactionType.YodleeTransform(token, item.CollectionsId);

                        foreach (Account account in item.Accounts.Where(x => x.YodleeId != 0))
                        {
                            Account tempAccount = account;
                            List <ManualCashFlow> manualFlows = manualCash.GetManualCashFlows(account.Id);
                            foreach (ManualCashFlow m in manualFlows)
                            {
                                m.CFClassification = classifications.Where(x => x.Id == m.CFClassificationId).FirstOrDefault();
                            }
                            account.AutomatedCashFlows = automatedCashFlow.GetAutomatedCashFlows(account.Id, smallest, DateTime.Now.AddDays(1));
                            foreach (YodleeTransactionLevel transaction in transactions.Where(x => x.accountId == account.YodleeId))
                            {
                                if (!account.AutomatedCashFlows.Where(x => x.YodleeId == transaction.id).Any())
                                {
                                    ManualCashFlow manualCashFlow = manualFlows
                                                                    .Where(x => x.AutomatedCashFlowId == null)
                                                                    .Where(x => x.Amount == transaction.amount.amount && x.CFClassification.Name.ToLower() == transaction.categoryType.ToLower() && x.DateBooked > transaction.transactionDate.AddDays(-2) && x.DateBooked < transaction.transactionDate.AddDays(5))
                                                                    .FirstOrDefault();
                                    try
                                    {
                                        returnList.automateReturns.Add(AddTransaction(transaction, account.Id, yodleeTypes, manualCashFlow, classifications, tempAccount));
                                    }
                                    catch (Exception e)
                                    {
                                        ExceptionCatcher catcher = new ExceptionCatcher();
                                        catcher.Catch(e.Message + ";" + JsonConvert.SerializeObject(transaction) + ";" + JsonConvert.SerializeObject(manualCashFlow) + "");
                                    }
                                    if (manualCashFlow != null)
                                    {
                                        manualFlows.Remove(manualCashFlow);
                                    }
                                }
                            }
                            //item.Accounts.Where(x=>x.Id == account.Id).FirstOrDefault() = tempAccount;
                        }
                        try
                        {
                            List <AccountChange>     accChangeList   = new List <AccountChange>();
                            List <AutomatedCashFlow> cashFlows       = new List <AutomatedCashFlow>();
                            List <ManualCashFlow>    manualCashFlows = new List <ManualCashFlow>();
                            //ac
                            foreach (AutomateReturn returnItem in returnList.automateReturns)
                            {
                                if (returnItem.AccountChange.AccountChangeId != "")
                                {
                                    returnItem.AccountChange.Account           = null;
                                    returnItem.AccountChange.AutomatedCashFlow = null;
                                    accChangeList.Add(returnItem.AccountChange);
                                }
                                returnItem.AutomatedCashFlow.Account          = null;
                                returnItem.AutomatedCashFlow.CFClassification = null;
                                cashFlows.Add(returnItem.AutomatedCashFlow);
                                if (returnItem.ManualCashFlow.Id != "")
                                {
                                    manualCashFlows.Add(returnItem.ManualCashFlow);
                                }
                            }
                            using (FinPlannerContext _context = new FinPlannerContext())
                            {
                                _context.AccountChange.AddRange(accChangeList);
                                _context.AutomatedCashFlows.AddRange(cashFlows);
                                foreach (ManualCashFlow manual in manualCashFlows)
                                {
                                    _context.Entry(manual).State = EntityState.Modified;
                                }
                                _context.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            ExceptionCatcher catcher = new ExceptionCatcher();
                            catcher.Catch(e.Message);
                        }
                    }
                }
            }
            return(true);
        }