Пример #1
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));
        }
Пример #2
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));
        }