public async Task <ActionResult <SBAccount> > PostSBAccount(SBAccount sBAccount) { _context.SBAccounts.Add(sBAccount); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSBAccount", new { id = sBAccount.Id }, sBAccount)); }
public async Task <IActionResult> PutSBAccount(int id, SBAccount sBAccount) { if (id != sBAccount.Id) { return(BadRequest()); } _context.Entry(sBAccount).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SBAccountExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult> Delete(SBAccount p) { int vid = Convert.ToInt32(TempData["ID"]); using (var httpClient = new HttpClient()) { using (var response = await httpClient.DeleteAsync("http://localhost:13173/api/SBAccounts/" + vid)) { string apiResponse = await response.Content.ReadAsStringAsync(); } } return(RedirectToAction("Index")); }
public async Task <ActionResult> Details(int id) { SBAccount b = new SBAccount(); using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync("http://localhost:13173/api/SBAccounts/" + id)) { string apiResponse = await response.Content.ReadAsStringAsync(); b = JsonConvert.DeserializeObject <SBAccount>(apiResponse); } } return(View(b)); }
public async Task <ActionResult> Create(SBAccount p) { using (var httpClient = new HttpClient()) { StringContent content = new StringContent(JsonConvert.SerializeObject(p), Encoding.UTF8, "application/json"); using (var response = await httpClient.PostAsync("http://localhost:13173/api/SBAccounts", content)) { string apiResponse = await response.Content.ReadAsStringAsync(); var obj = JsonConvert.DeserializeObject <SBAccount>(apiResponse); } } return(RedirectToAction("Index")); }
public async Task <ActionResult> Edit(SBAccount b) { SBAccount receivedemp = new SBAccount(); int vid = Convert.ToInt32(TempData["AccountID"]); using (var httpClient = new HttpClient()) { StringContent content1 = new StringContent(JsonConvert.SerializeObject(b), Encoding.UTF8, "application/json"); using (var response = await httpClient.PutAsync("http://localhost:5866/api/SBAccounts/" + vid, content1)) { string apiResponse = await response.Content.ReadAsStringAsync(); receivedemp = JsonConvert.DeserializeObject <SBAccount>(apiResponse); } } return(RedirectToAction("Index")); }
public SBAccount FindByUserNameAndPassword(string userName, string password) { var cmd = new MySqlCommand("select * from accounts where userName = @userName and password = @password", ConnectionHelper.GetConnection()); cmd.Parameters.AddWithValue("@userName", userName); cmd.Parameters.AddWithValue("@password", password); var reader = cmd.ExecuteReader(); var sbAccount = new SBAccount(); if (reader.Read()) { sbAccount.UserName = reader.GetString("userName"); sbAccount.Password = reader.GetString("password"); sbAccount.Balance = reader.GetDouble("balance"); } ConnectionHelper.CloseConnection(); return(sbAccount); }
public static void GenerateMenu(Transaction transaction) { currentLoggedInAddress = null; currentLoggedInAccount = null; Console.Clear(); Console.WriteLine("Please choose the type of transaction: "); Console.WriteLine("1. Withdraw."); Console.WriteLine("2. Deposit."); Console.WriteLine("3. Transfer."); Console.WriteLine("Please enter your choice: "); var choice = int.Parse(Console.ReadLine()); while (true) { switch (choice) { case 1: transaction.Withdraw(); break; case 2: transaction.Deposit(); break; case 3: transaction.Transfer(); break; default: Console.WriteLine("Choose the wrong type of transaction."); break; } if (choice == 4) { break; } } }
public bool UpdateBalance(SBAccount currentLoggedInAccount, TransactionSB transactionSb) { var trans = ConnectionHelper.GetConnection().BeginTransaction(); try { var cmd = new MySqlCommand("select balance from accounts where accountNumber = @accountNumber", ConnectionHelper.GetConnection()); cmd.Parameters.AddWithValue("@accountNumber", currentLoggedInAccount.AccountNumber); var reader = cmd.ExecuteReader(); double currentBalance = 0; if (reader.Read()) { currentBalance = reader.GetDouble("balance"); } reader.Close(); if (transactionSb.Type == TransactionSB.TransactionType.Withdraw && currentBalance < transactionSb.Amount) { throw new Exception("Not enough money in the account."); } if (transactionSb.Type == TransactionSB.TransactionType.Withdraw) { currentBalance -= transactionSb.Amount; } if (transactionSb.Type == TransactionSB.TransactionType.Deposit) { currentBalance += transactionSb.Amount; } var cmd1 = new MySqlCommand( "update accounts set balance = @balance where accountNumber = @accountNumber", ConnectionHelper.GetConnection()); cmd1.Parameters.AddWithValue("@balance", currentBalance); cmd1.Parameters.AddWithValue("@accountNumber", currentLoggedInAccount.AccountNumber); var updateResult = cmd1.ExecuteNonQuery(); var cmd2 = new MySqlCommand( "insert into transactions (transactionId, senderAccountNumber, receiverAccountNumber, type, amount, message, createdAt, updatedAt, status) values ( @transactionId, @senderAccountNumber, @receiverAccountNumber, @type, @amount, @message, @createdAt, @updatedAt, @status) ", ConnectionHelper.GetConnection()); cmd2.Parameters.AddWithValue("@transactionId", transactionSb.TransactionId); cmd2.Parameters.AddWithValue("@senderAccountNumber", transactionSb.SenderAccountNumber); cmd2.Parameters.AddWithValue("@receiverAccountNumber", transactionSb.ReceiverAccountNumber); cmd2.Parameters.AddWithValue("@type", transactionSb.Type); cmd2.Parameters.AddWithValue("@amount", transactionSb.Amount); cmd2.Parameters.AddWithValue("@message", transactionSb.Message); cmd2.Parameters.AddWithValue("@createdAt", transactionSb.CreatedAtMls); cmd2.Parameters.AddWithValue("@updatedAt", transactionSb.UpdatedAtMls); cmd2.Parameters.AddWithValue("@status", transactionSb.Status); var transactionResult = cmd2.ExecuteNonQuery(); if (updateResult != 1 || transactionResult != 1) { throw new Exception("Cannot add transactions or update accounts."); } trans.Commit(); return(true); } catch (Exception e) { trans.Rollback(); Console.WriteLine(e); return(false); } finally { ConnectionHelper.CloseConnection(); } }
static void Main(string[] args) { BankRepository obj = new BankRepository(); SBAccount sb1 = new SBAccount(); Console.WriteLine("Welcome to the Banking Project"); Console.WriteLine("Choose the option from below menu"); Console.WriteLine("1... Add a new Account"); Console.WriteLine("2... View List of Accounts"); Console.WriteLine("3... Deposit Amount"); Console.WriteLine("4... Withdraw Amount"); Console.WriteLine("5... View Account Detail"); int choice = Convert.ToInt32(Console.ReadLine()); switch (choice) { case 1: { Console.WriteLine("Enter Account Number"); sb1.AccountNumber = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Enter Customer Name"); sb1.CustomerName = Console.ReadLine(); Console.WriteLine("Enter Address"); sb1.CustomerAddress = Console.ReadLine(); Console.WriteLine("Enter Current Balance"); sb1.CurrentBalance = Convert.ToInt32(Console.ReadLine()); obj.NewAccount(sb1); Console.WriteLine("Your Account is Successfully Added"); break; } case 2: { List <SBAccount> result = obj.GetAllAccounts(); foreach (var item in result) { Console.WriteLine(item.ToString()); } break; } case 3: { Console.WriteLine("How much amount you want to Deposit"); decimal amt = Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("Please Enter your Account Number"); int accno = Convert.ToInt32(Console.ReadLine()); double balance = obj.DepositAmount(accno, amt); Console.WriteLine("Your Current Balance is :" + balance); break; } case 4: { Console.WriteLine("How much amount you want to Withdraw"); decimal amt = Convert.ToDecimal(Console.ReadLine()); Console.WriteLine("Please Enter your Account Number"); int accno = Convert.ToInt32(Console.ReadLine()); double balance = obj.WithdrawAmount(accno, amt); Console.WriteLine("Your Current Balance is :" + balance); break; } case 5: { Console.WriteLine("Please Enter your Account Number"); int accno = Convert.ToInt32(Console.ReadLine()); SBAccount s = obj.GetAccountDetails(accno); Console.WriteLine("Your Details are :"); Console.WriteLine(s.ToString()); break; } default: { Console.WriteLine("Please Enter a valid choice"); break; } } }