// GET: Expenses
        public IActionResult Index(string sortOrder, string searchString, int?page)
        {
            if (User.Identity.Name == null)
            {
                return(Redirect("/Identity/Account/Login"));
            }
            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm     = sortOrder == "Date" ? "date_desc" : "Date";
            ViewBag.AmountSortParm   = sortOrder == "Amount" ? "amount_desc" : "Amount";
            ViewBag.CategorySortParm = sortOrder == "Category" ? "category_desc" : "Category";
            var    userID = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            string sort   = String.IsNullOrEmpty(sortOrder) ? "title_asc" : sortOrder;
            string search = String.IsNullOrEmpty(searchString) ? "" : searchString;

            ViewData["CurrentSort"]   = sort;
            ViewData["CurrentFilter"] = search;

            ExpenseRepo expRepo = new ExpenseRepo(_context);

            var expenses = expRepo.GetAllExpenses(userID);

            if (!String.IsNullOrEmpty(searchString))
            {
                expenses = expRepo.GetExpensesBySearch(userID, searchString);
            }
            expenses = expRepo.SortExpenses(expenses, sortOrder);
            int pageSize = 3;

            //return View(await expenses.ToListAsync());
            return(View(PaginatedList <Expense> .Create(expenses, page ?? 1, pageSize)));
        }
        public IActionResult GetCategory(string category, string sortOrder, string searchString, int?page)
        {
            if (User.Identity.Name == null)
            {
                return(Redirect("/Identity/Account/Login"));
            }
            var         userID  = User.FindFirst(ClaimTypes.NameIdentifier).Value;
            ExpenseRepo expRepo = new ExpenseRepo(_context);

            ViewData["Category"]    = category;
            ViewData["Total"]       = expRepo.CalculateCategoryTotal(category, userID).ToString("C");
            ViewData["WeeklyTotal"] = expRepo.CalculateWeeklyTotal(category, userID).ToString("C");
            var expenses = expRepo.GetExpensesByCategory(userID, category);

            ViewBag.NameSortParm     = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm     = sortOrder == "Date" ? "date_desc" : "Date";
            ViewBag.AmountSortParm   = sortOrder == "Amount" ? "amount_desc" : "Amount";
            ViewBag.CategorySortParm = sortOrder == "Category" ? "category_desc" : "Category";
            string sort   = String.IsNullOrEmpty(sortOrder) ? "title_asc" : sortOrder;
            string search = String.IsNullOrEmpty(searchString) ? "" : searchString;

            ViewData["CurrentSort"]   = sort;
            ViewData["CurrentFilter"] = search;

            if (!String.IsNullOrEmpty(searchString))
            {
                expenses = expRepo.SearchExpensesWithCategory(userID, category, searchString);
            }
            expenses = expRepo.SortExpenses(expenses, sortOrder);
            int pageSize = 3;

            return(View(PaginatedList <Expense> .Create(expenses, page ?? 1, pageSize)));
        }