// ////////////////////////////////////////////////////////////// // kiem tra so tien trong tai khoan du cho rut khong? // neu ham tra True thi du nguoc lai khong du. public bool checkAccount(decimal amount, Account account) { bool kiemTra = false; if (amount <= (account.Balance + account.OverDraftLimit.Value)) { kiemTra = true; } return kiemTra; }
public ActionResult WithdrawOther(Account a) { decimal amount = (decimal)a.Balance; if (amount % 50000 == 0) { if (amount <= 10000000) { Card card = (Card)Session["Card"]; ATM atm = (ATM)Session["ATM"]; Account account = db.Accounts.Find(card.AccountID); bool kiemTraAcc, kiemTraAtm, kiemTraLimitWithdraw; kiemTraAcc = checkAccount(amount, account);// goi ham kiem tra tai khoan account kiemTraAtm = checkATM(amount); // goi ham kiem tra tien trong ATM string kiemTraType = checkTypeMoney(amount); // goi ham kiem tra tung menh gia trong ATM kiemTraLimitWithdraw = checkLimitWithdraw(amount, account);//goi ham kiem tra gioi han rut tien cua tai khoan if (kiemTraAcc == true && kiemTraAtm == true && kiemTraLimitWithdraw == true && kiemTraType != "") { // tru tien trong tai khoan account.Balance -= amount; //ghi log lc = new LogController(); string detailsFrom = ""; lc.WriteLog(1, 1, card.CardNo, amount, detailsFrom); // goi ham tru tien o ATM và hien view so tien ma khach se nhan duoc ViewBag.money = kiemTraType; db.SaveChanges(); return View(); } else { ViewBag.Error = showError(kiemTraAcc, kiemTraLimitWithdraw, kiemTraAtm, kiemTraType); return View(); } } else { ViewBag.Error = "Số tiền rút cho phép là dưới mười triệu đồng :10000000"; return View(); } } else { ViewBag.Error = "Số tiền rút phải là bội của năm mươi nghìn đồng:50.000"; return View(); } }
public ActionResult TransferCashID(Account account) { if (ModelState.IsValid) { int accountID = account.AccountID; Card card = (Card)Session["Card"]; Account accountTo = db.Accounts.Find(accountID); Account accountFrom = db.Accounts.Find(card.AccountID); Customer cusFrom = db.Customers.Find(accountFrom.CustID); if (accountTo != null && card.AccountID != account.AccountID) { Session["AccountTo"] = accountTo; return RedirectToAction("TransferCashAmount", "Account"); } else { ViewBag.CusNameFrom = cusFrom.Name; ViewBag.AccIDFrom = accountFrom.AccountID; ViewBag.Error = " Bạn đang chuyển tiền vào chính tài khoản của mình hoặc tài khoản bạn chuyển tiền đến không tồn tại." + " Xin vui lòng nhập lại !"; return View(); } } return View(account); }
public ActionResult TransferCashConfirm(Account account) { ATM atm = (ATM)Session["ATM"]; Card card = (Card)Session["Card"]; Account accountFrom = db.Accounts.Find(card.AccountID); // Tránh lỗi mutipleEntity ?!? Account accountto = (Account)Session["AccountTo"]; int accountToID = accountto.AccountID; Account accountTo = db.Accounts.Find(accountToID); decimal amount = (decimal)Session["AmountTransfer"]; accountFrom.Balance = accountFrom.Balance - amount; accountTo.Balance = accountTo.Balance + amount; db.Entry(accountFrom).State = EntityState.Modified; db.Entry(accountTo).State = EntityState.Modified; db.SaveChanges(); // Ghi Log cho tk gửi lc = new LogController(); // Details chỉ đến tên chủ tài khoản + AccNo string detailsFrom = "Transfer cash to " + accountTo.Customer.Name + " AccountID: " + accountTo.AccountID; lc.WriteLog(2, atm.ATMID, card.CardNo, amount, detailsFrom); //string detailsTo = "Receive cash from " + accountFrom.Customer.Name + " AccountID: " + accountFrom.AccountID; // Xóa Session Session["AccountTo"] = null; Session["AmountTransfer"] = null; return RedirectToAction("SuccessTransAsking", "Home"); }
// kiem tra gioi han rut tien cua tai khoan public bool checkLimitWithdraw(decimal amount, Account account) { bool kiemtra = false; if (amount <= account.WithDrawLimit.Value) { kiemtra = true; } return kiemtra; }