public ActionResult getPaymentInsertPartial(int paymentId) { if (Session["LoggedIn"] != null) { bool loggedIn = (bool)Session["LoggedIn"]; if (!loggedIn) { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } TempData["paymentId"] = paymentId; // Get payment Payment p = bankService.getPaymentById(paymentId); int kr = (int)p.Amount; double oreDouble = (p.Amount - kr) * 100; int ore = (int)oreDouble; PaymentInsertModel viewModel = new PaymentInsertModel() { AmountKr = kr, AmountOre = ore, DueDate = p.DueDate, FromAccountNo = p.FromAccountNo, Message = p.Message, ToAccountNo = p.ToAccountNo }; return(PartialView("PaymentInsertPartial", viewModel)); } else { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } }
public ActionResult getPaymentInsertPartial(PaymentInsertModel viewModel) { if (Session["LoggedIn"] != null) { bool loggedIn = (bool)Session["LoggedIn"]; if (!loggedIn) { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } if (!ModelState.IsValid) { //return View(); return(RedirectToAction("DuePayments")); } double amount = viewModel.AmountKr + ((double)viewModel.AmountOre / 100); int paymentId = (int)TempData["paymentId"]; Payment payment = new Payment() { Amount = amount, DateAdded = DateTime.Now, DueDate = viewModel.DueDate, FromAccountNo = viewModel.FromAccountNo, ToAccountNo = viewModel.ToAccountNo, Message = viewModel.Message, PaymentID = paymentId }; bool success = bankService.updatePayment(payment); if (success) { //return PartialView("PaymentInsertPartial",viewModel); return(RedirectToAction("DuePayments")); } else { //return PartialView("PaymentInsertPartial", viewModel); return(RedirectToAction("DuePayments")); } } //return PartialView("PaymentInsertPartial", viewModel); return(RedirectToAction("DuePayments")); }
public ActionResult PaymentInsert() // Legg til betaling { //Session["LoggedIn"] = true; // TODO: USED FOR TESTING ONLY, REMEMBER TO COMMENT OUT WHEN DONE TESTING //Session["UserId"] = "01018912345"; // TODO: REMEMBER TO COMMENT OUT. ONLY USED DURING TESTING PHASE if (Session["LoggedIn"] != null) { bool loggedIn = (bool)Session["LoggedIn"]; if (!loggedIn) { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } // LOGIC STARTS HERE: string userBirthNo = Session["UserId"] as string; List <Account> fromAccounts = bankService.getAccountsByBirthNo(userBirthNo); List <Account> toAccounts = bankService.getAllAccounts(); // Set initial dates for the datepicker: DateTime currDate = DateTime.Today; var model = new PaymentInsertModel() { FromAccounts = new SelectList(fromAccounts, "AccountNo", "AccountNo"), ToAccounts = new SelectList(toAccounts, "AccountNo", "AccountNo"), DueDate = currDate }; model.SelectedFromAccountNo = fromAccounts.FirstOrDefault().AccountNo; //model.SelectedFromAccountNo = "10000000001"; model.SelectedToAccountNo = toAccounts.FirstOrDefault().AccountNo; //model.SelectedFromAccountNo = "10000000009"; return(View(model)); } else { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } }
public ActionResult PaymentInsert(PaymentInsertModel model) // Legg til betaling { //Session["LoggedIn"] = true; // TODO: REMEMBER TO COMMENT OUT. ONLY USED DURING TESTING PHASE //Session["UserId"] = "01018912345"; // TODO: REMEMBER TO COMMENT OUT. ONLY USED DURING TESTING PHASE if (Session["LoggedIn"] != null) { bool loggedIn = (bool)Session["LoggedIn"]; if (!loggedIn) { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } if (!ModelState.IsValid) { return(View()); } // LOGIC STARTS HERE: //string userBirthNo = Session["UserId"] as string; //List<Account> accounts = bankService.getAccountsByBirthNo(userBirthNo); //AccountViewModel fromAccountV = model.Accounts.ElementAt(model.SelectedFromAccount); // User birth no: string userBirthNo = Session["UserId"] as string; // User input of from/to accountNo: string fromAccountNo = model.SelectedFromAccountNo; string toAccountNo = model.SelectedToAccountNo; // Check that from and to account are not the same: if (fromAccountNo != toAccountNo) { Account fromAccount = bankService.getByAccountNo(fromAccountNo); Account toAccount = bankService.getByAccountNo(fromAccountNo); // Check that from account exists: if (fromAccount != null) { // Check that the account belongs to logged in user: if (fromAccount.Owner.BirthNo == userBirthNo) { // Check that to account exists: if (toAccount != null) { double amount = model.AmountKr + ((double)model.AmountOre / 100); // Check that amount being payed is below or equal to balance: if (amount <= fromAccount.Balance) { // ALL IS GOOD: Attempt to go through with payment: var payment = new Payment() { DateAdded = DateTime.Now, DueDate = model.DueDate, Amount = amount, Message = model.Message, FromAccountNo = fromAccountNo, ToAccountNo = toAccountNo }; if (bankService.addPayment(payment)) { // Success return(RedirectToAction("DuePayments", "Customer", new { area = "" })); } else { // Add to db failed return(View()); } } } } } } return(View()); } else { return(RedirectToAction("LoginBirth", "Home", new { area = "" })); } }