Пример #1
0
        public ActionResult Budget()
        {
            ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            Plaid plaid = new Plaid
            {
                User = user
            };

            plaid.GetTransactions();

            //groups by category, sums up amounts and orders categories by greatest to least
            //may want to broaden the date range and get the average amount spent per category
            var budgetquery = (from mem in plaid.Transaction_list
                               where mem.Amount > 0
                               group mem by mem.CategoryID into g
                               select new
            {
                Category = g.Distinct(),
                Amount = g.Sum(x => x.Amount)
            }).OrderByDescending(x => x.Amount).Take(10);

            foreach (var category in budgetquery)
            {
                Budget budget = new Budget
                {
                    Category        = category.Category.FirstOrDefault().CategoryID.ToString(),
                    Category_Amount = category.Amount
                };

                plaid.BudgetList.Add(budget);
            }

            return(View());
        }
Пример #2
0
        public async Task <ActionResult> Profiler(User_Finance data)
        {
            Plaid plaid = new Plaid();

            if (ModelState.IsValid)
            {
                ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

                using (var context = new PersonalFinanceAppEntities())
                {
                    User_Finance update = new User_Finance
                    {
                        UserID         = user.Id,
                        Income         = data.Income,
                        Fixed_Expenses = data.Fixed_Expenses
                    };

                    context.User_Finance.Add(update);
                    await context.SaveChangesAsync();
                }

                //this will indicate that the user has synced accounts and completed the profiler.
                user.FirstLoginFlag = false;
                var result = await UserManager.UpdateAsync(user);

                TempData["result"] = "Profile saved!";
                return(RedirectToAction("Main", "Dashboard"));
            }

            // If we got this far, something failed, redisplay form
            ViewBag.StatusMessage = "Yikes! Something went wrong";
            return(View(plaid));
        }
Пример #3
0
        //GET: Account/Profiler
        public async Task <ActionResult> Profiler()
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

                if (user.FirstLoginFlag == true && user.PhoneNumberConfirmed == false)
                {
                    return(RedirectToAction("AddPhoneNumber", "Manage"));
                }

                Plaid plaid = new Plaid
                {
                    User = user
                };
                try { await plaid.GetAccountList(); }
                catch { }

                ViewBag.Message = TempData["result"] as string;

                return(View(plaid));
            }

            return(View());
        }
Пример #4
0
        public async Task <ActionResult> AccountSync()
        {
            ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            if (user.FirstLoginFlag == true && user.PhoneNumberConfirmed == false)
            {
                return(RedirectToAction("AddPhoneNumber", "Manage"));
            }

            Plaid plaid = new Plaid
            {
                User = user
            };

            try
            {
                await plaid.GetAccountList();

                plaid.p_token = plaid.Reauthaccounts.FirstOrDefault().access_token ?? "";
            }
            catch { }
            ViewBag.Message = TempData["result"] as string;

            return(View(plaid));
        }
Пример #5
0
        //
        // GET: Dashboard/Main
        public async Task <ActionResult> Main()
        {
            if (user.FirstLoginFlag == true && user.PhoneNumberConfirmed == false)
            {
                return(RedirectToAction("AddPhoneNumber", "Manage"));
            }
            if (user.FirstLoginFlag == true)
            {
                return(RedirectToAction("AccountSync", "Account"));
            }

            Plaid plaid = new Plaid
            {
                User       = user,
                Start_date = Session["startdate"] as string,
                End_date   = Session["enddate"] as string
            };

            var transaction_list = Session["transactions"] as List <User_Transactions>;

            if (transaction_list is null)
            {
                await plaid.GetAccountList();

                if (plaid.Reauthaccounts.Count != 0)
                {
                    return(RedirectToAction("AccountSync", "Account"));
                }
                plaid.GetTransactions();
                Session["transactions"]    = plaid.Transaction_list;
                Session["BarChart"]        = plaid.BarChart;
                Session["DonutChart"]      = plaid.DonutChart;
                Session["AccountList"]     = plaid.Account_list;
                Session["Assets"]          = plaid.Assets;
                Session["Liabilities"]     = plaid.Liabilities;
                Session["NetWorth"]        = plaid.NetWorth;
                Session["InstitutionList"] = plaid.InstitutionList;
            }
            else
            {
                plaid.Transaction_list = transaction_list;
                plaid.BarChart         = Session["BarChart"] as List <BarChartData>;
                plaid.DonutChart       = Session["DonutChart"] as List <DonutChartData>;
                plaid.SelectedAccount  = (Session["SelectedAccount"] as string) ?? "All Accounts";
                plaid.Start_date       = (Session["startdate"] as string) ?? DateTime.Today.AddMonths(-1).ToShortDateString();
                plaid.End_date         = (Session["enddate"] as string) ?? DateTime.Today.ToShortDateString();

                plaid.Account_list    = Session["AccountList"] as List <User_Accounts>;
                plaid.Assets          = Session["Assets"] as string;
                plaid.Liabilities     = Session["Liabilities"] as string;
                plaid.NetWorth        = Session["NetWorth"] as string;
                plaid.InstitutionList = Session["InstitutionList"] as List <Institution>;

                plaid.DonutDataSum(plaid.DonutChart);
            }

            return(View(plaid));
        }
Пример #6
0
        public async void should_have_accept_header()
        {
            var fake = new FakeResponseHandler();
            var client = new HttpClient(fake);
            var plaid = new Plaid("fakeId","fakeKey",client);

            var insitutions = plaid.GetInstitutionsTask().Result;

            insitutions.Count.ShouldBeGreaterThan(1);
        }
Пример #7
0
        public async Task <ActionResult> DeleteAccount(string slct)
        {
            ApplicationUser user = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            Plaid plaid = new Plaid
            {
                User = user
            };

            await plaid.DeleteInstitution(slct);

            ViewBag.Message = "Account Deleted!";

            return(RedirectToAction("AccountSync", "Account"));
        }
Пример #8
0
        public async Task <RedirectToRouteResult> Account(string xyz)
        {
            Plaid plaid = new Plaid
            {
                User       = user,
                Start_date = Session["startdate"] as string,
                End_date   = Session["enddate"] as string
            };

            try
            {
                DateTime start_date = DateTime.Parse(plaid.Start_date);
                DateTime end_date   = DateTime.Parse(plaid.End_date);

                plaid.GetTransactions(start_date, end_date, xyz);
            }

            catch
            {
                DateTime?start_date = null;
                DateTime?end_date   = null;

                plaid.GetTransactions(start_date, end_date, xyz);
            }

            await plaid.GetAccountList();

            var accountlist = plaid.Account_list;
            var chartdata   = plaid.BarChart;
            var donutdata   = plaid.DonutChart;
            var networth    = plaid.NetWorth;

            Session["BarChart"]        = chartdata;
            Session["DonutChart"]      = donutdata;
            Session["AccountList"]     = accountlist;
            Session["Assets"]          = plaid.Assets;
            Session["Liabilities"]     = plaid.Liabilities;
            Session["NetWorth"]        = networth;
            Session["transactions"]    = plaid.Transaction_list;
            Session["SelectedAccount"] = plaid.SelectedAccount;
            Session["AccountID"]       = xyz;

            return(RedirectToAction("Main"));
        }
Пример #9
0
        public async Task <ActionResult> AccountSync(Response data)
        {
            Plaid plaid = new Plaid();

            if (ModelState.IsValid)
            {
                ApplicationUser user   = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());
                string          _token = data.Public_token;
                string          name   = data.Name;

                plaid.User             = user;
                plaid.Institution_name = name;
                await plaid.AuthenticateAccount(_token);

                TempData["result"] = "Account added!";
                return(RedirectToAction("AccountSync"));
            }

            // If we got this far, something failed, redisplay form
            ViewBag.StatusMessage = "Yikes! Something went wrong";
            return(View(plaid));
        }
Пример #10
0
        public RedirectToRouteResult DatePickerHandler(Dates dates)
        {
            Plaid plaid = new Plaid();

            if (ModelState.IsValid)
            {
                DateTime start_date = DateTime.Parse(dates.start_date);
                DateTime end_date   = DateTime.Parse(dates.end_date);
                Session["startdate"] = dates.start_date;
                Session["enddate"]   = dates.end_date;

                string selected_account = Session["AccountID"] as string;

                if (!String.IsNullOrEmpty(selected_account))
                {
                    return(RedirectToAction("Account", new { xyz = selected_account }));
                }

                plaid.User = user;
                plaid.GetTransactions(start_date, end_date);

                Session["transactions"]    = plaid.Transaction_list;
                Session["BarChart"]        = plaid.BarChart;
                Session["DonutChart"]      = plaid.DonutChart;
                Session["SelectedAccount"] = plaid.SelectedAccount;

                plaid.Account_list    = Session["AccountList"] as List <User_Accounts>;
                plaid.Assets          = Session["Assets"] as string;
                plaid.Liabilities     = Session["Liabilities"] as string;
                plaid.NetWorth        = Session["NetWorth"] as string;
                plaid.InstitutionList = Session["InstitutionList"] as List <Institution>;

                return(RedirectToAction("Main", plaid));
            }
            //if we got this far something went wrong - redisplay the page
            return(RedirectToAction("Main"));
        }
Пример #11
0
 public void Setup()
 {
     _client = new Plaid("test_id","test_secret");
 }
Пример #12
0
        //
        //GET: Populating data for the Data Table
        public JsonResult DataTableHandler(DataTable param)
        {
            Plaid plaid = new Plaid
            {
                User       = user,
                Start_date = Session["startdate"] as string,
                End_date   = Session["enddate"] as string
            };
            var transaction_list = Session["transactions"] as List <User_Transactions>;

            if (transaction_list is null)
            {
                plaid.GetTransactions();
            }
            else
            {
                plaid.Transaction_list = transaction_list;
                plaid.BarChart         = Session["BarChart"] as List <BarChartData>;
                plaid.DonutChart       = Session["DonutChart"] as List <DonutChartData>;
                plaid.Account_list     = Session["AccountList"] as List <User_Accounts>;
                plaid.Assets           = Session["Assets"] as string;
                plaid.Liabilities      = Session["Liabilities"] as string;
                plaid.NetWorth         = Session["NetWorth"] as string;
                plaid.DonutDataSum(plaid.DonutChart);
            }

            var displayedTransactions = (IEnumerable <User_Transactions>)plaid.Transaction_list;

            var sortColumnIndex = Convert.ToInt32(Request["iSortCol_0"]);

            if (sortColumnIndex == 0)
            {
                Func <User_Transactions, DateTime> orderingFunction = (c => c.Date);
                var sortDirection = Request["sSortDir_0"]; // asc or desc
                if (sortDirection == "desc")
                {
                    displayedTransactions = displayedTransactions.OrderBy(orderingFunction);
                }
                else
                {
                    displayedTransactions = displayedTransactions.OrderByDescending(orderingFunction);
                }
            }
            else if (sortColumnIndex == 4)
            {
                Func <User_Transactions, decimal> orderingFunction = (c => c.Amount);
                var sortDirection = Request["sSortDir_0"]; // asc or desc
                if (sortDirection == "asc")
                {
                    displayedTransactions = displayedTransactions.OrderBy(orderingFunction);
                }
                else
                {
                    displayedTransactions = displayedTransactions.OrderByDescending(orderingFunction);
                }
            }
            else
            {
                Func <User_Transactions, string> orderingFunction = (c => sortColumnIndex == 1 ? c.CategoryID :
                                                                     sortColumnIndex == 2 ? c.Location_Name :
                                                                     c.Location_State);
                var sortDirection = Request["sSortDir_0"]; // asc or desc
                if (sortDirection == "asc")
                {
                    displayedTransactions = displayedTransactions.OrderBy(orderingFunction);
                }
                else
                {
                    displayedTransactions = displayedTransactions.OrderByDescending(orderingFunction);
                }
            }

            displayedTransactions = displayedTransactions
                                    .Skip(param.iDisplayStart)
                                    .Take(param.iDisplayLength);

            var data = from transaction in displayedTransactions
                       select new[] { transaction.Date.ToShortDateString(),
                transaction.CategoryID,
                transaction.Location_Name,
                                      (transaction.Location_City + " " + transaction.Location_State),
                                      String.Format("{0:C}", transaction.Amount) };


            return(Json(new
            {
                dom = "",
                param.sEcho,
                iTotalRecords = plaid.Transaction_list.Count(),
                iTotalDisplayRecords = plaid.Transaction_list.Count(),
                iSortingCols = 5,
                aaData = data
            },
                        JsonRequestBehavior.AllowGet));
        }
Пример #13
0
 public void Setup()
 {
     _p = new Plaid("herp","derp");
 }