public async Task <bool> UpdateYodlee()
        {
            Collections        collection  = new Collections();
            YodleeModel        yodlee      = new YodleeModel();
            List <Collections> collections = collection.GetCollections("", "");
            bool result = true;

            foreach (string id in collections.Where(x => x.Accounts.Count() > 0).Select(x => x.CollectionsId))
            //foreach(string id in collections.Where(x=>x.CollectionsId == "f687f366-d162-4a04-89c7-8e0ad123f9cf").Select(x=>x.CollectionsId))
            {
                if (!result)
                {
                    return(result);
                }
                string token = await yodlee.getToken(id, "");

                List <string> providers = await GetProviders(token);

                foreach (string provider in providers.Distinct())
                {
                    HttpClient client = new HttpClient();
                    client.DefaultRequestHeaders.Add("Api-Version", "1.1");
                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    HttpResponseMessage response = await client.PutAsync(url + "/providerAccounts?providerAccountIds=" + provider, new StringContent(""));

                    if (!response.IsSuccessStatusCode)
                    {
                        result = false;
                        break;
                    }
                }
            }
            return(result);
        }
Пример #2
0
        private async Task <ReturnModel> Register(string userId, string collectionsId)
        {
            YodleeAuthReturn auth = await GetAdminAuth();

            ReturnModel returnModel = new ReturnModel();

            if (auth.token.accessToken != null)
            {
                YodleeModel yodleeModel = new YodleeModel();
                if (!Check(collectionsId))
                {
                    yodleeModel = new YodleeModel(collectionsId, "New");
                }
                else
                {
                    yodleeModel = new YodleeModel(collectionsId, "Get");
                }
                AspNetUsers   user          = new AspNetUsers();
                UserNames     userNames     = user.getNames(userId);
                RegisterModel registerModel = new RegisterModel(yodleeModel.loginName, userNames);

                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Add("Api-Version", "1.1");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", auth.token.accessToken);
                StringContent       content  = new StringContent(JsonConvert.SerializeObject(registerModel), Encoding.UTF8, "application/json");
                HttpResponseMessage response = await client.PostAsync(url + "/auth/register", content);

                if (response.IsSuccessStatusCode)
                {
                    YodleeAuthReturn authReturn = new YodleeAuthReturn();
                    authReturn = await authReturn.GetToken(yodleeModel.loginName);

                    returnModel.result    = true;
                    returnModel.returnStr = authReturn.token.accessToken;
                }
                else
                {
                    string tokenStr = await response.Content.ReadAsStringAsync();

                    ExceptionCatcher exceptionCatcher = new ExceptionCatcher();
                    exceptionCatcher.Catch(tokenStr);
                    returnModel.result = false;
                }
            }
            else
            {
                ExceptionCatcher catcher = new ExceptionCatcher();
                catcher.Catch("No Token generated");
                returnModel.result = false;
            }
            return(returnModel);
        }
        public async Task <List <YodleeAccountLevel> > GetYodleeAccounts(string collectionsId)
        {
            YodleeAccountModel accounts = new YodleeAccountModel();
            YodleeModel        yodlee   = new YodleeModel();
            string             token    = await yodlee.getToken(collectionsId, "");

            HttpClient client = new HttpClient();

            client.DefaultRequestHeaders.Add("Api-Version", "1.1");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            HttpResponseMessage response = await client.GetAsync(url + "/accounts");

            if (response.IsSuccessStatusCode)
            {
                string str = await response.Content.ReadAsStringAsync();

                accounts = JsonConvert.DeserializeObject <YodleeAccountModel>(str);
            }
            return(accounts.account);
        }
Пример #4
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;
         }
     }
 }
Пример #5
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);
        }