public async Task <IActionResult> OnGetAsync(int?id, DateTime?duplicateDateError, [FromQuery] BillPayPaging paging)
        {
            if (id == null)
            {
                return(NotFound());
            }

            CurrentPaymentPage = paging.PaymentPage ?? 1;
            CurrentBillPage    = paging.BillPage ?? 1;
            CurrentExpensePage = paging.ExpensePage ?? 1;

            if (duplicateDateError != null)
            {
                DuplicateDateError = duplicateDateError;
            }

            BillPay = await _billPayService.GetByIdAsync((int)id);

            if (BillPay == null)
            {
                return(NotFound());
            }

            //Bills pagination
            int totalUpcomingBills = await _billService.CountUpcomingBillsAsync();

            TotalBillPages = (int)Math.Ceiling(((float)totalUpcomingBills / 20));
            UpcomingBills  = await _billService.GetUpcomingBillsAsync((CurrentBillPage - 1) * 20, 20);

            //Payments pagination
            int totalPayments = await _paymentService.CountPaymentsByBillPayAsync(BillPay.ID);

            TotalPaymentPages = (int)Math.Ceiling(((float)totalPayments / 8));
            BillPay.Payments  =
                await _paymentService.GetPaymentsByBillPayAsync(BillPay.ID, (CurrentPaymentPage - 1) * 8, 8);

            //Expenses pagination
            int totalExpenses = await _expenseService.CountExpensesByBillPayAsync(BillPay.ID);

            TotalExpensePages = (int)Math.Ceiling(((float)totalExpenses / 8));
            BillPay.Expenses  = await _expenseService.GetExpensesByBillPayAsync(BillPay.ID, (CurrentExpensePage - 1) * 8, 8);

            if (BillPay == null)
            {
                return(NotFound());
            }
            return(Page());
        }
        public async Task <IActionResult> OnPostConfirmPayment(int?paymentID, int?billPayID, [FromQuery] BillPayPaging paging)
        {
            if (billPayID == null || paymentID == null)
            {
                return(NotFound());
            }

            //Ensure parameters belong to current user
            Payment payment = await _paymentService.GetPaymentByIdAsync((int)paymentID);

            if (payment == null)
            {
                return(NotFound());
            }

            //Update payment confirmation status
            await _paymentService.ToggleConfirmationAsync(payment);

            //Call get method to rebuild page
            return(RedirectToPage("Edit", new {
                ID = billPayID,
                PaymentPage = paging.PaymentPage,
                BillPage = paging.BillPage,
                ExpensePage = paging.ExpensePage
            }));
        }
        public async Task <IActionResult> OnPostConfirmExpense(int?expenseID, int?billPayID, [FromQuery] BillPayPaging paging)
        {
            if (billPayID == null || expenseID == null)
            {
                return(NotFound());
            }

            //Ensure parameters belong to current user
            Expense expense = await _expenseService.GetExpenseByIDAsync((int)expenseID);

            if (expense == null)
            {
                return(NotFound());
            }

            //Remove expense
            await _expenseService.ToggleConfirmationAsync(expense);

            //Call get method to rebuild page
            return(RedirectToPage("Edit", new {
                ID = billPayID,
                PaymentPage = paging.PaymentPage,
                BillPage = paging.BillPage,
                ExpensePage = paging.ExpensePage
            }));
        }