private static void Search(DatabaseRepo _repo, BankLogic bankLogic, string searchPatern) { var result = _repo.AllCustomers().Where(x => x.Name.ToLower().Contains(searchPatern) || x.City.ToLower().Contains(searchPatern)).ToList(); if (!result.Any()) { Console.WriteLine("Nein nobody here"); } else { foreach (var item in result) { Console.WriteLine($"{item.CustomerId} : {item.Name}"); } } DrawStarLine(); Console.WriteLine(); Console.WriteLine("Search again press 0 else press 1"); var input = Console.ReadLine(); if (input == "0") { Console.WriteLine(); DrawStarLine(); Console.WriteLine(); Console.WriteLine("Search"); var result1 = Console.ReadLine(); Search(_repo, bankLogic, result1); } else { ClearAndReoload(_repo, bankLogic); } }
public string Transaction(DatabaseRepo _repo, int fromAccId, int toAccId, decimal amount) { var accounts = _repo.AllAccounts(); var fromAcc = accounts.FirstOrDefault(x => x.AccountId == fromAccId); var toAcc = accounts.FirstOrDefault(x => x.AccountId == toAccId); string result; if (CheckIfTransactionPossible(fromAcc, amount)) { fromAcc.Balance -= amount; toAcc.Balance += amount; _repo.CreateTransaction(new Transaction { Amount = amount, FromAccountId = fromAccId, ToAccountId = toAccId }); result = "Success"; } else { result = "Lol you are too poor "; } return(result); }
public EditDialogResponder(DatabaseRepo databaseRepo, LangResponse langResponse, SlackClient slackClient, ImageUtility imageUtility, ConfigService configService) : base(databaseRepo) { _langResponse = langResponse; _slackClient = slackClient; _imageUtility = imageUtility; _configService = configService; }
static void Main(string[] args) { var _repo = new DatabaseRepo(); var banklogic = new BankLogic(); _repo.ImportAllData(); DisplayMenu(_repo, banklogic); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; // Initialize the database on app creation DatabaseRepo.InitializeDB(); }
private static bool ValidateCustomerId(int customerId, DatabaseRepo repo) { while (ShowCustomer(repo, customerId) == null) { return(false); } return(true); }
public static void ShowMenu() { Console.Clear(); Console.WriteLine("\t\t Main menu\n " + "*********************************\n " + "0) Save and exit \n " + "1) Search for customer \n " + "2) Show Customer Report \n " + "3) Create new customer \n " + "4) Delete customer \n " + "5) Create new account \n " + "6) Delete account \n " + "7) Account overview \n\n\n"); DatabaseRepo.ShowStats(); var userInput = Console.ReadLine(); if (userInput == "0") { SaveNewFile.WhenChangesCreateNewFile(); } else if (userInput == "1") { DatabaseRepo.SearchCustomer(); } else if (userInput == "2") { DatabaseRepo.ShowCustomerReport(); } else if (userInput == "3") { DatabaseRepo.CreateNewCustomer(); } else if (userInput == "4") { DatabaseRepo.DeleteCustomer(); } else if (userInput == "5") { DatabaseRepo.CreateNewAccount(); } else if (userInput == "6") { DatabaseRepo.DeleteAccount(); } else if (userInput == "7") { AccountMenu.ShowAccountMenu(); } }
public void Deposit(decimal amount, int accountId, DatabaseRepo _Repo) { var account = _Repo.AllAccounts().FirstOrDefault(x => x.AccountId == accountId); if (amount > 0) { account.Balance += amount; } }
public void Withdraw(decimal amount, int accountId, DatabaseRepo _Repo) { var account = _Repo.AllAccounts().FirstOrDefault(x => x.AccountId == accountId); if (amount > 0 && account.Balance >= amount) { account.Balance -= amount; } }
private static void ClearAndReoload(DatabaseRepo _repo, BankLogic bankLogic) { DrawStarLine(); Console.WriteLine("Press any key to continue"); Console.ReadKey(); Console.Clear(); Console.Beep(); DisplayMenu(_repo, bankLogic); }
public async Task Test_DatabaseRepo_GettingNoteInTheDatabase() { DatabaseRepo.InitializeDB(); LocalNote.Models.NoteModel note = new LocalNote.Models.NoteModel("THIS IS THE TITLE", new LocalNote.Models.ContentModel("THERE IS CONTENT NOW", "THERE IS CONTENT NOW")); var actual = await DatabaseRepo.GetNote(note.Title); Assert.IsTrue(note == actual); }
public void CompareSavedQueryMetaDatabase() { var fileRepo = new FileCompareRepo(); var compareResultModelList = new List <CompareResultModel>(); var savedQueryMetaCompareResultModel = new List <SavedQueryMetaCompareResultModel>(); var connstring1 = _appSettingsHandler.ReadSetting("SavedQueryConnectionString1"); var connstring2 = _appSettingsHandler.ReadSetting("SavedQueryConnectionString2"); var compareResultFile = _appSettingsHandler.ReadSetting("CompareSavedQueryResultFile"); var resultFolder1 = _appSettingsHandler.ReadSetting("ResultFolder1") + "/SavedQueryMeta/"; var resultFolder2 = _appSettingsHandler.ReadSetting("ResultFolder2") + "/SavedQueryMeta/"; ; fileRepo.DeleteAllFilesInFolder($"{resultFolder1}"); fileRepo.DeleteAllFilesInFolder($"{resultFolder2}"); var repo = new DatabaseRepo(); var savedQueries = repo.GetSavedQueries(connstring1, 10); foreach (var savedQuery in savedQueries) { var savedQueryResult1 = repo.GetSavedQueryById(savedQuery, connstring1); var savedQueryResult2 = repo.GetSavedQueryById(savedQuery, connstring2); if (savedQueryResult1 != string.Empty && savedQueryResult2 != string.Empty) { _savedQueryService.SaveToFile(savedQueryResult1, savedQuery, "SavedQueryMeta", $"{resultFolder1}\\{savedQuery}\\"); _savedQueryService.SaveToFile(savedQueryResult2, savedQuery, "SavedQueryMeta", $"{resultFolder2}\\{savedQuery}\\"); var result = CompareSavedQueryResults( $@"{resultFolder1}\{savedQuery}\{savedQuery}_SavedQueryMeta.txt", $@"{resultFolder2}\{savedQuery}\{savedQuery}_SavedQueryMeta.txt"); savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel() { Id = savedQuery, Result = result }); } else { savedQueryMetaCompareResultModel.Add(new SavedQueryMetaCompareResultModel() { Id = savedQuery, Result = null }); } } fileRepo.DeleteFile(compareResultFile); fileRepo.SaveToFile(savedQueryMetaCompareResultModel, compareResultFile); }
public async Task Test_DatabaseRepo_AddingNoteInTheDatabase() { DatabaseRepo.InitializeDB(); LocalNote.Models.NoteModel noteToBeAdded = new LocalNote.Models.NoteModel("THIS IS THE TITLE", new LocalNote.Models.ContentModel("NO CONTENT FOR YOU", "NO CONTENT FOR YOU")); DatabaseRepo.AddNote(noteToBeAdded); var actual = await DatabaseRepo.GetNote("THIS IS THE TITLE"); Assert.IsTrue(noteToBeAdded == actual); }
public async Task Test_DatabaseRepo_DeletingNoteInTheDatabase() { DatabaseRepo.InitializeDB(); LocalNote.Models.NoteModel noteToBeDeleted = new LocalNote.Models.NoteModel("THIS IS THE TITLE", new LocalNote.Models.ContentModel("THERE IS CONTENT NOW", "THERE IS CONTENT NOW")); DatabaseRepo.DeleteNote(noteToBeDeleted); var actual = await DatabaseRepo.GetNote("THIS IS THE TITLE"); Assert.IsNull(actual); }
protected override async Task <ISlackDialogResponse> Respond(SlackDialogPayload payload, MemeMessage message, Response response) { if (payload == null) { throw new ArgumentNullException(nameof(payload)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (response == null) { throw new ArgumentNullException(nameof(response)); } var text = new StringBuilder(); for (int i = 0; true; i++) { if (!payload.Submission.TryGetValue($"line{i}", out var value)) { break; } if (i > 0) { text.Append("; "); } text.Append(value); } var isAnonymous = Boolean.Parse(payload.Submission["isAnonymous"]); var template = await _configService.GetTemplate(message.TemplateId, message.UserId); var imageUrl = await _imageUtility.GetImageUrl(text.ToString(), template); var updatedMessage = await DatabaseRepo.UpdatePreview( id : message.Id, templateId : message.TemplateId, message : text.ToString(), imageUrl : imageUrl, isAnonymous : isAnonymous); var slackMessage = await _langResponse.RenderPreview(updatedMessage); slackMessage.ReplaceOriginal = true; await _slackClient.SendMessageResponse(response.ResponseUrl, slackMessage); await DatabaseRepo.DeleteResponse(response.Id); return(new SlackEmptyResponse()); }
/// <summary> /// Returns the retrieved movies information by an Id /// </summary> /// <param name="dbRepo">The movie database to search from</param> /// <param name="id">The Movie Id</param> /// <returns></returns> public IHttpActionResult GetById(DatabaseRepo dbRepo, string id) { AggregatedModel aggregatedModel; switch (dbRepo) { case DatabaseRepo.Tmdb: aggregatedModel = _tmdbConnection.GetMovieById(id); aggregatedModel.YoutubeResults = _youtubeConnection.RetrieveData(aggregatedModel.MovieResults.FirstOrDefault()?.Title); return(Json(new { Results = aggregatedModel })); case DatabaseRepo.Omdb: aggregatedModel = _omdbConnection.GetMovieById(id); aggregatedModel.YoutubeResults = _youtubeConnection.RetrieveData(aggregatedModel.MovieResults.FirstOrDefault()?.Title); return(Json(new { Results = aggregatedModel })); default: throw new Exception("Incorret DB Type"); } }
public static void ShowAccountMenu() { Console.Clear(); Console.WriteLine("Account overview\n\n " + "1) Withdraw \n " + "2) Insert \n " + "3) Transformer \n " + "9) Back to menu"); var userInput = Console.ReadLine(); if (userInput == "9") { MainMenu.ShowMenu(); } else { DatabaseRepo.Transactions(userInput); } }
/// <summary> /// Returns list of movies and youtube result by Id /// </summary> /// <param name="dbRepo">The movie database to search from</param> /// <param name="title">The Movie Title</param> /// <returns>AggregatedModel</returns> public AggregatedModel GetByTitle(DatabaseRepo dbRepo, string title, string page = "1") { AggregatedModel aggregatedModel; switch (dbRepo) { case DatabaseRepo.Tmdb: aggregatedModel = _tmdbConnection.GetMovieByTitle(title, page); aggregatedModel.YoutubeResults = _youtubeConnection.RetrieveData(title, page); aggregatedModel.RelevanceType = MovieRelevance.Search; return(aggregatedModel); case DatabaseRepo.Omdb: aggregatedModel = _omdbConnection.GetMovieByTitle(title, page); aggregatedModel.YoutubeResults = _youtubeConnection.RetrieveData(title, page); aggregatedModel.RelevanceType = MovieRelevance.Search; return(aggregatedModel); default: throw new Exception("Incorret DB Type"); } }
private static bool ValidateAccountId(int accountId, DatabaseRepo repo) { var account = repo.AllAccounts().Find(x => x.AccountId == accountId); return(account != null && account.Balance == 0); }
public static void DisplayMenu(DatabaseRepo _repo, BankLogic bankLogic) { DrawStarLine(); Console.WriteLine("* Welcome to ElPaplito, the worst bank in the world! *"); DrawStarLine(); Console.WriteLine("Importing from " + _repo.GetCurrentTextFile()); Console.WriteLine("Total Customers: " + _repo.AllCustomers().Count); Console.WriteLine("Total Accounts: " + _repo.AllAccounts().Count); Console.WriteLine("Total balance: " + _repo.AllAccounts().Sum(x => x.Balance)); Console.WriteLine("Press any key to continue..."); Console.ReadLine(); Console.WriteLine("0. Search"); Console.WriteLine("1. Show customer"); Console.WriteLine("2. Withdraw"); Console.WriteLine("3. Deposit"); Console.WriteLine("4. Transaction"); Console.WriteLine("5. Exit and save"); Console.WriteLine("6. Create customer"); Console.WriteLine("7. Delete customer"); Console.WriteLine("8. Create account"); Console.WriteLine("9. Delete account"); Console.Write("Enter your choice: "); var userChoice = Console.ReadLine(); if (userChoice == "0") { Console.WriteLine(); Console.WriteLine("Search:"); var result = Console.ReadLine(); Search(_repo, bankLogic, result.ToLower()); } else if (userChoice == "1") { Console.WriteLine(); Console.WriteLine("CustomerId:"); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } var result = ShowCustomer(_repo, customerId); Console.WriteLine("CustomerId: " + result.CustomerId); Console.WriteLine("Orginisation: " + result.OrginisationNumber); Console.WriteLine("Name: " + result.Name); Console.WriteLine("Adress: " + result.Adress + " Zipcode: " + result.ZipCode + " City: " + result.City + " Country: " + result.Country); Console.WriteLine(); var accs = bankLogic.GetCustomersAccounts(customerId, _repo.AllAccounts()); if (accs.Count == 0) { Console.Write("This customer does not have any accounts."); } else { decimal total = 0; foreach (var acc in accs) { total += acc.Balance; Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Total balance: " + total); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "2") { Console.WriteLine(); Console.WriteLine("CustomerId: "); var fromCusId = Int32.Parse(Console.ReadLine()); while (_repo.AllCustomers().FirstOrDefault(x => x.CustomerId == fromCusId) == null) { Console.WriteLine("Could not find any customer, try again..."); fromCusId = Int32.Parse(Console.ReadLine()); } var cusAccs = bankLogic.GetCustomersAccounts(fromCusId, _repo.AllAccounts()); foreach (var acc in cusAccs) { Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Which account?"); var fromAccId = Int32.Parse(Console.ReadLine()); var fromAcc = _repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId); while (_repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId) == null) { Console.WriteLine("Could not find account, try again..."); fromAccId = Int32.Parse(Console.ReadLine()); } Console.WriteLine("Amount:"); var amount = (Console.ReadLine()); if (amount.Contains("-") || decimal.Parse(amount) > fromAcc.Balance) { Console.WriteLine("Withdraw failed!"); } else { bankLogic.Withdraw(decimal.Parse(amount), fromAccId, _repo); } Console.WriteLine("You now have " + fromAcc.Balance + "$ left!"); Console.ReadKey(); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "3") { Console.WriteLine(); Console.WriteLine("CustomerId: "); var fromCusId = Int32.Parse(Console.ReadLine()); while (_repo.AllCustomers().FirstOrDefault(x => x.CustomerId == fromCusId) == null) { Console.WriteLine("Could not find any customer, try again..."); int.TryParse(Console.ReadLine(), out fromCusId); Console.WriteLine("CustomerId: "); fromCusId = Int32.Parse(Console.ReadLine()); } var cusAccs = bankLogic.GetCustomersAccounts(fromCusId, _repo.AllAccounts()); foreach (var acc in cusAccs) { Console.Write("Account: " + acc.AccountId); Console.WriteLine(" Balance: " + acc.Balance); } Console.WriteLine("Which account?"); var fromAccId = Int32.Parse(Console.ReadLine()); var fromAcc = _repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId); while (_repo.AllAccounts().FirstOrDefault(x => x.AccountId == fromAccId) == null) { Console.WriteLine("Could not find account, try again..."); int.TryParse(Console.ReadLine(), out fromAccId); Console.WriteLine("AccountId: "); fromAccId = Int32.Parse(Console.ReadLine()); } Console.WriteLine("Amount:"); var amount = (Console.ReadLine()); if (amount.Contains("-")) { Console.WriteLine("No negative number are allowed"); } else { bankLogic.Deposit(decimal.Parse(amount), fromAccId, _repo); } Console.WriteLine("You now have " + fromAcc.Balance + "$ on your account!"); Console.ReadKey(); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "4") { int fromAcc = 0; int toAcc = 0; Console.WriteLine(); Console.WriteLine("Transaction"); Console.WriteLine(); Console.WriteLine("From Account: Enter Account id"); Console.WriteLine(); while (!int.TryParse(Console.ReadLine(), out fromAcc)) { Console.WriteLine("Please Enter a valid account id!"); } Console.WriteLine(); Console.WriteLine("To Account: Enter Account id"); Console.WriteLine(); while (!int.TryParse(Console.ReadLine(), out toAcc)) { Console.WriteLine("Please Enter a valid account id!"); } Console.WriteLine(); Console.WriteLine("Enter amount: "); Console.WriteLine(); decimal amount = decimal.Parse(Console.ReadLine()); var result = bankLogic.Transaction(_repo, fromAcc, toAcc, amount); if (result == "Success") { Console.WriteLine($"Successful transaction. Transfered: {amount}$ from account: {fromAcc} to account: {toAcc}"); } else { Console.WriteLine("Failed transaction"); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "5") { Console.WriteLine(); Console.WriteLine("Exit and save"); _repo.SaveDateToTextFile(); Console.WriteLine("Info has been saved to: " + _repo.GetCurrentTextFile()); Console.WriteLine(); Console.WriteLine("Total Customers: " + _repo.AllCustomers().Count); Console.WriteLine("Total Accounts: " + _repo.AllAccounts().Count); Console.WriteLine("Total balance:" + _repo.AllAccounts().Sum(x => x.Balance)); Thread.Sleep(5000); Environment.Exit(0); } else if (userChoice == "6") { int orgNo = 0; Console.WriteLine(); Console.WriteLine("Create customer:"); Console.WriteLine(); Console.WriteLine("Name:"); var name = Console.ReadLine(); while (String.IsNullOrEmpty(name)) { Console.WriteLine("Please enter a valid Name"); name = Console.ReadLine(); } Console.WriteLine("Organisation number:"); while (!int.TryParse(Console.ReadLine(), out orgNo)) { Console.WriteLine("Please Enter a valid numerical value!"); Console.WriteLine("Please Enter an ID number:"); } Console.WriteLine("Adress:"); var adress = Console.ReadLine(); while (String.IsNullOrEmpty(adress)) { Console.WriteLine("Please enter a valid Adress"); adress = Console.ReadLine(); } Console.WriteLine("City:"); var city = Console.ReadLine(); while (String.IsNullOrEmpty(city)) { Console.WriteLine("Please enter a valid city"); city = Console.ReadLine(); } Console.WriteLine("State:"); var state = Console.ReadLine(); Console.WriteLine("ZipCode:"); var zipcode = Console.ReadLine(); while (String.IsNullOrEmpty(zipcode)) { Console.WriteLine("Please enter a valid zipcode"); zipcode = Console.ReadLine(); } Console.WriteLine("Country:"); var country = Console.ReadLine(); while (String.IsNullOrEmpty(country)) { Console.WriteLine("Please enter a valid country"); country = Console.ReadLine(); } Console.WriteLine("Phone:"); var phone = Console.ReadLine(); while (String.IsNullOrEmpty(phone)) { Console.WriteLine("Please enter a valid phone"); phone = Console.ReadLine(); } var result = _repo.CreateCustomer(name, adress, phone, city, country, zipcode, orgNo.ToString(), state); if (result) { DrawStarLine(); Console.WriteLine("Customer added dount forget to save!"); ClearAndReoload(_repo, bankLogic); } else { Console.WriteLine("Shit happens try again"); Console.WriteLine(); ClearAndReoload(_repo, bankLogic); } } else if (userChoice == "7") { Console.WriteLine(); Console.WriteLine("Delete customer"); Console.WriteLine(); Console.WriteLine("Enter CustomerId: "); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } if (bankLogic.ValidateDeleteCustomer(customerId, _repo.AllAccounts()) == false) { Console.WriteLine("CanĀ“t delete customer, customer still have money left!"); Console.WriteLine("Press any key to continue..."); Console.ReadKey(); } else { _repo.DeleteCustomer(customerId); Console.WriteLine("Customer deleted, dount forget to save"); Console.WriteLine(); } ClearAndReoload(_repo, bankLogic); } else if (userChoice == "8") { Console.WriteLine(); Console.WriteLine("Create account"); Console.WriteLine(); Console.WriteLine("Enter CustomerId: "); int customerId; int.TryParse(Console.ReadLine(), out customerId); while (ValidateCustomerId(customerId, _repo) == false) { Console.WriteLine("Could not find any customer, try again..."); Console.WriteLine("Press any key to try again"); int.TryParse(Console.ReadLine(), out customerId); } _repo.CreateAccount(customerId); Console.WriteLine("Your account has been created"); ClearAndReoload(_repo, bankLogic); } else if (userChoice == "9") { Console.WriteLine(); Console.WriteLine("Delete account"); Console.WriteLine(); Console.WriteLine("Enter Account id: "); int accountId; int.TryParse(Console.ReadLine(), out accountId); while (ValidateAccountId(accountId, _repo) == false) { Console.WriteLine("ERROR! Invalid accountId or account still have money"); DisplayMenu(_repo, bankLogic); int.TryParse(Console.ReadLine(), out accountId); } _repo.DeleteAccount(accountId); Console.WriteLine("Account deleted"); ClearAndReoload(_repo, bankLogic); } Console.ReadLine(); }
public DashboardController(DatabaseRepo database, DashboardRepo dashboardRepo) { this.database = database; this.dashboardRepo = dashboardRepo; }
public LoginController(DatabaseRepo repo) { this.repo = repo; }
public FirstAidController(DatabaseRepo repo) { this.repo = repo; }
public async Task Test_DatabaseRepo_GettingNoteInTheDatabase_WhenTitleIsNull() { DatabaseRepo.InitializeDB(); await DatabaseRepo.GetNote(null); }
public HospitalController(DatabaseRepo repo) { this.repo = repo; }
public AnatomyController(DatabaseRepo repo) { this.repo = repo; }
private static Customer ShowCustomer(DatabaseRepo _repo, int customerId) { return(_repo.AllCustomers().FirstOrDefault(x => x.CustomerId == customerId)); }
public void Test_DatabaseRepo_DeletingNoteInTheDatabase_WhenNoteIsNull() { DatabaseRepo.InitializeDB(); LocalNote.Models.NoteModel noteToBeAdded = null; DatabaseRepo.DeleteNote(noteToBeAdded); }
public DiseaseController(DatabaseRepo repo) { this.repo = repo; }
public HealthController(DatabaseRepo databaseRepo, ILogger <HealthController> logger, SlackClient slackClient) { _databaseRepo = databaseRepo; _logger = logger; _slackClient = slackClient; }