public async static Task SeedBankVaultAsync(ApplicationDbContext context) { if (!context.GLCategories.Any(category => category.Name.ToLower() == "cash assets")) { var cashAssets = new GLCategory { Name = "CASH ASSETS", Type = AccountType.Assets, IsEnabled = true, Description = "GL Category for Cash Assets Accounts" }; context.Add(cashAssets); await context.SaveChangesAsync(); } GLCategory category = await context.GLCategories.SingleOrDefaultAsync(c => c.Name.ToLower() == "cash assets"); if (!context.InternalAccounts.Any(account => account.AccountCode == "10000000000000")) { var vault = new InternalAccount { AccountName = "Vault", AccountBalance = 100000000, AccountCode = "10000000000000", IsActivated = true, GLCategory = category }; context.Add(vault); await context.SaveChangesAsync(); } }
private static void DepositToAdmin(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Deposit Menu"; Console.WriteLine($"User:{username}\tYou pressed 2. Deposit to Cooperative’s internal bank account\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again."); // You have {tries} tries.\n"); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //deposit data input Console.WriteLine("Please insert the amount you want to deposit."); Console.Write("Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); //Input validation var account = new InternalAccount(); Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (!account.HasSufficientBalance(username, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAccount(username, "admin", amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
public OutputData Update(IInputData input, object instance) { BasePasswordData passwd = instance.Convert <BasePasswordData>(); InternalAccount account = new InternalAccount(passwd.UserId, passwd.Password); account.Update(); return(OutputData.CreateToolkitObject(KeyData.Empty)); }
public OutputData Insert(IInputData input, object instance) { InternalAccount account = instance as InternalAccount; TkDebug.AssertNotNull(account, "account", this); string password = account.GetNewPassword("InternalAccount"); ServiceAccount.Add(account.Account + "@" + WeixinSettings.Current.WeixinAccount, account.NickName, password); return(OutputData.CreateToolkitObject(new KeyData(account.Account, account.NickName))); }
public async Task AddInternalAccountAsync(InternalAccountViewModel accountViewModel) { var categoryId = int.Parse(accountViewModel.CategoryId); var category = await _context.GLCategories.FindAsync(categoryId); var account = new InternalAccount { AccountCode = GenerateInternalAccountCode(category.Type), AccountName = accountViewModel.AccountName, GLCategoryId = categoryId, IsActivated = accountViewModel.IsActivated }; _context.Add(account); await _context.SaveChangesAsync(); }
public static ConsoleKeyInfo DisplayMenu(string username) { Console.Clear(); Console.Title = "Internal Bank System - Main Menu"; Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine($"Welcome {username}\n"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; var account = new InternalAccount(); if (account.IsUserAdmin(username)) { return(DisplayAdminMenu(username)); } return(DisplaySimpleUserMenu(username)); }
private static void ViewMyAccount(string username) { var account = new InternalAccount(); Console.Title = "Internal Bank System - My Account"; Console.Clear(); if (account.IsUserAdmin(username)) { Console.WriteLine($"User:{username}\tYou pressed 1. View Cooperative's internal bank account"); } else { Console.WriteLine($"User:{username}\tYou pressed 1. View my bank account"); } Console.WriteLine(); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(account.ViewAccount(username)); Console.WriteLine("------------------------------------------------------------"); GoToMainMenu(); return; }
public bool SendTodaysStatements(string username, List <string> memory) { var account = new InternalAccount(); var today = DateTime.Today; string filePath = "C:\\Users\\vivi\\Desktop\\"; string fileName; if (account.IsUserAdmin(username)) { fileName = "statement_admin" + today.ToString("_dd_MM_yyyy") + ".txt"; } else { var userId = account.GetUserId(username); fileName = "statement_user_" + userId + today.ToString("_dd_MM_yyyy") + ".txt"; } if (!File.Exists(filePath + fileName)) { memory.Insert(0, $"User: {username}\t | Date: {today:dd/MM/yyyy}\n"); memory.Insert(1, ""); memory.Insert(2, "Transaction\t Participants\t Amount\t Transaction Date \t Account Balance\n"); } try { using (var sw = new StreamWriter(filePath + fileName, true, Encoding.Unicode)) { foreach (var item in memory) { sw.WriteLine(item); } } return(true); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nA file error occurred."); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Press Enter to see Details about the error or any other button to continue.."); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Enter) { Console.WriteLine($"\nError Details: {ex.Message}"); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to continue .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); } Console.Clear(); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine("\nTo go back to Main Menu press Enter. To continue and exit press any key.."); Console.ForegroundColor = ConsoleColor.White; var k = Console.ReadKey(); if (k.Key != ConsoleKey.Enter) { Console.Clear(); Console.Title = "Internal Bank System - Exit"; Console.WriteLine("\nApplication is closing.."); Console.WriteLine($"Goodbye."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to exit the application .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); Environment.Exit(0); Console.ReadKey(); } return(false); } }
public async Task CreateTellerPosting(string userId, TellerPostingViewModel viewModel) { float creditBalance = 0; float debitBalance = 0; CBAUser user = await _context.Users.Include(u => u.Till).FirstOrDefaultAsync(u => u.Id == userId); InternalAccount tellerAccount = user.Till; if ((viewModel.TransactionSlipNo == null) || (await _context.Postings.AnyAsync(p => p.TransactionSlipNo == viewModel.TransactionSlipNo))) { throw new Exception("Duplicate Transaction. A transaction with this Slip Number has already been posted."); } InternalAccount vault = await _context.InternalAccounts.SingleOrDefaultAsync(i => i.AccountCode == "10000000000000"); AccountConfiguration settings = _context.AccountConfigurations.First(); CustomerAccount customerAccount; var creditPosting = new Posting { TransactionDate = viewModel.TransactionDate, TransactionSlipNo = viewModel.TransactionSlipNo, Credit = viewModel.Amount, Notes = viewModel.Notes, Balance = creditBalance, PostingDate = DateTime.Now, CBAUserId = userId, }; var debitPosting = new Posting { TransactionDate = viewModel.TransactionDate, TransactionSlipNo = viewModel.TransactionSlipNo, Debit = viewModel.Amount, Notes = viewModel.Notes, Balance = debitBalance, PostingDate = DateTime.Now, CBAUserId = userId, }; switch (viewModel.TransactionType) { case TransactionType.Withdrawal: if (tellerAccount == null) { throw new Exception("You cannot post a customer transaction. There is no Till associated with this account."); } customerAccount = await _context.CustomerAccounts .Where(i => i.AccountNumber == viewModel.AccountNumber) .FirstOrDefaultAsync(); if (!customerAccount.IsActivated) { throw new Exception("Unable to post transaction. Customer Account is deactivated."); } if (tellerAccount.AccountBalance < viewModel.Amount) { throw new Exception("Unable to post transaction. Insufficient funds in Till."); } switch (customerAccount.AccountClass) { case AccountClass.Savings: if (customerAccount.AccountBalance <= settings.SavingsMinBalance) { throw new Exception("Account has reached Minimum Balance limit. Cannot post withdrawal."); } break; case AccountClass.Current: if (customerAccount.AccountBalance <= settings.CurrentMinBalance) { throw new Exception("Account has reached Minimum Balance limit. Cannot post withdrawal."); } break; case AccountClass.Loan: break; default: break; } creditBalance = tellerAccount.AccountBalance - viewModel.Amount; debitBalance = customerAccount.AccountBalance - viewModel.Amount; creditPosting.AccountCode = tellerAccount.AccountCode; debitPosting.AccountNumber = customerAccount.AccountNumber; creditPosting.GLAccount = tellerAccount; debitPosting.GLAccount = customerAccount; tellerAccount.AccountBalance = creditBalance; customerAccount.AccountBalance = debitBalance; _context.Update(customerAccount); break; case TransactionType.Deposit: if (tellerAccount == null) { throw new Exception("You cannot post a customer transaction. There is no Till associated with this account."); } customerAccount = await _context.CustomerAccounts .Where(i => i.AccountNumber == viewModel.AccountNumber) .FirstOrDefaultAsync(); if (!customerAccount.IsActivated) { throw new Exception("Unable to post transaction. Customer Account is deactivated."); } creditBalance = customerAccount.AccountBalance + viewModel.Amount; debitBalance = tellerAccount.AccountBalance + viewModel.Amount; creditPosting.AccountNumber = customerAccount.AccountNumber; debitPosting.AccountCode = tellerAccount.AccountCode; creditPosting.GLAccount = customerAccount; debitPosting.GLAccount = tellerAccount; tellerAccount.AccountBalance = debitBalance; customerAccount.AccountBalance = creditBalance; _context.Update(customerAccount); break; case TransactionType.VaultIn: tellerAccount = await _context.InternalAccounts.FirstOrDefaultAsync(a => a.AccountCode == viewModel.AccountCode); if (tellerAccount.AccountBalance < viewModel.Amount) { throw new Exception("Unable to post transaction. Insufficient funds in Till."); } creditBalance = tellerAccount.AccountBalance - viewModel.Amount; debitBalance = vault.AccountBalance + viewModel.Amount; creditPosting.AccountCode = tellerAccount.AccountCode; debitPosting.AccountCode = vault.AccountCode; creditPosting.GLAccount = tellerAccount; debitPosting.GLAccount = vault; creditPosting.TransactionDate = debitPosting.TransactionDate = DateTime.Now; creditPosting.Notes = debitPosting.Notes = "VaultIn"; tellerAccount.AccountBalance = creditBalance; vault.AccountBalance = debitBalance; _context.Update(vault); break; case TransactionType.VaultOut: tellerAccount = await _context.InternalAccounts.FirstOrDefaultAsync(a => a.AccountCode == viewModel.AccountCode); if (vault.AccountBalance < viewModel.Amount) { throw new Exception("Unable to post transaction. Insufficient funds in Vault."); } creditBalance = vault.AccountBalance - viewModel.Amount; debitBalance = tellerAccount.AccountBalance + viewModel.Amount; creditPosting.AccountCode = vault.AccountCode; debitPosting.AccountCode = tellerAccount.AccountCode; creditPosting.GLAccount = vault; debitPosting.GLAccount = tellerAccount; creditPosting.TransactionDate = debitPosting.TransactionDate = DateTime.Now; creditPosting.Notes = debitPosting.Notes = "VaultIn"; tellerAccount.AccountBalance = debitBalance; vault.AccountBalance = creditBalance; _context.Update(vault); break; default: break; } _context.Update(tellerAccount); await _context.SaveChangesAsync(); creditPosting.TransactionDate = DateTime.Now; debitPosting.TransactionDate = DateTime.Now; creditPosting.Balance = creditBalance; debitPosting.Balance = debitBalance; _context.Add(creditPosting); _context.Add(debitPosting); await _context.SaveChangesAsync(); }
private static void SendToFile(string username) { Console.Title = "Internal Bank System - Save File"; Console.Clear(); var account = new InternalAccount(); if (account.IsUserAdmin(username)) { Console.WriteLine($"User:{username}\tYou pressed 5. Send today’s transactions and Exit"); } else { Console.WriteLine($"User:{username}\tYou pressed 4. Send today’s transactions and Exit"); } Console.WriteLine(); if (memory.Count == 0) { Console.WriteLine("There are no transactions to be saved.. Memory is empty."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to continue and exit the application .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); Console.Clear(); Console.Title = "Internal Bank System - Exit"; Console.WriteLine($"\nGoodbye {username}."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to exit the application .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); Environment.Exit(0); Console.ReadKey(); } //success Console.WriteLine("Saving memory to file.."); var file = new FileAccess(); var valid = file.SendTodaysStatements(username, memory); Thread.Sleep(500); if (valid) { Console.WriteLine( ); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Successful Operation!"); Console.ForegroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to continue .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); Console.Clear(); Console.Title = "Internal Bank System - Exit"; Console.WriteLine($"\nGoodbye {username}."); Console.ForegroundColor = ConsoleColor.Gray; Console.Write("\nPress any button to exit the application .."); Console.ForegroundColor = ConsoleColor.White; Console.ReadKey(); Environment.Exit(0); Console.ReadKey(); } }
private static void WithdrawMenu(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Withdraw Menu"; Console.WriteLine($"User:{username}\tYou pressed 4. Withdraw from account\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again."); // You have {tries} tries.\n"); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //available users var account = new InternalAccount(); var users = account.GetUsernames(); //withdraw data input Console.WriteLine("Please insert the username of the account you want to withdraw from and the amount you want to withdraw."); Console.WriteLine("These are the available users:"); foreach (var item in users) { Console.WriteLine($"- {item}"); } Console.WriteLine("To withdraw the same amount to from all accounts type [all] in place of username."); Console.Write("Username: "******"Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); // if admin from all if (account.IsUserAdmin(username) && otherUsername.ToLower() == "all") { //Input validation for all Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; continue; } var suffBalance = true; foreach (var unames in users) { if (!account.HasSufficientBalance(unames, amount)) { message = "Insufficient account balance."; suffBalance = false; continue; } } if (!suffBalance) { message = "Insufficient account balance."; continue; } //Successful input Console.WriteLine("\nProcessing your request.."); account.WithdrawFromAll(username, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } //Input validation Console.WriteLine(); if (!account.IsUserValid(otherUsername)) { message = "User not found."; } else if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (username == otherUsername) { message = "Cannot withdraw from Cooperative's internal bank account."; } else if (!account.HasSufficientBalance(otherUsername, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.Withdraw(otherUsername, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
private static void Deposit(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - Deposit Menu"; Console.WriteLine($"User:{username}\tYou pressed 3. Deposit to user's bank account\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again."); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //available users var account = new InternalAccount(); var users = account.GetUsernames(); //deposit data input Console.WriteLine("Please insert the username of the account you want to deposit to and the amount you want to deposit."); Console.WriteLine("These are the available users:"); foreach (var item in users) { if (item != username) { Console.WriteLine($"- {item}"); } } if (account.IsUserAdmin(username)) { Console.WriteLine("To deposit the same amount to all accounts type [all] in place of username."); } Console.Write("Username: "******"Amount: "); var amountValidation = Decimal.TryParse(Console.ReadLine(), out decimal amount); //If admin and input all if (account.IsUserAdmin(username) && otherUsername.ToLower() == "all") { //Input validation for all var adminAmount = (users.Count - 1) * amount; Console.WriteLine(); if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; continue; } else if (!account.HasSufficientBalance(username, adminAmount)) { message = "Insufficient account balance."; continue; } //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAll(username, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } //Input validation for user Console.WriteLine(); if (!account.IsUserValid(otherUsername)) { message = "User not found."; } else if (amount <= 0 || !amountValidation) { message = "Invalid input. Insert a positive number as amount.."; } else if (username == otherUsername) { message = "Cannot deposit to your account."; } else if (account.IsUserAdmin(otherUsername)) { message = "Cannot deposit to Cooperative’s internal bank account. \nTo deposit to Cooperative’s internal bank account go back to Main Menu."; } else if (!account.HasSufficientBalance(username, amount)) { message = "Insufficient account balance."; } else { //Successful input Console.WriteLine("\nProcessing your request.."); account.DepositToAccount(username, otherUsername, amount, out string msg); memory.Add(msg); Thread.Sleep(500); DisplayResults(); return; } } }
private static void ViewAccounts(string username) { var message = ""; var i = 0; while (true) { Console.Clear(); Console.Title = "Internal Bank System - View user's Account"; Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\n"); //error messages if (i > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"{message} \nPlease try again.");// You have {tries} tries.\n"); Console.ForegroundColor = ConsoleColor.White; //------------------------------------------------------------------------------------------------ var key = Esc(); if (key.Key == ConsoleKey.Escape) { return; } //------------------------------------------------------------------------------------------------ } i++; //available users var account = new InternalAccount(); var users = account.GetUsernames(); //username input Console.WriteLine("Please insert the username of the account you want to view."); Console.WriteLine("These are the available users:"); foreach (var item in users) { Console.WriteLine($"- {item}"); } Console.WriteLine("To view all accounts type [all] in place of username."); Console.Write("Username: "******"all") { //success Console.WriteLine("\nProcessing your request.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\n"); Console.WriteLine("------------------------------------------------------------"); foreach (var item in users) { Console.WriteLine(account.ViewAccount(item)); Console.WriteLine("------------------------------------------------------------"); } GoToMainMenu(); return; } //input validation if (!users.Contains(otherUsername)) { message = "Invalid input. User not found."; } else { //success Console.WriteLine("\nProcessing your request.."); Thread.Sleep(500); Console.Clear(); Console.WriteLine($"User:{username}\tYou pressed 2. View user bank accounts\n"); Console.WriteLine("------------------------------------------------------------"); Console.WriteLine(account.ViewAccount(otherUsername)); Console.WriteLine("------------------------------------------------------------"); GoToMainMenu(); return; } } }
static void Main(string[] args) { Console.OutputEncoding = Encoding.Unicode; Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("el-GR"); var fmt = Thread.CurrentThread.CurrentCulture.DateTimeFormat; fmt.ShortDatePattern = @"yyyy-MM-dd"; fmt.LongTimePattern = @"HH:mm:ss.FFF"; Console.Title = "Internal Bank System"; //opening message Console.WriteLine("Opening Application..."); //check for database connectivity Console.Write("Opening connection to Database.. "); try { using (SqlConnection conn = new SqlConnection(connectionString)) // conn antikeimeno p antiproswpevei to connection me thn vash mas { conn.Open(); Console.WriteLine($"Connection state: {conn.State}"); } } catch (Exception) { Console.WriteLine("Connection error."); // You have {tries} tries.\n"); } Thread.Sleep(1000); //wait //Login Screen var username = LoginScreen.DisplayLogin(connectionString); if (string.IsNullOrEmpty(username)) { //Login fail --> Application closes Console.Clear(); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input. Application is closing.."); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine(); Console.WriteLine("Goodbye.."); } else { while (true) { //Display Menu var choice = Menu.DisplayMenu(username); bool admin = new InternalAccount().IsUserAdmin(username); var i = 0; Console.WriteLine(i++); //Display SubMenu switch (choice.Key) { case ConsoleKey.D1: { ViewMyAccount(username); } break; case ConsoleKey.D2: { if (admin) { ViewAccounts(username); } else { DepositToAdmin(username); } } break; case ConsoleKey.D3: { Deposit(username); } break; case ConsoleKey.D4: { if (admin) { WithdrawMenu(username); } else { //Send to file user SendToFile(username); } } break; case ConsoleKey.D5: { if (admin) { //sent to file admin SendToFile(username); } else { InvalidInput(); } } break; case ConsoleKey.Escape: { Exit(username); } break; default: { InvalidInput(); } break; } } } Console.ReadKey(); }
public static string DisplayLogin(string connectionString) { var message = ""; for (var tries = 3; tries > 0; tries--) { Console.Clear(); Console.Title = "Internal Bank System - Login"; Console.WriteLine(); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.DarkMagenta; Console.WriteLine("Welcome to the Internal Bank System of Cooperative Company !"); Console.BackgroundColor = ConsoleColor.Black; Console.ForegroundColor = ConsoleColor.White; //error messages if (tries < 3 && tries > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(); Console.WriteLine($"{message} Please try again. You have {tries} tries."); Console.ForegroundColor = ConsoleColor.White; } //username and password input Console.WriteLine(); Console.WriteLine("Enter your username and password to login to your account."); Console.Write("Username: "******"Password: "******"User not found."; } else if (!account.IsPasswordValid(username, password)) { message = "Invalid entry."; } else { //Successful login Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Login Successful!"); Console.ForegroundColor = ConsoleColor.White; System.Threading.Thread.Sleep(500); return(username); } } //after 3 fails application displays message and closes. return(null); }