public async Task <IActionResult> EditBillPay(BillPayViewModel _billPay)
        {
            ModelState.Clear();

            //Validates the edited bill pay
            //Shows errors back if invalid
            Dictionary <string, string> errors = new Dictionary <string, string>();

            BillPay.IsValid(_context, _billPay.BillPay, out errors);

            if (errors.Count > 0)
            {
                foreach (KeyValuePair <string, string> entry in errors)
                {
                    ModelState.AddModelError(entry.Key, entry.Value);
                }
            }

            if (!ModelState.IsValid)
            {
                return(await EditBillPay(_billPay.BillPay.BillPayID));
            }

            //Updates the chosen bill
            BillPay billPay = await _context.BillPay.FindAsync(_billPay.BillPay.BillPayID);

            if (billPay == null)
            {
                return(await EditBillPay(_billPay.BillPay.BillPayID));
            }

            billPay.AccountNumber = _billPay.BillPay.AccountNumber;
            billPay.PayeeID       = _billPay.BillPay.PayeeID;
            billPay.Amount        = _billPay.BillPay.Amount;
            billPay.ScheduleDate  = _billPay.BillPay.ScheduleDate;
            billPay.Period        = _billPay.BillPay.Period;
            billPay.ModifyDate    = DateTime.UtcNow;

            //saves changes to the DB
            await _context.SaveChangesAsync();

            //goes back to the list view
            return(RedirectToAction("BillPayListView", "BillPay"));
        }
        public async Task <IActionResult> CreateBillPay(BillPayViewModel billPayModel)
        {
            ModelState.Clear();
            //Validates and shows errors to the user if there are any
            Dictionary <string, string> errors = new Dictionary <string, string>();

            BillPay.IsValid(_context, billPayModel.BillPay, out errors);

            if (errors.Count > 0)
            {
                foreach (KeyValuePair <string, string> entry in errors)
                {
                    ModelState.AddModelError(entry.Key, entry.Value);
                }
            }

            if (!ModelState.IsValid)
            {
                return(await CreateBillPay());
            }

            //creates, adds and saves the new bill
            BillPay billPay = new BillPay()
            {
                AccountNumber = billPayModel.BillPay.AccountNumber,
                PayeeID       = billPayModel.BillPay.PayeeID,
                Amount        = billPayModel.BillPay.Amount,
                ScheduleDate  = billPayModel.BillPay.ScheduleDate,
                Period        = billPayModel.BillPay.Period,
                ModifyDate    = DateTime.UtcNow
            };

            //adds to database and saves
            _context.BillPay.Add(billPay);
            _context.SaveChanges();
            return(RedirectToAction("ViewAccounts", "Customer"));
        }