public ActionResult Withdraw(TransactionModel model) { if (ModelState.IsValid && model.debit > 0) { string dtStamp = DateTime.Now.ToString(); var balance = getAccountBalance(model.account); if (balance <= model.debit) { TempData["successW"] = "N"; } else { var dbATM = new ATMEntities(); var transaction = new transaction { tStamp = dtStamp, debit = model.debit, account = model.account, credit = 0 }; dbATM.transactions.AddObject(transaction); dbATM.SaveChanges(); TempData["successW"] = "Y"; } return View(model); } else { ModelState.AddModelError("", "The withdrawal value provided is incorrect."); } return View(model); }
public ActionResult Deposit(TransactionModel model) { if (ModelState.IsValid && model.credit > 0) { string dtStamp = DateTime.Now.ToString(); var dbATM = new ATMEntities(); var transaction = new transaction { tStamp = dtStamp, credit = model.credit, account = model.account, debit = 0 }; dbATM.transactions.AddObject(transaction); dbATM.SaveChanges(); TempData["successD"] = "Y"; } else { ModelState.AddModelError("", "The deposit value provided is incorrect."); } return View(model); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email); if (createStatus == MembershipCreateStatus.Success) { // On success create a new customer data MembershipUser newUser = MembershipService.GetUser(model.UserName, false); string newUserID = newUser.ProviderUserKey.ToString(); string dtStamp = DateTime.Now.ToString(); string accountNo = Guid.NewGuid().ToString(); var dbATM = new ATMEntities(); var customer = new customer { idCustomer = newUserID, firstName = model.FirstName, lastName = model.LastName, account = accountNo, cDate = dtStamp }; dbATM.customers.AddObject(customer); dbATM.SaveChanges(); FormsService.SignIn(model.UserName, false); Session.Add("accountNumber", accountNo); TempData["justRegistered"] = "Y"; return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", CustomerValidation.ErrorCodeToString(createStatus)); } } ViewData["PasswordLength"] = MembershipService.MinPasswordLength; return View(model); }