示例#1
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);
            }
        }
        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);
        }
        public async Task <List <string> > GetProviders(string token)
        {
            List <string> providers = new List <string>();
            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();

                YodleeAccountModel accounts = JsonConvert.DeserializeObject <YodleeAccountModel>(str);
                if (accounts.account != null)
                {
                    foreach (YodleeAccountLevel item in accounts.account)
                    {
                        providers.Add(item.providerAccountId.ToString());
                    }
                }
            }
            return(providers);
        }