示例#1
0
        public ReturnModel UpdateAutomated(string manualcashflow)
        {
            CFType            type = new CFType();
            AutomatedCashFlow automatedCashFlow = getTransaction(this.ID);
            Account           account           = new Account(automatedCashFlow.AccountId);
            string            collectionsId     = account.CollectionsId;
            List <CFType>     types             = type.GetCFList(collectionsId);

            types.Add(new CFType {
                Id = "999"
            });
            if (manualcashflow != null)
            {
                ManualCashFlow mancf = new ManualCashFlow();
                mancf.updateTransaction(manualcashflow, this.ID);
            }
            if (!types.Any(x => x.Id == this.CFTypeId))
            {
                type = type.CreateCFType(collectionsId, this.CFTypeId);
                automatedCashFlow.CFTypeId = type.Id;
            }
            else
            {
                automatedCashFlow.CFTypeId = this.CFTypeId;;
            }
            automatedCashFlow.Validated       = this.Validated;
            automatedCashFlow.SourceOfExpense = this.SourceOfExpense;
            return(updateTransaction(automatedCashFlow));
        }
示例#2
0
 private ReportedTransaction(AutomatedCashFlow auto, List <CFType> types, List <CFClassification> classifications)
 {
     CFType           = types.Where(x => x.Id == auto.CFTypeId).FirstOrDefault();
     CFClassification = classifications.Where(x => x.Id == auto.CFClassificationId).FirstOrDefault();
     Amount           = auto.Amount;
     DateCaptured     = auto.DateCaptured;
     SourceOfExpense  = auto.SourceOfExpense;
     AccountId        = auto.AccountId;
     DateBooked       = auto.DateBooked;
     Validated        = auto.Validated;
 }
示例#3
0
        public AccountChange AddAccountChange(AutomatedCashFlow flow, Account account, int sign)
        {
            AccountChange change = new AccountChange();

            change.AccountChangeId     = Guid.NewGuid().ToString();
            change.UpdatedBalance      = Math.Round(account.Available + (flow.Amount * sign), 2);
            account.Available          = change.UpdatedBalance;
            change.Account             = account;
            change.DateAdded           = DateTime.Now;
            change.AutomatedCashFlowId = flow.ID;
            change.AccountId           = account.Id;
            return(change);
        }
示例#4
0
 private ReportedTransaction(AutomatedCashFlow auto, Account account)
 {
     CFType                     = new CFType(auto.CFTypeId);
     CFClassification           = new CFClassification(auto.CFClassificationId);
     Amount                     = auto.Amount;
     DateCaptured               = auto.DateCaptured;
     SourceOfExpense            = auto.SourceOfExpense;
     Account                    = account;
     Account.ManualCashFlows    = null;
     Account.AutomatedCashFlows = null;
     DateBooked                 = auto.DateBooked;
     Validated                  = auto.Validated;
 }
示例#5
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);
        }
示例#6
0
        public UnseenModel(string userId)
        {
            AspNetUsers users = new AspNetUsers();
            string      id    = users.getUserId(userId);

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                List <string> collections = _context
                                            .UserCollectionMapping
                                            .Where(x => x.Id == id)
                                            .Select(x => x.CollectionsId)
                                            .ToList();
                List <string> accountsStr = _context
                                            .Account
                                            .Where(Acc => collections.Contains(Acc.CollectionsId))
                                            .Select(x => x.Id)
                                            .ToList();
                Account account = new Account();
                Accounts = new List <Account>();
                foreach (string item in collections)
                {
                    Accounts
                    .AddRange(account.GetAccounts(item));
                }
                AutomatedCashFlow automatedCash  = new AutomatedCashFlow();
                ManualCashFlow    manualCash     = new ManualCashFlow();
                CFType            type           = new CFType();
                CFClassification  classification = new CFClassification();
                AutomatedCashFlows = automatedCash
                                     .GetAutomatedCashFlowsUnseen(accountsStr);
                ManualCashFlows = manualCash
                                  .GetManualCahFlowsUnseen(accountsStr);
                CFTypes = type
                          .GetCFList(collections)
                          .GroupBy(x => x.Id)
                          .Select(x => x.First())
                          .ToList();
                CFClassifications = classification
                                    .GetList();
            }
        }
示例#7
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);
        }
示例#8
0
 private ReturnModel updateTransaction(AutomatedCashFlow automatedCashFlow)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         try
         {
             _context.Entry(automatedCashFlow).State = EntityState.Modified;
             _context.SaveChanges();
             return(new ReturnModel()
             {
                 result = true
             });
         }
         catch (Exception e)
         {
             ExceptionCatcher catcher = new ExceptionCatcher();
             catcher.Catch(e.Message);
             return(new ReturnModel()
             {
                 result = false, returnStr = e.Message
             });
         }
     }
 }
示例#9
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);
        }