public ActionResult Create([Bind(Include = "AccountNumber,AccountName,Balance,IBAN")] Account account) { if (ModelState.IsValid) { account = Depositmoney(account); db.Accounts.Add(account); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(account)); }
private void buttonOK_Click(object sender, RoutedEventArgs e) { editEmployeeInfo.EmployeeNo = this.txtEmployeeNo.Text; editEmployeeInfo.EmployeeName = this.txtEmployeeName.Text; editEmployeeInfo.sex = this.radioMan.IsChecked == true ? "男" : "女"; editEmployeeInfo.workDate = this.datePickerworkDate.SelectedDate; editEmployeeInfo.telphone = this.txttelphone.Text; editEmployeeInfo.idCard = this.txtidCard.Text; if (photofilePath != "") { Stream mystream = File.OpenRead(photofilePath); byte[] bt = new byte[mystream.Length]; mystream.Read(bt, 0, (int)mystream.Length); editEmployeeInfo.photo = bt; } try { int i = context.SaveChanges(); MessageBox.Show(string.Format("成功修改{0}个职员信息", i)); } catch { MessageBox.Show("修改职员失败!"); } this.Close(); editEmployeeInfo.EmployeeNo = this.txtEmployeeNo.Text; editEmployeeInfo.EmployeeName = this.txtEmployeeName.Text; editEmployeeInfo.sex = this.radioMan.IsChecked == true ? "男" : "女"; editEmployeeInfo.workDate = this.datePickerworkDate.SelectedDate; editEmployeeInfo.telphone = this.txttelphone.Text; editEmployeeInfo.idCard = this.txtidCard.Text; if (photofilePath != "") { Stream mystream = File.OpenRead(photofilePath); byte[] bt = new byte[mystream.Length]; mystream.Read(bt, 0, (int)mystream.Length); editEmployeeInfo.photo = bt; } try { int i = context.SaveChanges(); MessageBox.Show(string.Format("成功修改{0}个职员信息", i)); } catch { MessageBox.Show("修改职员失败!"); } this.Close(); }
public ActionResult Create([Bind(Include = "a_branch_id,a_branch_name,a_branch_add,a_admin_id,available_cash,b_branch_id")] ATM aTM) { if (ModelState.IsValid) { aTM.a_branch_id = db.ATMs.Max(u => u.a_branch_id) + 1; db.ATMs.Add(aTM); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.a_admin_id = new SelectList(db.A_ATM, "a_admin_id", "a_admin_name", aTM.a_admin_id); ViewBag.b_branch_id = new SelectList(db.Banks, "b_branch_id", "b_branch_name", aTM.b_branch_id); return(View(aTM)); }
//更改密码 private void btnOk_Click(object sender, RoutedEventArgs e) { var query = from t in context.AccountInfo where t.accountNo == this.txtAccount.Text select t; if (query.Count() > 0) { var q = query.First(); q.accountPass = this.txtNewPass.Password; if (q.IsLoss == 1) { MessageBox.Show("该卡已经被挂失!"); return; } try { context.SaveChanges(); MessageBox.Show("更改密码成功!"); } catch { MessageBox.Show("更改密码失败!"); } } }
private void button_Delete_Click(object sender, RoutedEventArgs e) { var item = dataGrid.SelectedItem as EmployeeInfo; if (item == null) { MessageBox.Show("请先选择要删除的职员信息!"); return; } MessageBoxResult result = MessageBox.Show("您确定要删除该职员的信息吗?", "删除确认", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { context = new BankEntities(); var q = from t in context.EmployeeInfo where t.EmployeeNo == item.EmployeeNo select t; if (q != null) { try { context.EmployeeInfo.Remove(q.FirstOrDefault()); int i = context.SaveChanges(); MessageBox.Show(string.Format("成功删除{0}个职员信息", i)); } catch { MessageBox.Show("删除失败!"); } } } ShowResult(); }
/// <summary> /// Opens new account /// </summary> /// <param name="account">New account</param> public void OpenAccount(Interface.DTO.Account account) { using (BankEntities bankEntities = new BankEntities()) { Owner accOwner = bankEntities.Owner.FirstOrDefault(owner => owner.Name == account.AccountOwner.FirstName && owner.Surname == account.AccountOwner.LastName); if (accOwner == null) { accOwner = bankEntities.Owner.Add(new Owner() { Name = account.AccountOwner.FirstName, Surname = account.AccountOwner.LastName }); } Account dbAccount = bankEntities.Account.Add(new Account() { Number = account.AccountNumber, Amount = account.CurrentAmount, BonusCount = account.BonusCount, IsOpen = true, Type = AccountTypeConverter.AccountTypeToString(account.AccountType), Owner = accOwner, OwnerId = accOwner.OwnerId }); bankEntities.SaveChanges(); } }
public int Post([FromBody] User_Details ud) { try { db.User_Details.Add(ud); var res = db.SaveChanges(); if (res > 0) { return(ud.Acc_No); } } catch (Exception e) { throw e; } return(0); }
public ActionResult Create([Bind(Include = "DepositID,Depositnumber,DepositAmount")] Deposit deposit) { if (ModelState.IsValid) { var account = db.Accounts.Where(x => x.AccountNumber == deposit.Depositnumber).FirstOrDefault(); deposit.Account = account; deposit = Checkbalanceandgetdeposit(deposit); db.Deposits.Add(deposit); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Depositnumber = new SelectList(db.Accounts, "AccountNumber", "AccountName", deposit.Depositnumber); return(View(deposit)); }
public string Tranfer(TranfersViewModel tranfer) { tranfer.AcountReceiver = "123123123123"; tranfer.LongDate = DateTime.Now; var acc = db.Accounts.Find(tranfer.AccountSender); if (acc == null) { return("Tài khoản không đúng"); } else { var acc2 = db.Accounts.Find(tranfer.AcountReceiver); if (tranfer.AccountCode.Equals(acc.AccountCode)) { if (acc.Balance > tranfer.Amount) { acc.Balance -= tranfer.Amount; acc2.Balance += tranfer.Amount; db.SaveChanges(); Transfer a = new Transfer(); a.AccountSender = tranfer.AccountSender; a.AccountReceiver = tranfer.AcountReceiver; a.Amount = tranfer.Amount; a.LogDate = DateTime.Now; db.Transfers.Add(a); db.SaveChanges(); return("giao dịch thành công"); } else { return("giao dịch thất bại"); } } else { return("Mã PIN không chính xác"); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { try { context.SaveChanges(); MessageBox.Show("保存成功!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "保存失败"); } }
public bool CreateDeposit(DepositCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Deposit { TransactionID = model.TransactionID, Amount = model.Amount }; ctx.Deposits.Add(entity); return(ctx.SaveChanges() == 1); } }
public object AddAccount([FromBody] CustomerAccount account) { account = entities.CustomerAccounts.Add(account); entities.SaveChanges(); int EGPCurrencyId = entities.Currencies.FirstOrDefault(cr => cr.CurrencyName == "EGP").CurrencyId; double addedBalance = 0.00; if (account.CurrencyId == EGPCurrencyId) { addedBalance = account.Openning_Balance; } else { ExchangeRate rate = entities.ExchangeRates.FirstOrDefault(ex => ex.FromCurrencyId == account.CurrencyId && ex.ToCurrencyId == EGPCurrencyId); if (rate.Operator == "m") { addedBalance = account.Openning_Balance * rate.Amount; } else // == "d" { addedBalance = account.Openning_Balance / rate.Amount; } } var newAccount = from accounts in entities.CustomerAccounts where accounts.Acc_ID == account.Acc_ID select new { accounts.Acc_ID, accounts.Acc_Number, accounts.Acc_Type, accounts.Class_Code, accounts.currency.CurrencyName, accounts.Openning_Balance, accounts.Status }; return(new { addedBalance = addedBalance, newAccount = newAccount }); }
public bool CreateWithdrawal(WithdrawalCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Withdrawal { TransactionID = model.TransactionID, Amount = model.Amount }; ctx.Withdrawals.Add(entity); return(ctx.SaveChanges() == 1); } }
public int CreateTransaction(TransactionCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Transaction { TransactionType = model.TransactionType, AccountID = model.AccountID }; ctx.Transactions.Add(entity); ctx.SaveChanges(); return(entity.TransactionID); } }
public ActionResult Create([Bind(Include = "TransferID,TransferFrom,TranferMoney,TransferTo")] Transfer transfer) { if (ModelState.IsValid) { var from = db.Accounts.Where(x => x.AccountNumber == transfer.TransferFrom).FirstOrDefault(); var To = db.Accounts.Where(x => x.AccountNumber == transfer.TransferTo).FirstOrDefault(); transfer.Account = from; transfer.Account1 = To; if (CheckBalance(transfer)) { transfer = updatebalance(transfer); db.Transfers.Add(transfer); db.SaveChanges(); } else { } return(RedirectToAction("Index")); } ViewBag.TransferFrom = new SelectList(db.Accounts, "AccountNumber", "AccountName", transfer.TransferFrom); ViewBag.TransferTo = new SelectList(db.Accounts, "AccountNumber", "AccountName", transfer.TransferTo); return(View(transfer)); }
public bool SaveNewBalanceToDatabase(string acctNum, decimal newBalance) { using (var ctx = new BankEntities()) { var entity = ctx .Accounts .Single(a => a.AccountNumber == acctNum); entity.AccountNumber = acctNum; entity.Balance = newBalance; return(ctx.SaveChanges() == 1); } }
public ActionResult Create([Bind(Include = "cust_id,cust_name,Dob,contact_no,cust_add,a_c_no,a_c_type,card_no,b_branch_id")] Customer customer) { if (ModelState.IsValid) { Random rnd = new Random(); string acc_gen = rnd.Next(10000000, 99999999).ToString(); int intIdt = db.Customers.Max(u => u.cust_id) + 1; customer.cust_id = intIdt; customer.Bal = 0; //starts at 0 while (db.Customers.Any(o => o.a_c_no == acc_gen)) { acc_gen = rnd.Next(10000000, 99999999).ToString(); } customer.a_c_no = "RO52" + "BANK" + "00009999" + acc_gen; customer.card_no = generate_card(customer, acc_gen); customer.card_pin = rnd.Next(1000, 9999).ToString(); //has to be random db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.b_branch_id = new SelectList(db.Banks, "b_branch_id", "b_branch_name", customer.b_branch_id); //ViewBag.acc_type = new SelectList(new SelectListItem { Text = "debit", Value = "debit" }, // new SelectListItem { Text = "credit", Value = "credit" }); ViewBag.a_c_type = new SelectList( new List <SelectListItem> { new SelectListItem { Selected = true, Text = "debit", Value = "debit" }, new SelectListItem { Selected = false, Text = "credit", Value = "credit" } }, "Value", "Text"); return(View(customer)); }
public bool CreateAccount(AccountCreateModel model) { using (var ctx = new BankEntities()) { var entity = new Account { AccountNumber = model.AccountNumber, AccountType = model.AccountType, Balance = model.Balance, Pin = model.Pin, CustomerID = model.CustomerId, CreatedUtc = DateTime.Now }; ctx.Accounts.Add(entity); return(ctx.SaveChanges() == 1); } }
/// <summary> /// Closes the account /// </summary> /// <param name="accountNumber">The existing account number</param> public void CloseAccount(string accountNumber) { using (BankEntities bankEntities = new BankEntities()) { var account = bankEntities.Account.FirstOrDefault(acc => acc.Number == accountNumber); if (account != null) { account.IsOpen = false; } else { throw new ArgumentException($"There is no account with number {accountNumber}"); } bankEntities.SaveChanges(); } }
/// <summary> /// Deposits given amount to the account with given account number /// </summary> /// <param name="accountNumber">The account number</param> /// <param name="amount">The amount to deposit</param> /// <param name="bonus">The bonus points to add</param> public void DepositAccount(string accountNumber, decimal amount, int bonus) { using (BankEntities bankEntities = new BankEntities()) { var account = bankEntities.Account.FirstOrDefault(acc => acc.Number == accountNumber); if (account != null) { account.BonusCount += bonus; account.Amount += amount; } else { throw new ArgumentException($"There is no account with number {accountNumber}"); } bankEntities.SaveChanges(); } }
public bool CreateCustomer(CustomerCreateModel model) { using (var ctx = new BankEntities()) { //1 Collecting info from model //2 Storing in matching Entity Property var entity = new Customer { //2 //1 SocialSecurityNumber = model.SocialSecurityNumber, FirstName = model.FirstName, LastName = model.LastName, CreatedUtc = DateTime.Now }; ctx.Customers.Add(entity); return(ctx.SaveChanges() == 1); } }
//更改密码 private void btnOk_Click(object sender, RoutedEventArgs e) { var query = from t in context.LoginInfo where t.Bno == this.txtAccount.Text select t; if (query.Count() > 0) { var q = query.First(); q.Password = this.txtNewPass.Password; try { context.SaveChanges(); MessageBox.Show("更改密码成功!"); } catch { MessageBox.Show("更改密码失败!"); } } }
public ActionResult Deposit(int cust_id, int branch, decimal balance, int atm) { string message; CustomerBankList cust = new CustomerBankList(); cust.Name = (from c in db.Customers where c.cust_id == cust_id select c).FirstOrDefault(); cust.Bnk = (from c in db.Banks where c.b_branch_id == branch select c).FirstOrDefault(); cust.atm = (from c in db.ATMs where c.b_branch_id == branch && c.a_branch_id == atm select c).FirstOrDefault(); cust.ListATM = (from c in db.ATMs where c.b_branch_id == branch select c).ToList(); if (balance % 5 != 0) { ViewBag.Message = "Amount has to be a multiple of 5"; return(View(cust)); } else { cust.Name.Bal = cust.Name.Bal + balance; cust.atm.available_cash = cust.atm.available_cash + balance; Transaction tran = new Transaction(); tran.a_c_no = cust.Name.a_c_no; tran.credit = balance; tran.debit = 0; tran.Date = DateTime.Now; tran.total = cust.Name.Bal; tran.message = "Deposit of " + tran.credit + " lei at branch " + cust.Bnk.b_branch_name + " and on ATM " + cust.atm.a_branch_name; tran.Transaction_ID = db.Transactions.Max(u => u.Transaction_ID) + 1; db.Transactions.Add(tran); } db.SaveChanges(); message = "You have successfuly deposited " + balance + " lei to this account!"; return(RedirectToAction("Welcome", "Simulator", new { card_no = cust.Name.card_no, branch1 = cust.Bnk.b_branch_id, message = message })); }
//存款 private void btnOk_Click(object sender, RoutedEventArgs e) { Custom custom = DataOperation.GetCustom(this.txtAccount.Text); if (custom == null) { MessageBox.Show("帐号不存在!"); return; } if (custom.AccountInfo.IsLoss == 1) { MessageBox.Show("该卡已经被挂失!"); return; } //获得combox selectindex值 BankEntities context = new BankEntities(); custom.MoneyInfo.accountNo = txtAccount.Text; if (combox.SelectedIndex == 0) { custom.Diposit("存款", double.Parse(this.txtmount.Text), combox.SelectedIndex); } if (combox.SelectedIndex >= 1 && combox.SelectedIndex <= 3) { custom.Diposit("存款", double.Parse(this.txtmount.Text), combox.SelectedIndex); } if (combox.SelectedIndex > 3 && combox.SelectedIndex <= 6) { var q = from t in context.MoneyInfo where t.accountNo == this.txtAccount.Text && t.dealType == "开户" select t; var w = q.FirstOrDefault(); var qq = from t in context.AccountInfo where t.accountNo == this.txtAccount.Text select t; var m = qq.FirstOrDefault(); if (txtmount.Text != w.balance.ToString()) { MessageBox.Show("此金额不正确,请重新填写!"); return; } else { if (m.accountClass == null) { if (combox.SelectedIndex == 4) { m.accountClass = 1.ToString(); } else if (combox.SelectedIndex == 5) { m.accountClass = 3.ToString(); } else { m.accountClass = 5.ToString(); } } if (m.accountMark.Contains(MouthTimeBox.Text)) { MessageBox.Show("此月已经存入所需金额,请重新填写!"); return; } else { string str = m.accountMark; m.accountMark = str + " " + MouthTimeBox.Text; context.SaveChanges(); } } custom.Diposit("存款", double.Parse(this.txtmount.Text), combox.SelectedIndex); } OperateRecord page = new OperateRecord(); NavigationService ns = NavigationService.GetNavigationService(this); ns.Navigate(page); }
public int Save() { return(db.SaveChanges()); }
[HttpPost] //***EDIT|SAVE! public ActionResult Edit(AccountList accountList, string additionalnumbers) { // var acct = new Account(); if (accountList != null) { if (accountList.AccountId == 0) { var acctno = (0 + db.Accounts.Count()).ToString().PadLeft(10, '0'); var Customer = new Customer { CustomerName = accountList.CustomerName, CreateDate = DateTime.Now, }; db.Customers.Add(Customer); db.SaveChanges(); var Account = new Account { AccountNo = acctno, CustomerFK = Customer.CustomerID, CreateDate = DateTime.Now, }; db.Accounts.Add(Account); db.SaveChanges(); if (!string.IsNullOrEmpty(additionalnumbers)) { string[] mobilenumbers = additionalnumbers.Split(','); for (int i = 0; i < mobilenumbers.Count(); i++) { var Mobile = new MobileNumber { MobileNumber1 = mobilenumbers[i], CustomerFK = Customer.CustomerID, CreateDate = DateTime.Now, }; db.MobileNumbers.Add(Mobile); db.SaveChanges(); } } var Deposit = new Transaction { Amount = accountList.Amount, TransactionTypeFK = 1, CustomerFK = Customer.CustomerID, RemainingBalance = accountList.Amount, CreateDate = DateTime.Now, UpdateDate = DateTime.Now, }; db.Transactions.Add(Deposit); db.SaveChanges(); } else { var acct = db.Accounts.Where(a => a.AccountId == accountList.AccountId).FirstOrDefault(); var name = db.Customers.Where(c => c.CustomerID == acct.CustomerFK).FirstOrDefault(); if (name != null) { name.CustomerName = accountList.CustomerName; name.UpdateDate = DateTime.Now; db.SaveChanges(); } if (accountList.MobileNumbers != null) { foreach (var item in accountList.MobileNumbers) { var num = db.MobileNumbers.Where(m => m.MobileNumberID == item.MobileNumberID).FirstOrDefault(); if (num != null) { num.MobileNumber1 = item.MobileNumber1; num.UpdateDate = DateTime.Now; db.SaveChanges(); } } } //if (!string.IsNullOrEmpty(additionalnumbers)) //{ // string[] mobilenumbers = additionalnumbers.Split(','); // for (int i = 0; i < mobilenumbers.Count(); i++) // { // int mobilenumber = accountList.MobileNumbers[i].MobileNumberID; // var num = db.MobileNumbers.Where(m => m.MobileNumberID == mobilenumber).FirstOrDefault(); // if (num != null) // { // num.MobileNumber1 = mobilenumbers[i]; // num.UpdateDate = DateTime.Now; // db.SaveChanges(); // } // } //} if (!string.IsNullOrEmpty(additionalnumbers)) { string[] mobilenumbers = additionalnumbers.Split(','); for (int i = 0; i < mobilenumbers.Count(); i++) { var Mobile = new MobileNumber { MobileNumber1 = mobilenumbers[i], CustomerFK = name.CustomerID, CreateDate = DateTime.Now, }; db.MobileNumbers.Add(Mobile); db.SaveChanges(); } } } } return(View()); }