예제 #1
0
 private static void ProcessTransactions(List<BankLoginAccountTransaction> transactions, BankLogin login, Options options)
 {
     foreach (BankLoginAccountTransaction transaction in transactions) {
         transaction.LoginId = login.Id;
         // Check existing
         var existing = options.DataService.Transactions.GetSingle(new { serviceid = transaction.ServiceId });
         if (existing == null) {
             // Get the source name
             var source = options.DataService.Accounts.GetSingle(new { serviceid = transaction.ServiceAccountId });
             transaction.Source = source.Name;
             // Map categories
             var category = options.DataService.Categories.FindCategoryMatch(transaction.Description);
             if (category != null) {
                 transaction.Category = category.Name;
             }
             // Save if a new transaction
             options.DataService.Transactions.Upsert(transaction);
         }
     }
 }
예제 #2
0
        public ActionResult Logins(FormCollection form)
        {
            var publicToken = form["public_token"];

            // Save the token in case of failure
            Service.Logins.SavePublicToken(publicToken);

            // Exchange for accessToken
            var accessToken = BankService.RunAfterAuthFunction(publicToken);

            // Save login
            var login = new BankLogin() {
                Institution = "plaid_link",
                Name = form["Name"],
                HouseholdId = GetHouseholdIdForCurrentUser(),
                AccessToken = accessToken
            };
            Service.Logins.Upsert(login);

            // Delete the token after a successful translation
            Service.Logins.DeletePublicToken(publicToken);

            // Get accounts
            var accounts = BankService.GetAccounts(login.Id, accessToken).Result;
            // Save accounts
            foreach (BankLoginAccount bank in accounts) {
                Service.Accounts.Upsert(bank);
            }

            return RedirectToAction("Logins");
        }