コード例 #1
0
        public IActionResult EditBillPay(int id, BillPay billpay)
        {
            if (id != billpay.BillPayID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var content  = new StringContent(JsonConvert.SerializeObject(billpay), Encoding.UTF8, "application/json");
                var response = BankAPI.InitializeClient().PutAsync("api/BillPays", content).Result;

                // These are to get customerID so it can be passed to ViewBillPays and get back into that page
                var response2  = BankAPI.InitializeClient().GetAsync($"api/Customers/getCustomerFromBillPay/{id}");
                int customerID = int.Parse(response2.Result.Content.ReadAsStringAsync().Result);

                if (response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("ViewBillPays", new { id = customerID }));
                }
            }
            ViewData["Status"] = new BillPayViewModel().Status;

            return(View(billpay));
        }
コード例 #2
0
        public async Task <IActionResult> CreateBillPay()
        {
            //finds the customer that wants to create a new Bill
            var customer = await _context.Customers.FindAsync(CustomerID);

            var billPayModel = new BillPayViewModel(customer);

            return(View(billPayModel));
        }
コード例 #3
0
        //edits a bill
        public async Task <IActionResult> EditBillPay(int?id)
        {
            var customer = await _context.Customers.FindAsync(CustomerID);

            var billPay = await _context.BillPay.FindAsync(id);

            BillPayViewModel model = new BillPayViewModel(customer, billPay);

            return(View(model));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(int id, BillPayViewModel billPayViewModel)
        {
            if (id != billPayViewModel.BillPay.BillPayID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                billPayViewModel.BillPay.ModifyDate = DateTime.UtcNow;
                var content  = new StringContent(JsonConvert.SerializeObject(billPayViewModel.BillPay), Encoding.UTF8, "application/json");
                var response = await NwbaApi.InitializeClient().PutAsync("api/billpays", content);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(billPayViewModel));
        }
コード例 #5
0
        public async Task <IActionResult> ModifyBillPay(int billpayID, int accountNumber, int payeeID, decimal amount, DateTime scheduleDate, string period)
        {
            var customer = await _context.Customers.FindAsync(CustomerID);

            var account = await _context.Accounts.FindAsync(accountNumber);

            var billPay = await _context.BillPays.FindAsync(billpayID);

            if (amount <= 0 || amount.HasMoreThanTwoDecimalPlaces() || amount > account.Balance)
            {
                ModelState.AddModelError(nameof(amount), "Invalid amount");
            }
            if (scheduleDate < DateTime.Today)
            {
                ModelState.AddModelError(nameof(scheduleDate), "Invalid date");
            }

            ViewData["Periods"]       = new BillPayViewModel().Periods;
            ViewData["AccountNumber"] = new SelectList(customer.Accounts, "AccountNumber", "AccountNumber");
            ViewData["PayeeID"]       = new SelectList(_context.Payees, "PayeeID", "PayeeName", billPay.PayeeID);


            if (!ModelState.IsValid)
            {
                List <Account> accounts = new List <Account>();

                ViewData["AccountNumber"] = new SelectList(customer.Accounts, "AccountNumber", "AccountNumber");
                ViewData["PayeeID"]       = new SelectList(_context.Payees, "PayeeID", "PayeeName");

                foreach (var acc in customer.Accounts)
                {
                    accounts.Add(acc);
                }

                ViewBag.Amount       = amount;
                ViewBag.ScheduleDate = scheduleDate;
                return(View(billPay));
            }

            billPayMethods.ModifyBillPay(billPay, accountNumber, payeeID, amount, scheduleDate, period);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(AllScheduledPayments)));
        }
コード例 #6
0
        public async Task <IActionResult> Pay(int?id)
        {
            BillPayViewModel vm;

            vm = new BillPayViewModel();
            if (id != null)
            {
                vm.Bill = await _context.GetBill(CustomerId, id);
            }
            else
            {
                vm.Bill = new BillPay();
            }
            vm.Payees   = _context.GetAllPayees();
            vm.Customer = await _context.GetCustomerWithAccounts(CustomerId);

            return(View(vm));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        // Opens initial page for modifying billpay
        public async Task <IActionResult> ModifyBillPay(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var billPay = await _context.BillPays.FindAsync(id);

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

            var customer = await _context.Customers.FindAsync(CustomerID);

            ViewData["Periods"]       = new BillPayViewModel().Periods;
            ViewData["AccountNumber"] = new SelectList(customer.Accounts, "AccountNumber", "AccountNumber");
            ViewData["PayeeID"]       = new SelectList(_context.Payees, "PayeeID", "PayeeName", billPay.PayeeID);
            return(View(billPay));
        }
コード例 #9
0
        public async Task <IActionResult> EditBillPay(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var response = await BankAPI.InitializeClient().GetAsync($"api/BillPays/{id}");

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }

            var result  = response.Content.ReadAsStringAsync().Result;
            var billpay = JsonConvert.DeserializeObject <BillPay>(result);

            ViewData["Status"] = new BillPayViewModel().Status;

            return(View(billpay));
        }
コード例 #10
0
        public async Task <IActionResult> Index(BillPayViewModel model, int?page = 1)
        {
            ViewBag.Accounts = await this.GetAccountsForViewBag();

            const int pageSize = 4;

            if (model.id != 0)
            {
                HttpContext.Session.SetInt32("BillPayID", model.id);
            }

            if (model.id == 0 && HttpContext.Session.GetInt32("BillPayID").HasValue)
            {
                model.id = HttpContext.Session.GetInt32("BillPayID").Value;
            }

            if (HttpContext.Session.GetInt32("BillPayID").HasValue)
            {
                var sessionID = HttpContext.Session.GetInt32("BillPayID").Value;
                var pagedList = await _bpayRepo.GetTransactionPage(sessionID, page, pageSize);

                model.BillPays = (IPagedList <BillPay>)pagedList;
            }
            else if (ViewBag.Accounts[0] != null)
            {
                var pagedList = await _bpayRepo.GetTransactionPage(ViewBag.Accounts[0].AccountNumber, page, pageSize);

                model.BillPays = (IPagedList <BillPay>)pagedList;
            }
            else
            {
                var pagedList = await _bpayRepo.GetTransactionPage(0, page, pageSize);

                model.BillPays = (IPagedList <BillPay>)pagedList;
            }

            return(View(model));
        }
コード例 #11
0
        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"));
        }
コード例 #12
0
        public async Task <IActionResult> Pay(BillPayViewModel vm)
        {
            bool update = vm.Bill.BillPayId == 0 ? false : true;

            vm.Bill.Account = await _context.GetAccount(CustomerId, vm.Bill.AccountId);

            vm.Bill.Payee = await _context.GetPayee(vm.Bill.PayeeId);

            switch (vm.Bill.SchedulePayment())
            {
            case BillPayResult.FAIL_DATE:
                ModelState.AddModelError($"Bill.{nameof(BillPay.ScheduleDate)}", "Date cannot be in the past");
                goto ErrorCleanup;

            case BillPayResult.FAIL_NEGATIVE:
                ModelState.AddModelError($"Bill.{nameof(BillPay.Amount)}", "Amount must be above 0");
                goto ErrorCleanup;

            case BillPayResult.FAIL_FORMAT:
                goto ErrorCleanup;

            case BillPayResult.OK:
                if (update)
                {
                    var oldBill = await _context.GetBill(vm.Bill.BillPayId, CustomerId);

                    //check we don't edit someone else's bill
                    if (oldBill == null)
                    {
                        ModelState.AddModelError($"Bill.{nameof(BillPay.BillPayId)}", "Illegal BillId in request");
                        goto ErrorCleanup;
                    }
                    //prevent 'Blocked' attribute from being set by users
                    vm.Bill.Blocked = oldBill.Blocked;
                    _context.UpdateBill(CustomerId, vm.Bill);
                }
                else
                {
                    vm.Bill.Blocked = false;
                    _context.CreateBill(CustomerId, vm.Bill);
                }
                _context.SaveChangesAsync();
                break;
            }
            if (update)
            {
                TempData["successMessage"] = $"Updated bill #{vm.Bill.BillPayId}.";
            }
            else
            {
                TempData["successMessage"] = $"Created bill #{vm.Bill.BillPayId}.";
            }

            return(RedirectToAction(nameof(Index)));

ErrorCleanup:
            vm.Payees   = _context.GetAllPayees();
            vm.Customer = await _context.GetCustomerWithAccounts(CustomerId);

            return(View(vm));
        }