Esempio n. 1
0
        public ReturnModel CreateCollection(NewCollectionsObj obj)
        {
            Collections           col         = new Collections(obj.durationType, obj.name, obj.User, obj.resetDate);
            UserCollectionMapping mapping     = new UserCollectionMapping(col.CollectionsId, obj.User);
            ReturnModel           returnModel = new ReturnModel();

            if (mapping.Id == "999")
            {
                returnModel.result = false;
                return(returnModel);
            }
            try
            {
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    _context.Collections.Add(col);
                    _context.UserCollectionMapping.Add(mapping);
                    _context.SaveChanges();
                }
                returnModel.result    = true;
                returnModel.returnStr = col.CollectionsId;
                return(returnModel);
            }
            catch (Exception e)
            {
                returnModel.result = false;
                return(returnModel);
            }
        }
Esempio n. 2
0
        public ReturnModel AddAccount(Account account)
        {
            ReturnModel model = new ReturnModel();

            account.AccountIdentifier = "xxxx" + account.AccountIdentifier;
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                if (account.Id == null)
                {
                    account.Id = Guid.NewGuid().ToString();
                    _context.Account.Add(account);
                }
                else
                {
                    Account account1 = _context.Account.Find(account.Id);
                    account1.Update(account);
                    _context.Entry(account1).State = EntityState.Modified;
                }
                try
                {
                    _context.SaveChanges();
                    model.result = true;
                }
                catch (Exception e)
                {
                    model.result    = false;
                    model.returnStr = e.Message;
                    ExceptionCatcher catcher = new ExceptionCatcher();
                    catcher.Catch(e.Message);
                }
            }
            return(model);;
        }
Esempio n. 3
0
        /// <summary>
        /// Add user and collection to collection mapping table
        /// </summary>
        /// <param name="obj"> New Collection Object containing user eamil as obj.user and collectionsharing id as obj.name</param>
        /// <returns></returns>
        public bool AddUserToCollection(NewCollectionsObj obj)
        {
            // 3 checks
            // 1 - is count == 0
            CollectionSharing sharing = ShareCounter(obj.name);
            // 2 - is the user different from the other users-- already mapped into UserCollectionsMapping
            UserCollectionMapping mapping = new UserCollectionMapping(sharing.CollectionId, obj.User);

            if (sharing.count == 0 && mapping.CheckUser())
            {
                // set the counter to +1
                sharing.CountIncrament();
                try
                {
                    using (FinPlannerContext _context = new FinPlannerContext())
                    {
                        _context.Entry(sharing).State = EntityState.Modified;
                        _context.UserCollectionMapping.Add(mapping);
                        _context.SaveChanges();
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
 private void Save()
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.Add(this);
         _context.SaveChanges();
     }
 }
Esempio n. 5
0
 private void SavedCollection(CollectionSharing collectionSharing)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.CollectionSharing.Add(collectionSharing);
         _context.SaveChanges();
     }
 }
Esempio n. 6
0
 private void Save(ClickTracker tracker)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.ClickTracker.Add(tracker);
         _context.SaveChanges();
     }
 }
Esempio n. 7
0
        public async Task <bool> UpdateAccounts(string collectionsId, List <Account> accounts)
        {
            YodleeAccountModel        model          = new YodleeAccountModel();
            List <YodleeAccountLevel> yodleeAccounts = await model.GetYodleeAccounts(collectionsId);

            try
            {
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    foreach (Account item in accounts)
                    {
                        if (item.YodleeId == 0 && item.AccountIdentifier != null)
                        {
                            item.YodleeId = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).Select(x => x.id).FirstOrDefault();
                        }
                        else
                        {
                            YodleeAccountLevel accountLevel = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).FirstOrDefault();
                            if (accountLevel != null)
                            {
                                if (accountLevel.availableBalance != null)
                                {
                                    item.Available = accountLevel.availableBalance.amount;
                                }
                                else if (accountLevel.availableCredit != null)
                                {
                                    item.Available = accountLevel.availableCredit.amount;
                                }
                                else
                                {
                                    item.Available = accountLevel.balance.amount;
                                }
                            }
                        }
                        _context.Entry(item).State = EntityState.Modified;
                        AccountBalance balance = new AccountBalance()
                        {
                            AccountBalanceId = Guid.NewGuid().ToString(),
                            AccountId        = item.Id,
                            Amount           = item.Available,
                            Date             = DateTime.Now.Date
                        };
                        _context.Add(balance);
                    }

                    _context.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                ExceptionCatcher catcher = new ExceptionCatcher();
                catcher.Catch(e.Message);
                return(false);
            }
        }
Esempio n. 8
0
 public void BankCharges(Collections collection)
 {
     try
     {
         Budget budget = collection.Budgets.Where(x => x.Simulation == false).OrderByDescending(x => x.EndDate).First();
         double fees   = 0;
         foreach (Account acc in collection.Accounts.Where(x => x.AccountType.Transactional == true))
         {
             fees = fees + acc.MonthlyFee;
             double debt = acc.AccountLimit - acc.Available;
             if (debt > 0)
             {
                 fees = fees + debt * (acc.CreditRate / 12 / 100);
             }
         }
         fees = Math.Round(fees, 2);
         budget.GetBudgetTransacions();
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             if (budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).Any())
             {
                 BudgetTransaction transaction = budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).FirstOrDefault();
                 transaction.Amount = fees;
                 _context.Entry(transaction).State = EntityState.Modified;
             }
             else
             {
                 CFClassification  classification = new CFClassification("Expense");
                 CFType            type           = new CFType("Bank Charges");
                 BudgetTransaction transaction    = new BudgetTransaction()
                 {
                     BudgetId            = budget.BudgetId,
                     Automated           = true,
                     BudgetTransactionId = Guid.NewGuid().ToString(),
                     CFClassificationId  = classification.Id,
                     CFTypeId            = type.Id,
                     Name   = "Automated Bank Charges",
                     Amount = fees,
                 };
                 _context.Add(transaction);
             }
             _context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         ExceptionCatcher catcher = new ExceptionCatcher();
         catcher.Catch(e.Message);
     }
 }
        public void Catch(string e)
        {
            ExceptionCatcher catcher = new ExceptionCatcher()
            {
                Id        = Guid.NewGuid().ToString(),
                DateTime  = DateTime.Now,
                Exception = e
            };

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.ExceptionCatcher.Add(catcher);
                _context.SaveChanges();
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Add a custom CFType to the dataset
 /// </summary>
 /// <param name="collectionsId">Id of the collection creating the custom type</param>
 /// <param name="name">The custom name that is being provided</param>
 /// <returns>The new CFType that has been created</returns>
 public CFType CreateCFType(string collectionsId, string name)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         CFType type = new CFType();
         type.Id              = Guid.NewGuid().ToString();
         type.Custom          = true;
         type.Name            = name;
         type.Infaltion       = true;
         type.ClientReference = collectionsId;
         _context.CFTypes.Add(type);
         _context.SaveChanges();
         return(type);
     }
 }
Esempio n. 11
0
 public void Save()
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.EmailStore.Add(this);
         try
         {
             _context.SaveChanges();
         }
         catch (Exception e)
         {
             ExceptionCatcher catcher = new ExceptionCatcher();
             catcher.Catch(e.Message);
         }
     }
 }
Esempio n. 12
0
        public void SaveLog(DateTime start, DateTime end, string processName, bool result)
        {
            AutomatedLog log = new AutomatedLog()
            {
                Id          = Guid.NewGuid().ToString(),
                Start       = start,
                End         = end,
                ProcessName = processName,
                result      = result
            };

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.AutomatedLog.Add(log);
                _context.SaveChanges();
            }
        }
Esempio n. 13
0
 public void updateTransaction(string manId, string autoId)
 {
     try
     {
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             ManualCashFlow man = _context.ManualCashFlows.Find(manId);
             man.AutomatedCashFlowId   = autoId;
             _context.Entry(man).State = EntityState.Modified;
             _context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         ExceptionCatcher exceptionCatcher = new ExceptionCatcher();
         exceptionCatcher.Catch(e.Message);
     }
 }
Esempio n. 14
0
        public void AddAccountChange(ManualCashFlow flow)
        {
            AccountChange change = new AccountChange();

            change.AccountChangeId = Guid.NewGuid().ToString();
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                Account          account        = _context.Account.Find(flow.AccountId);
                CFClassification classification = _context.CFClassifications.Find(flow.CFClassificationId);
                change.UpdatedBalance         = Math.Round(account.Available + (flow.Amount * classification.Sign), 2);
                account.Available             = change.UpdatedBalance;
                change.DateAdded              = DateTime.Now;
                change.ManualCashFlowId       = flow.Id;
                _context.Entry(account).State = EntityState.Modified;
                _context.AccountChange.Add(change);
                _context.SaveChanges();
            }
        }
        public void Create(Account account, PaymentModel payment, AccountAmortisation amortisation)
        {
            DateTime end   = account.Maturity;
            DateTime start = DateTime.Now;

            start = new DateTime(start.Year, start.Month, end.Day);
            List <MonthlyAmortisation> monthlies = new List <MonthlyAmortisation>();
            double amount = account.Available;

            for (int i = 0; end.Date > start.AddMonths(i).Date; i++)
            {
                MonthlyAmortisation monthly = new MonthlyAmortisation
                {
                    MonthlyAmortisationId = Guid.NewGuid().ToString(),
                    AccountAmortisationId = amortisation.AccountAmortisationId,
                    Date = start.AddMonths(i),
                    Open = amount
                };
                monthly.Interest   = amount * (account.CreditRate / 12 / 100);
                monthly.Payment    = payment.CostOfLoan;
                monthly.Capital    = monthly.Payment - monthly.Interest;
                monthly.Additional = payment.AdditionalLoan;
                monthly.Close      = amount - monthly.Capital - monthly.Additional;
                monthlies.Add(monthly);
                amount = monthly.Close;
                if (amount < 0)
                {
                    break;
                }
            }
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.AddRange(monthlies);
                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    ExceptionCatcher catcher = new ExceptionCatcher();
                    catcher.Catch(e.Message);
                }
            }
        }
 public void Update(Account account)
 {
     if (isExists(account.Id))
     {
     }
     else
     {
         AccountAmortisation amortisation = new AccountAmortisation()
         {
             AccountId             = account.Id,
             AccountAmortisationId = Guid.NewGuid().ToString()
         };
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             _context.Add(amortisation);
             try
             {
                 _context.SaveChanges();
             }
             catch (Exception e)
             {
                 ExceptionCatcher catcher = new ExceptionCatcher();
                 catcher.Catch(e.Message);
             }
         }
         PaymentModel payment = new PaymentModel(account, amortisation.AccountAmortisationId);
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             _context.Add(payment);
             try
             {
                 _context.SaveChanges();
             }
             catch (Exception e)
             {
                 ExceptionCatcher catcher = new ExceptionCatcher();
                 catcher.Catch(e.Message);
             }
         }
         MonthlyAmortisation monthly = new MonthlyAmortisation();
         monthly.Create(account, payment, amortisation);
     }
 }
Esempio n. 17
0
 public bool Edit(NewBudgetObj obj)
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         Budget budget = _context.Budget.Find(obj.BudgetId);
         List <BudgetTransaction> transactions = _context.BudgetTransactions.Where(x => x.BudgetId == obj.BudgetId).ToList();
         //split the transactions into two lists Present/Updated and New
         List <BudgetTransaction> newList = new List <BudgetTransaction>();
         BudgetTransaction        b       = new BudgetTransaction();
         bool check = false;
         foreach (BudgetTransaction item in obj.BudgetTransactions)
         {
             check = false;
             foreach (BudgetTransaction ex in transactions)
             {
                 if (item.CFClassificationId == ex.CFClassificationId && item.CFTypeId == ex.CFTypeId)
                 {
                     check     = true;
                     ex.Amount = item.Amount;
                     _context.Entry(ex).State = EntityState.Modified;
                     break;
                 }
             }
             if (!check)
             {
                 newList.Add(item);
             }
         }
         newList = b.CreateBudgetTransactions(newList, obj.BudgetId, budget.CollectionId);
         _context.AddRange(newList);
         try
         {
             _context.SaveChanges();
             return(true);
         }
         catch (Exception e)
         {
             return(false);
         }
     }
 }
Esempio n. 18
0
 public YodleeModel(string collectionsId, string instruction)
 {
     if (instruction == "New")
     {
         Id            = Guid.NewGuid().ToString();
         loginName     = Guid.NewGuid().ToString("N");
         CollectionsId = collectionsId;
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             _context.YodleeModel.Add(this);
             _context.SaveChanges();
         }
     }
     if (instruction == "Get")
     {
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             YodleeModel getM = _context.YodleeModel.Where(x => x.CollectionsId == collectionsId).FirstOrDefault();
             loginName = getM.loginName;
         }
     }
 }
Esempio n. 19
0
        public ReturnModel Save()
        {
            ManualCashFlow flow        = new ManualCashFlow(this);
            ReturnModel    returnModel = new ReturnModel();

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.Add(flow);
                try
                {
                    _context.SaveChanges();
                    AccountChange change = new AccountChange();
                    change.AddAccountChange(flow);
                    returnModel.result = true;
                    return(returnModel);
                }
                catch (Exception e)
                {
                    returnModel.returnStr = e.Message;
                    returnModel.result    = false;
                    return(returnModel);
                }
            }
        }
Esempio n. 20
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
             });
         }
     }
 }
Esempio n. 21
0
        public void Duplicate(Collections collections)
        {
            Budget                   budget                = GetBudget(collections.CollectionsId);
            BudgetTransaction        budgetTransaction     = new BudgetTransaction();
            List <BudgetTransaction> budgetTransactions    = new List <BudgetTransaction>();
            List <BudgetTransaction> newBudgetTransactions = new List <BudgetTransaction>();

            budgetTransactions = budgetTransaction.GetBudgetTransactions(budget.BudgetId);
            DateTime endDate   = DateTime.MinValue;
            DateTime StartDate = DateTime.Now;

            switch (collections.DurationType)
            {
            case "Day":
                endDate = DateTime.Now.AddDays(1);
                break;

            case "Week":
                int dayofweek  = (int)StartDate.DayOfWeek;
                int difference = Math.Abs(dayofweek - collections.ResetDay);
                StartDate = StartDate.AddDays(-difference);
                endDate   = StartDate.AddDays(7);
                break;

            case "Month":
                int day = StartDate.Day;
                if (day == 0)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, 1).AddMonths(1);
                    StartDate = StartDate.AddDays(-1);
                }
                else if (day >= collections.ResetDay)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, collections.ResetDay);
                }
                else
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month - 1, collections.ResetDay);
                }
                if (collections.ResetDay == 28)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, 1).AddMonths(1);
                    StartDate = StartDate.AddDays(-1);
                }
                endDate = StartDate.AddMonths(1);
                break;
            }
            Budget newBudget = new Budget
            {
                BudgetId     = Guid.NewGuid().ToString(),
                CollectionId = collections.CollectionsId,
                StartDate    = StartDate,
                EndDate      = endDate
            };

            foreach (BudgetTransaction item in budgetTransactions)
            {
                newBudgetTransactions.Add(new BudgetTransaction
                {
                    Amount              = item.Amount,
                    UserId              = item.UserId,
                    BudgetId            = newBudget.BudgetId,
                    BudgetTransactionId = Guid.NewGuid().ToString(),
                    CFClassificationId  = item.CFClassificationId,
                    CFTypeId            = item.CFTypeId,
                    Name  = item.Name,
                    Notes = item.Notes
                });
            }
            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.Budget.Add(newBudget);
                _context.BudgetTransactions.AddRange(newBudgetTransactions);
                _context.SaveChanges();
            }
        }
Esempio n. 22
0
        public bool Create(NewBudgetObj obj)
        {
            string collectionId = obj.CollectionsId;
            //DateTime StartDate = obj.StartDate;
            List <BudgetTransaction> transactions = obj.BudgetTransactions;
            Collections col       = new Collections(collectionId);
            DateTime    EndDate   = new DateTime();
            DateTime    StartDate = DateTime.Now;

            switch (col.DurationType)
            {
            case "Day":
                EndDate = StartDate.AddDays(1);
                break;

            case "Week":
                int dayofweek  = (int)StartDate.DayOfWeek;
                int difference = Math.Abs(dayofweek - col.ResetDay);
                StartDate = StartDate.AddDays(-difference);
                EndDate   = StartDate.AddDays(7);
                break;

            case "Month":
                int day = StartDate.Day;
                if (day == 0)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, 1).AddMonths(1);
                    StartDate = StartDate.AddDays(-1);
                }
                else if (day >= col.ResetDay)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, col.ResetDay);
                }
                else
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month - 1, col.ResetDay);
                }
                if (col.ResetDay == 28)
                {
                    StartDate = new DateTime(StartDate.Year, StartDate.Month, 1).AddMonths(1);
                    StartDate = StartDate.AddDays(-1);
                }
                EndDate = StartDate.AddMonths(1);
                break;
            }
            if (DateCheck(collectionId, EndDate))
            {
                Budget                   budget = new Budget(collectionId, StartDate, EndDate, false);
                BudgetTransaction        t      = new BudgetTransaction();
                List <BudgetTransaction> list   = t.CreateBudgetTransactions(transactions, budget.BudgetId, budget.CollectionId);
                try
                {
                    using (FinPlannerContext _context = new FinPlannerContext())
                    {
                        _context.Budget.Add(budget);
                        foreach (BudgetTransaction item in list)
                        {
                            _context.BudgetTransactions.Add(item);
                        }
                        _context.SaveChanges();
                    }
                    return(true);
                }
                catch (Exception e)
                {
                    return(false);
                }
            }
            else
            {
                // Now we are simply adding transactions
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    Budget            budget            = _context.Budget.Where(x => x.CollectionId == collectionId && x.StartDate == StartDate).FirstOrDefault();
                    BudgetTransaction budgetTransaction = new BudgetTransaction();
                    try
                    {
                        List <BudgetTransaction> budgetTransactions = budgetTransaction.GetBudgetTransactions(budget.BudgetId);

                        foreach (BudgetTransaction item in transactions)
                        {
                            //does it exist?
                            bool exists = budgetTransactions
                                          .Where(x => x.BudgetTransactionId == item.BudgetTransactionId)
                                          .Any();
                            //does not exist
                            if (!exists)
                            {
                                _context.BudgetTransactions.Add(new BudgetTransaction(item, budget.BudgetId, budget.CollectionId));
                            }
                            //does exist
                            else
                            {
                                BudgetTransaction newT = _context
                                                         .BudgetTransactions
                                                         .Find(item.BudgetTransactionId);
                                double amount = budgetTransactions
                                                .Where(x => x.BudgetTransactionId == item.BudgetTransactionId)
                                                .Select(x => x.Amount)
                                                .FirstOrDefault();
                                string name = budgetTransactions
                                              .Where(x => x.BudgetTransactionId == item.BudgetTransactionId)
                                              .Select(x => x.Name)
                                              .FirstOrDefault();
                                string typeId = budgetTransactions
                                                .Where(x => x.BudgetTransactionId == item.BudgetTransactionId)
                                                .Select(x => x.CFTypeId)
                                                .FirstOrDefault();
                                //if amount is different
                                if (amount != item.Amount)
                                {
                                    newT.Amount = item.Amount;
                                }
                                //if name is different
                                if (name != item.Name)
                                {
                                    newT.Name = item.Name;
                                }
                                if (typeId != item.CFTypeId)
                                {
                                    newT.CFTypeId = item.CFTypeId;
                                }
                                if (amount != item.Amount || name != item.Name || typeId != item.CFClassificationId)
                                {
                                    _context.Entry(newT).State = EntityState.Modified;
                                }
                            }
                        }
                        //remove deleted items
                        foreach (BudgetTransaction item in budgetTransactions)
                        {
                            //is it in the list
                            bool check = transactions.Where(x => x.BudgetTransactionId == item.BudgetTransactionId).Any();
                            if (!check)
                            {
                                _context.BudgetTransactions.Remove(item);
                            }
                        }
                        _context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ExceptionCatcher catcher = new ExceptionCatcher();
                        catcher.Catch(e.Message);
                    }
                }
                return(false);
            }
        }
Esempio n. 23
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);
        }