public ActionResult Admin(Bank_Admin admin) { BankEntities usersEntities = new BankEntities(); if (admin.b_admin_name == null) { ModelState.AddModelError(admin.b_admin_name, "The Username field cannot be empty"); } if (admin.b_admin_pin.ToString() == null) { ModelState.AddModelError(admin.b_admin_pin.ToString(), "The PIN field cannot be empty"); } int?userId = usersEntities.VALIDATE_ADMIN(admin.b_admin_name.ToString(), admin.b_admin_pin.ToString()).FirstOrDefault(); string message = string.Empty; switch (userId.Value) { case -1: message = "Username or password incorrect"; break; case 0: FormsAuthentication.SetAuthCookie(admin.b_admin_name, admin.RememberMe); return(RedirectToAction("Index", "Admin", admin)); } ViewBag.Message = message; return(View(admin)); }
/// <summary> /// 获取存款用户信息,并初始化余额 /// </summary> /// <param name="accountNumber"></param> /// <returns></returns> public static Custom GetCustom(string accountNumber) { Custom custom = null; BankEntities c = new BankEntities(); try { var q = (from t in c.AccountInfo where t.accountNo == accountNumber select t).Single(); custom = CreateCustom(q.accountType); custom.AccountInfo.accountNo = accountNumber; custom.AccountInfo.accountName = q.accountName; custom.AccountInfo.accountPass = q.accountPass; custom.AccountInfo.IdCard = q.IdCard; } catch { return(null); } var q1 = (from t in c.MoneyInfo where t.accountNo == accountNumber select t).Sum(x => x.dealMoney); //custom.AccountBalance = q1.Year; return(custom); }
public async Task <bool> WithdrawAsync(decimal amount) { using (BankEntities context = new BankEntities()) { Account query = await GetAccountAsync(context); var balance = query.Balance; var newBalance = balance - amount; var balanceDiff = amount * -1; if (newBalance <= 0) { Console.WriteLine("You don't have enough funds."); return(false); } var transaction = new Transaction() { AccountNumber = _accountNum, TransactionType = "Withdrawal", BalanceDifference = balanceDiff, TransactionDate = DateTime.Now }; query.Balance = newBalance; context.Transactions.Add(transaction); return(await context.SaveChangesAsync() == 1); } }
public async Task <Account> GetAccountAsync(BankEntities context) { return(await context .Accounts .Where(e => e.AccountNumber == _accountNum) .SingleOrDefaultAsync()); }
public async Task <ResponseModel> Transfer([FromBody] RequestModel requestModel) { //performs validation on request's data //get merchant account details from database var account = new Account(); using (BankEntities db = new BankEntities()) { account = await db.Accounts.FindAsync(requestModel.MerchantAccountID); } //check if account exists if (account == null) { return(new ResponseModel(ResponseStatuses.Error, "Invalid Merchant account ID")); } /* * contact issuing bank to request money transfer * check if response from issuing bank is as expected and return appropriate response to this caller */ //if everything is as expected: //update account balance using (BankEntities db = new BankEntities()) { account.Amount += requestModel.Amount; db.Entry(account).State = EntityState.Modified; await db.SaveChangesAsync(); } //return successful response return(new ResponseModel(ResponseStatuses.Successful, string.Empty)); }
//Get Customer from DB private Customer GetCustomerIdBySSN(BankEntities context, int ssn) { return (context .Customers .SingleOrDefault(c => c.SocialSecurityNumber == ssn)); }
private Account GetAccountByNumAndPin(BankEntities context, string accountNum, string pin) { return (context .Accounts .SingleOrDefault(a => a.AccountNumber == accountNum && a.Pin == pin)); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log) { log.Info("Received new account request"); HttpResponseMessage response; try { var user = await req.Content.ReadAsAsync <User>(); if (user != null) { log.Info("Saving to database"); using (var db = new BankEntities()) { db.Users.Add(user); await db.SaveChangesAsync(); } response = req.CreateResponse(HttpStatusCode.OK); } else { var errorMessage = "Failed to parse user"; log.Error(errorMessage); response = req.CreateErrorResponse(HttpStatusCode.BadRequest, errorMessage); } } catch (Exception e) { log.Error(e.Message, e); response = req.CreateErrorResponse(HttpStatusCode.InternalServerError, e); } return(response); }
/// <summary> /// Gets all open accounts /// </summary> /// <returns>The enumeration of the account instance</returns> public IEnumerable <Interface.DTO.Account> GetAccounts() { List <Interface.DTO.Account> accounts = new List <Interface.DTO.Account>(); using (BankEntities bankEntities = new BankEntities()) { var dbAccounts = from account in bankEntities.Account where account.IsOpen select new { Number = account.Number, OwnerName = account.Owner.Name, OwnerSurname = account.Owner.Surname, AccountType = account.Type, CurrentAmount = account.Amount, BonusCount = account.BonusCount }; foreach (var account in dbAccounts) { accounts.Add(new Interface.DTO.Account(account.Number, new Interface.DTO.Owner(account.OwnerName, account.OwnerSurname), AccountTypeConverter.StringToAccountType(account.AccountType)) { CurrentAmount = account.CurrentAmount, BonusCount = account.BonusCount }); } } return(accounts); }
/// <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 ActionResult Simulator(CustomerBankList user) { BankEntities usersEntities = new BankEntities(); int? userId = usersEntities.VALIDATE_USER(user.Name.card_no.ToString(), user.Name.card_pin.ToString()).FirstOrDefault(); string card_number = user.Name.card_no; int branch = (int)user.Bnk.b_branch_id; string message = string.Empty; switch (userId.Value) { case -1: { message = "Card Number or PIN is incorrect"; user.BankList = db.Banks.ToList(); break; } case 0: FormsAuthentication.SetAuthCookie(user.Name.card_no, user.RememberMe); return(RedirectToAction("Welcome", "Simulator", new { card_no = user.Name.card_no, branch1 = user.Bnk.b_branch_id })); } ViewBag.Message = message; return(View(user)); }
public BankEntities[] DisplayAllDetails() { SqlConnection ConnectionObject = new SqlConnection("Data Source=TAVDESK001;initial catalog=BankDatabase;integrated security=true"); BankEntities[] EntityArray = new BankEntities[100]; string command = "select * from AccountDetails;"; SqlCommand cmd = new SqlCommand(command, ConnectionObject); ConnectionObject.Open(); SqlDataReader SqlReader = cmd.ExecuteReader(); int counter = 0; while (SqlReader.Read()) { BankEntities EntityObject = new BankEntities(); EntityObject.AccountNumber = Convert.ToInt32(SqlReader.GetValue(0)); EntityObject.AccountBalance = Convert.ToInt32(SqlReader.GetValue(1)); EntityObject.BranchName = SqlReader.GetValue(2).ToString(); EntityObject.AccountType = SqlReader.GetValue(3).ToString(); EntityArray[counter] = EntityObject; counter++; } ConnectionObject.Close(); return(EntityArray); }
public BankEntities getAccountDetail(int AccNum) { try { BankEntities EntityObject = new BankEntities(); SqlConnection ConnectionObject = new SqlConnection("Data Source=TAVDESK001;initial catalog=BankDatabase;integrated security=true"); BankEntities[] EntityArray = new BankEntities[100]; string command = "select * from AccountDetails;"; SqlCommand cmd = new SqlCommand(command, ConnectionObject); ConnectionObject.Open(); SqlDataReader SqlReader = cmd.ExecuteReader(); while (SqlReader.Read()) { if (Convert.ToInt32(SqlReader.GetValue(0)) == AccNum) { EntityObject.AccountNumber = Convert.ToInt32(SqlReader.GetValue(0)); EntityObject.AccountBalance = Convert.ToInt32(SqlReader.GetValue(1)); EntityObject.BranchName = SqlReader.GetValue(2).ToString(); EntityObject.AccountType = SqlReader.GetValue(3).ToString(); break; } } ConnectionObject.Close(); return(EntityObject); } catch (Exception e) { return(null); } }
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> /// Gets the account using it's number /// </summary> /// <param name="accountNumber">The number of the account</param> /// <returns>The account with given number</returns> public Interface.DTO.Account GetAccount(string accountNumber) { using (BankEntities bankEntities = new BankEntities()) { var dbAccount = (from account in bankEntities.Account where account.IsOpen && account.Number == accountNumber join owner in bankEntities.Owner on account.OwnerId equals owner.OwnerId select new { Number = account.Number, OwnerName = account.Owner.Name, OwnerSurname = account.Owner.Surname, AccountType = account.Type, CurrentAmount = account.Amount, BonusCount = account.BonusCount }).FirstOrDefault(); if (dbAccount != null) { return(new Interface.DTO.Account( dbAccount.Number, new Interface.DTO.Owner(dbAccount.OwnerName, dbAccount.OwnerSurname), AccountTypeConverter.StringToAccountType(dbAccount.AccountType)) { CurrentAmount = dbAccount.CurrentAmount, BonusCount = dbAccount.BonusCount }); } else { return(null); } } }
private void Button_Click_1(object sender, RoutedEventArgs e) { BankEntities Content = new BankEntities(); if (date1 != null) { DateTime date2 = DateTime.Now; if ((date2 - date1).TotalHours < 8) { MessageBox.Show("您未完成今日的工作任务"); } else { MessageBox.Show("你已经成功下班打卡"); WageInfo wg1 = new WageInfo(); wg1.worktime = this.date1; wg1.closingtime = this.date2; wg1.normaltime = 320; wg1.overtime = 0; if ((date2 - date1).TotalHours == 1) { wg1.overtime = 20; } if ((date2 - date1).TotalHours == 2) { wg1.overtime = 40; } } } }
public OperateRecord() { InitializeComponent(); BankEntities context = new BankEntities(); var query = from t in context.MoneyInfo select t; this.datagrid1.ItemsSource = query.ToList(); }
public OperateRecord() { InitializeComponent(); BankEntities context = new BankEntities(); var query = from t in context.MoneyInfo select t; this.datagrid1.ItemsSource = query.ToList(); }
/// <summary> /// 获取指定类别的利率 /// </summary> /// <param name="rateType">利率类别</param> /// <returns>对应类别的利率值</returns> public static double GetRate(RateType rateType) { string type = rateType.ToString(); BankEntities c = new BankEntities(); var q = (from t in c.RateInfo where t.rationType == type select t.rationValue).Single(); return(q.Value); }
public void ShowResult() { using (BankEntities c = new BankEntities()) { var q = from t in c.EmployeeInfo select t; datagrid1.ItemsSource = q.ToList(); } }
public async Task <IEnumerable <Transaction> > GetAccountHistoryAsync() { using (BankEntities context = new BankEntities()) { return(await context .Transactions .Where(e => e.AccountNumber == _accountNum) .ToListAsync()); } }
/// <summary> /// 获取指定类别的利率 /// </summary> /// <param name="rateType">利率类别</param> /// <returns>对应类别的利率值</returns> public static double GetRate(RateType rateType) { bool mark = true; string type = rateType.ToString(); BankEntities context = new BankEntities(); var qq = from t in context.AccountInfo where t.accountNo == DataOperation.str select t; var m = qq.FirstOrDefault(); if (type == "零存整取1年" || type == "零存整取3年" || type == "零存整取5年") { if (type == "零存整取1年") { for (int i = 2; i <= 12; i++) { if (!m.accountMark.Contains(i.ToString())) { mark = false; } } } else if (type == "零存整取3年") { for (int i = 2; i <= 36; i++) { if (!m.accountMark.Contains(i.ToString())) { mark = false; } } } else { for (int i = 2; i <= 60; i++) { if (!m.accountMark.Contains(i.ToString())) { mark = false; } } } if (mark == false) { type = "零存整取违规"; } } BankEntities c = new BankEntities(); var q = (from t in c.RateInfo where t.rationType == type select t.rationValue).Single(); return(q.Value); }
public int GetAccountId(string accountNum) { BankEntities context = new BankEntities(); var query = from a in context.Accounts where a.AccountNumber == accountNum select a; foreach (var account in query) { return(account.AccountID); } return(0); }
public void AuthServiceVerifyTests() { string accountNum = "1111"; string pin = "1111"; BankEntities bank = new BankEntities(); AuthService authService = new AuthService(); //Act bool test = authService.VerifyUser(accountNum, pin); //Assert Assert.IsTrue(test); }
public async Task <decimal> GetBalanceAsync() { using (BankEntities context = new BankEntities()) { var query = await context .Accounts .Where(e => e.AccountNumber == _accountNum) .Select(e => e.Balance) .SingleOrDefaultAsync(); return(query); } }
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 int AddingNewAccount(BankEntities EntityObject, int KeyValue) { int a; if (KeyValue == 1) { a = DataAccessObject.AddingAccount("AddingAccountDetails", EntityObject); } else { a = EntityDataAccessObject.AddingAccount(EntityObject); } return(a); }
public BankEntities DisplayAccountofParticularAccount(int AccNum, int KeyValue) { BankEntities EntityObject = new BankEntities(); if (KeyValue == 1) { EntityObject = DataAccessObject.getAccountDetail(AccNum); } else { EntityObject = EntityDataAccessObject.getAccountDetails(AccNum); } return(EntityObject); }
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); } }
private void ShowResult() { if (context != null) { context.Dispose(); context = new BankEntities(); } //step2 var q = from t in context.EmployeeInfo select t; //step 3 this.dataGrid.ItemsSource = q.ToList(); }
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 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); } }
private void comboBoxAccountType_SelectionChanged(object sender, SelectionChangedEventArgs e) { string s = comboBoxAccountType.SelectedItem.ToString(); using(BankEntities c = new BankEntities()) { var q = from t in c.AccountInfo where t.accountType == s select t; if (q.Count() > 0) { this.txtAccountNo.Text = string.Format("{0}", int.Parse(q.Max(x => x.accountNo)) + 1); } else { txtAccountNo.Text = string.Format("{0}00001", comboBoxAccountType.SelectedIndex + 1); } } }