public bool ExchangeMoney(int accountSrcId, int accountDstId, int MoneyAmount) { // it's rigth to throw exceptions but it's more clear and easy to deal with without throw and with bool var accSrc = BankSystem.GetAccountById(accountSrcId); var accDst = BankSystem.GetAccountById(accountDstId); if (!this.accountsIds.Contains(accountSrcId)) { return(false); } if (accSrc == null || accDst == null) { return(false); } if (accSrc.DecreaseAmount(MoneyAmount)) { accDst.IncreaseAmount(MoneyAmount); } else { return(false); } return(true); }
//Case 6 static void CaseDeleteAccount(BankSystem bankSystem) { bool successfullyParsedAccountId; do { Console.WriteLine(); Console.WriteLine("> 6"); Console.WriteLine("* Ta bort konto *"); Console.Write("Kontonummer: "); var inputAccountId = Console.ReadLine(); successfullyParsedAccountId = int.TryParse(inputAccountId, out int accountId); if (successfullyParsedAccountId) { var response = bankSystem.accountManagement.Delete(accountId); Console.WriteLine(response ? "Kontot borttaget." : "Saldot på kontot är ej noll, går ej att radera."); } else { Console.WriteLine("Felaktigt nummer, kontrollera att du skrivit in rätt kontonummer."); Console.WriteLine("Tryck 0 för att komma till menyn annars tryck enter för att försöka igen."); if (Console.ReadKey(true).KeyChar == '0') { break; } } } while (!successfullyParsedAccountId); }
//Case 3 static void CaseCreateCustomer(BankSystem bankSystem) { Console.WriteLine("> 3"); Console.WriteLine("* Skapa kund *"); Console.Write("Namn: "); var inputCustomerName = Console.ReadLine(); Console.Write("Personnummer: "); var inputCustomerLegalId = Console.ReadLine(); Console.Write("Adress: "); var inputCustomerAddress = Console.ReadLine(); Console.Write("Postkod: "); var inputCustomerZipCode = Console.ReadLine(); Console.Write("Ort: "); var inputCustomerCity = Console.ReadLine(); Console.Write("Region: "); var inputCustomerRegion = Console.ReadLine(); Console.Write("Land: "); var inputCustomerCountry = Console.ReadLine(); Console.Write("Telefonnummer: "); var inputCustomerPhoneNumber = Console.ReadLine(); var newCustomer = bankSystem.customerManagement.Create(inputCustomerName, inputCustomerLegalId, inputCustomerAddress, inputCustomerZipCode, inputCustomerCity, inputCustomerRegion, inputCustomerCountry, inputCustomerPhoneNumber); Console.WriteLine(newCustomer ? "Användaren skapad" : "Användare ej skapad"); }
//Case 4 static void CaseDeleteCustomer(BankSystem bankSystem) { bool successfullyParsed; do { Console.WriteLine(); Console.WriteLine("> 4"); Console.WriteLine("* Ta bort kund *"); Console.Write("Kundnummer: "); var inputCustomerId = Console.ReadLine(); successfullyParsed = int.TryParse(inputCustomerId, out int deletedCustomerId); if (successfullyParsed) { if (bankSystem.customerManagement.Delete(deletedCustomerId)) { Console.WriteLine("Kunden " + deletedCustomerId + " är borttagen."); } else { Console.WriteLine("Felaktigt kundnummer"); } } else { Console.WriteLine("Felaktig inmatning"); Console.WriteLine("Tryck 0 för att komma till menyn annars tryck enter för att försöka igen."); if (Console.ReadKey(true).KeyChar == '0') { break; } } } while (!successfullyParsed); }
public async Task <ActionResult <BankSystem> > PostBankSystem(BankSystem bankSystem) { _context.BankSystem.Add(bankSystem); await _context.SaveChangesAsync(); return(CreatedAtAction("GetBankSystem", new { id = bankSystem.Id }, bankSystem)); }
public async Task <IActionResult> PutBankSystem(int id, BankSystem bankSystem) { if (id != bankSystem.Id) { return(BadRequest()); } _context.Entry(bankSystem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BankSystemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CanCreateTransaction() { var repo = FileRepository.Instance; var service = new FileService(); const string path = @".\Files\bankdata-small.txt"; service.TransformFileToRepo(repo, path); var sut = new BankSystem(repo); var fromAccountNo = 13130; var toAccountNo = 13020; Assert.False( sut.transactionManagement.CreateTransaction(fromAccountNo, toAccountNo, 5000)); Assert.False( sut.transactionManagement.CreateTransaction(fromAccountNo, toAccountNo, -500)); Assert.True( sut.transactionManagement.CreateTransaction(fromAccountNo, toAccountNo, 500)); var allAccounts = sut.accountManagement.AllAccounts(); var account1 = allAccounts.Single(x => x.AccountId == fromAccountNo); var account2 = allAccounts.Single(x => x.AccountId == toAccountNo); Assert.Equal(4307.00m, account1.Balance); Assert.Equal(1113.20m, account2.Balance); }
public bool ExchangeMoney(int accountSrcId, int accountDstId, int MoneyAmount) { var accSrc = BankSystem.GetAccountById(accountSrcId); var accDst = BankSystem.GetAccountById(accountDstId); if (!this.accountsIds.Contains(accountSrcId)) { return(false); } if (accSrc == null || accDst == null) { return(false); } if (accSrc.DecreaseAmount(MoneyAmount)) { accDst.IncreaseAmount(MoneyAmount); } else { return(false); } return(true); }
public void Test3() { var masterCard = BankSystem.Status(); var tinkoff = new Bank("Тинькофф", 0.0365, 365, 0.1, 5000); var sber = new Bank("Сбер", 0.03, 730, 0.15, 6000); masterCard.AddBank(tinkoff); masterCard.AddBank(sber); var builder = new ClientBuilder(); builder.SetName("Егор"); builder.SetSurname("Колобов"); builder.SetAddress("Санкт-Петербург"); builder.SetPassportID(228666420); var me = builder.GetClient(); builder.SetName("Друг"); builder.SetSurname("Хороший"); builder.SetAddress("Санкт-Петербург"); builder.SetPassportID(1488691337); var friend = builder.GetClient(); me.AddAccount("Тинькофф", "deposit", 100000); friend.AddAccount("Сбер", "debit", 500000); friend.Transfer("Сбер", friend.AccountId[0], me.AccountId[0], 250000); Assert.AreEqual(350000, me.Info("Тинькофф", me.AccountId[0])); Assert.AreEqual(250000, friend.Info("Сбер", friend.AccountId[0])); }
public void Test1() { var masterCard = BankSystem.Status(); var tinkoff = new Bank("Тинькофф", 0.0365, 365, 0.1, 5000); masterCard.AddBank(tinkoff); var builder = new ClientBuilder(); builder.SetName("Егор"); builder.SetSurname("Колобов"); builder.SetAddress("Санкт-Петербург"); builder.SetPassportID(228666420); var me = builder.GetClient(); me.AddAccount("Тинькофф", "debit", 100000); // 100 000, Bonus = 0 masterCard.DailyUpdate(); // Bonus += 10 me.Replenishment("Тинькофф", me.AccountId[0], 100000); // + 100 000 = 200 00 masterCard.DailyUpdate(); // Bonus += 20 me.Withdrawal("Тинькофф", me.AccountId[0], 150000); // - 150 000 = 50 000 masterCard.DailyUpdate(); // Bonus += 5 masterCard.MonthUpdate(); // 50 000 + Bonus = 50 000 + 35 = 50 035 Assert.AreEqual(50035, me.Info("Тинькофф", me.AccountId[0])); }
public void TestTransferTo(double money) { List <Client> clients = new List <Client>(); clients.Add(new NotVerifiedClient("Ринат")); clients[0] = clients[0].GivePassportId(1); clients[0] = clients[0].GiveAddress("Ленинградский"); clients.Add(new NotVerifiedClient("Максим")); clients[1] = clients[1].GivePassportId(2); clients[1] = clients[1].GiveAddress("Ленинградский"); clients.Add(new NotVerifiedClient("Влад")); clients[2] = clients[2].GivePassportId(3); clients[2] = clients[2].GiveAddress("Ленинградский"); clients.Add(new NotVerifiedClient("Сергей")); Date date1 = new Date(1, 2, 2021); BankSystem bankSystem = BankSystem.getInstance(date1); bankSystem.AddBank("Сбербанк", 3, 10, 3, 3.5, 4, 50000, date1); bankSystem.AddBank("Газпромбанк", 5, 9, 3, 3.5, 4, 100000, date1); bankSystem.AddAccount("Сбербанк", clients[0], "DebitAccount", 150000); //1 bankSystem.AddAccount("Сбербанк", clients[1], "CreditAccount", 200000); //2 bankSystem.AddAccount("Газпромбанк", clients[1], "DepositAccount", 250000); //3 bankSystem.AddAccount("Газпромбанк", clients[2], "DebitAccount", 300000); //4 bankSystem.AddAccount("Газпромбанк", clients[3], "CreditAccount", 350000); //5 bankSystem.AddAccount("Газпромбанк", clients[3], "DepositAccount", 400000); //6 bankSystem.AddAccount("Сбербанк", clients[3], "DebitAccount", 450000); //7 double expected = clients[1].Accounts[0].Money + money; bankSystem.Transfer(1, 2, money); double actual = clients[1].Accounts[0].Money; Assert.AreEqual(expected, actual); }
public void CanCreateAccount() { var repo = FileRepository.Instance; var sut = new BankSystem(repo); var acc = sut.accountManagement.Create(1); Assert.True(acc); }
public void CanDeleteAccount() { var repo = FileRepository.Instance; var sut = new BankSystem(repo); var acc = sut.accountManagement.Create(1000); var del = sut.accountManagement.Delete(1001); Assert.True(del); }
static void Main(string[] args) { // hardcode (i just didnt want to think about db or any files with data =) ) Account acc1 = Account.CreateAccount(100, "uah"); // id 1 Account acc2 = Account.CreateAccount(5454, "uah"); // 2 Account acc3 = Account.CreateAccount(200, "usd"); // . Account acc4 = Account.CreateAccount(123, "uah"); // . Account acc5 = Account.CreateAccount(1, "usd"); Account acc6 = new Account(); // this acc is not added to bank system initially Account acc7 = new Account(); // so we add explisitly BankSystem.AddAccounts(new Account[] { acc6, acc7 }); // head od hierarchy // basic user with no power User basicUser = new User(1, "Andrii", "Koval", "login", "password"); //bank client is able to have bank accounts Console.WriteLine("---------------------Creatinh Bank Client"); BankClient client = BankClient.CreateBankClient(); Console.WriteLine("---------------------Creatinh Bank Client"); // a piece of hardcode ((( client.AddAccountId(acc1.id); client.AddAccountId(acc3.id); client.AddAccountId(acc5.id); client.ShowInfo(); Console.WriteLine("---------------------Creatinh Bank Exmployee"); BankEmployee employee = BankEmployee.CreateBankEmployee(); Console.WriteLine("---------------------Creating Bank Exmployee"); BankSystem.AddUser(employee); BankSystem.AddUser(client); BankSystem.AddUser(basicUser); Console.WriteLine("\n------------------------------------All users in system"); foreach (var user in BankSystem.Users.Values) { user.ShowInfo(); } Console.WriteLine("------------------------------------All users in system\n"); acc1.IncreaseAmount(100); acc3.IncreaseAmount(100); acc5.DecreaseAmount(50000); client.ShowInfo("CLIENT OVERRIDEN METHOD", "CLIENT OVERRIDEN METHOD"); Console.WriteLine(employee.systemUsersCount); }
public void CanSearchForCustomer() { var repo = FileRepository.Instance; var system = new BankSystem(repo); system.customerManagement.Create("Kalle Kallesson", "801010-1010", "Långgatan 1", "11122", "Huvudsta", "Stockholm", "Sverige", "010111222"); var customers = system.customerManagement.Search("Kalle"); Assert.Single(customers); }
//Case 9 static void CaseTransaction(BankSystem bankSystem) { Console.WriteLine("> 9"); Console.WriteLine("* Överföring *"); int inputFromAccount = -1; while (inputFromAccount == -1) { Console.Write("Från? "); try { inputFromAccount = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("Ogiltigt kontonummer"); } } int inputToAccount = -1; while (inputToAccount == -1) { Console.Write("Till? "); try { inputToAccount = Convert.ToInt32(Console.ReadLine()); } catch { Console.WriteLine("Ogiltigt kontonummer"); } } decimal inputAmount = 0m; while (inputAmount == 0m) { Console.Write("Belopp? "); try { inputAmount = Decimal.Parse(Console.ReadLine(), CultureInfo.InvariantCulture); } catch { Console.WriteLine("Ogiltig summa"); } } var transactionResult = bankSystem.transactionManagement.CreateTransaction(inputFromAccount, inputToAccount, inputAmount); Console.WriteLine(transactionResult ? "Transaktion klar" : "Transaktion misslyckad"); }
public ActionResult DecreaseAmount(int id, int MoneyAmount) { try { var acc = BankSystem.GetAccountById(id); acc.DecreaseAmount(MoneyAmount); } catch { return(Redirect("/")); } return(Redirect("/Accounts")); }
public void CanGetAllAccounts() { var repo = FileRepository.Instance; var sut = new BankSystem(repo); var acc = sut.accountManagement.Create(1000); var acc2 = sut.accountManagement.Create(1001); var acc3 = sut.accountManagement.Create(1002); var acc4 = sut.accountManagement.Create(1003); var list = sut.accountManagement.AllAccounts(); Assert.Equal(4, list.Count); }
public ActionResult ChangeCurrency(int id, string Currency) { try { var acc = BankSystem.GetAccountById(id); acc.Currency = Currency; } catch { return(Redirect("/")); } return(Redirect("/Accounts")); }
public void NewCustomerGetsAValidId() { var repo = FileRepository.Instance; var system = new BankSystem(repo); var service = new FileService(); const string path = @".\Files\bankdata-small.txt"; service.TransformFileToRepo(repo, path); system.customerManagement.Create("Kalle Kallesson", "801010-1010", "Långgatan 1", "11122", "Huvudsta", "Stockholm", "Sverige", "010111222"); Assert.Equal(1033, system.customerManagement.AllCustomers().LastOrDefault()?.CustomerId); }
public void CanDeleteCustomer() { var repo = FileRepository.Instance; var system = new BankSystem(repo); system.customerManagement.Create("Kalle Kallesson", "801010-1010", "Långgatan 1", "11122", "Huvudsta", "Stockholm", "Sverige", "010111222"); system.customerManagement.Create("Micke Makaroni", "760219-4117", "Gatan 1", "11352", "Rinkeby", "Stockholm", "Sverige", "0732185733"); system.customerManagement.Create("John Doe", "990419-5748", "Lincoln St. 3465", "34621", "Manhattan", "New York", "USA", "9675483922"); system.customerManagement.Delete(1002); var customers = system.customerManagement.AllCustomers(); Assert.Equal(2, customers.Count); }
public void CetCustomerByCustomerId() { NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetCustomers().AddRange(representation.Customers); BankSystem sut = new BankSystem(fakeProvider); sut.Initialize(); var result1 = sut.GetCustomerById("1"); Assert.Throws <NullReferenceException>(() => sut.GetCustomerById("0")); Assert.Equal(1, result1.CustomerId); }
void PopulateBankInformation() { TempBankDetails.AccountName = Name; TempBankDetails.AccountNumber = StringGenerator.RandomNumberChar(9, 9); TempBankDetails.AccountPass = StringGenerator.RandomMixedChar(6, 12); TempBankDetails.BankIP = "127.0.0.1"; TempBankDetails.BankName = "LEC Bank"; TempBankDetails.CreditRating = 1; TempBankDetails.Loan = 0; TempBankDetails.LoanIntrest = 1; TempBankDetails.AccountIntrest = Random.Range(0, 5); TempBankDetails.AccountBalance = Random.Range(0, 50000); TempBankDetails = new BankSystem(TempBankDetails.AccountName, TempBankDetails.AccountNumber, TempBankDetails.AccountPass, TempBankDetails.BankIP, TempBankDetails.BankName, TempBankDetails.CreditRating, TempBankDetails.Loan, TempBankDetails.LoanIntrest, TempBankDetails.AccountIntrest, TempBankDetails.AccountBalance); }
public PeopleSystem(string name, string personid, string phonenumber, string ipaddress, string maritalstatus, string personalstatus, int iq, Texture2D photo, DOBSystem dob, CollageSystem collage, UniversitySystem university, BankSystem bankdetails, GatewaySystem gateway) { Name = name; PersonID = personid; PhoneNumber = phonenumber; IPAddress = ipaddress; MaritalStatus = maritalstatus; PersonalStatus = personalstatus; IQ = iq; Photo = photo; DOB = dob; Collage = collage; University = university; BankDetails = bankdetails; Gateway = gateway; }
//Case 5 static void CaseCreateAccount(BankSystem bankSystem) { bool successfullyParsed; do { Console.WriteLine(); Console.WriteLine("> 5"); Console.WriteLine("* Skapa konto *"); Console.Write("Kundnummer: "); var inputCustomerId = Console.ReadLine(); successfullyParsed = int.TryParse(inputCustomerId, out int customerId); if (successfullyParsed) { var customer = bankSystem.customerManagement.GetCustomer(customerId); if (customer != null) { var result = bankSystem.accountManagement.Create(customerId); Console.WriteLine(result ? $"Nytt konto för kundnummer {customerId} skapat." : "Nåt gick fel, försök igen"); } else { Console.WriteLine(); Console.WriteLine("Felaktigt kundnummer"); Console.WriteLine("Tryck 0 för att komma till menyn annars tryck enter för att försöka igen."); if (Console.ReadKey(true).KeyChar == '0') { break; } } } else { Console.WriteLine(); Console.WriteLine("Felaktig inmatning"); Console.WriteLine("Tryck 0 för att komma till menyn annars tryck enter för att försöka igen."); if (Console.ReadKey(true).KeyChar == '0') { break; } } } while (!successfullyParsed); }
public void Test4() { var masterCard = BankSystem.Status(); var tinkoff = new Bank("Тинькофф", 0.0365, 365, 0.1, 5000); masterCard.AddBank(tinkoff); var builder = new ClientBuilder(); builder.SetName("Егор"); builder.SetSurname("Колобов"); var me = builder.GetClient(); me.AddAccount("Тинькофф", "debit", 100000); me.Withdrawal("Тинькофф", me.AccountId[0], 90000); Assert.AreEqual(95000, me.Info("Тинькофф", me.AccountId[0])); }
private static void MainDemo() { var acc1 = new Account(100, "uah"); // id 1 var acc2 = new Account(5454, "uah"); // 2 var acc3 = new Account(200, "usd"); // . var acc4 = new Account(1, "usd"); try { acc1.Activate("Bank228"); acc2.Activate("Bank228"); acc3.Activate("Bank228"); acc4.Activate("WorngPass"); } catch { } Console.WriteLine("---------------------Creating Bank Client"); BankClient client = BankClient.CreateBankClient(); BankClient client2 = BankClient.CreateBankClient(); Console.WriteLine("---------------------Creating Bank Client"); client.AddAccountId(acc1.id); client.AddAccountId(acc3.id); client.ShowInfo(); Console.WriteLine("---------------------Creating Bank Exmployee"); var employee = BankEmployee.CreateBankEmployee(); Console.WriteLine("---------------------Creating Bank Exmployee"); User basicUser = new User("Andrii", "Koval", "login", "password"); BankSystem.AddUser(employee); BankSystem.AddUser(client); BankSystem.AddUser(client2); BankSystem.AddUser(basicUser); }
//Case 1 static void CaseSearchCustomer(BankSystem bankSystem) { Console.WriteLine(); Console.WriteLine("> 1"); Console.WriteLine("* Sök kund *"); Console.Write("Namn eller postort?"); var inputSearch = Console.ReadLine(); var resultSearch = bankSystem.customerManagement.Search(inputSearch); foreach (var item in resultSearch) { Console.WriteLine(item.CustomerId + ": " + item.CustomerName); } if (resultSearch.Count == 0) { Console.WriteLine("Inga kunder med dessa uppgifter hittades."); } }
public void DepositToAccount() { //Assemble NetcoinRepoRepresentation representation = NetcoinRepositoryUtility.CreateSampleCustomersAndAccounts(5, 0M); INetcoinRepository fakeProvider = new FakeNetcoinRepository(); fakeProvider.GetAccounts().AddRange(representation.Accounts); AccountService sut = new AccountService(fakeProvider); BankSystem bank = new BankSystem(fakeProvider); bank.Initialize(); //Act sut.Deposit(2, 100M); //Act & assert Assert.True(fakeProvider.GetAccounts().Single(x => x.AccountId == 2).Balance == 100); Assert.Throws <ArgumentOutOfRangeException>(() => sut.Withdraw(1, -1M)); Assert.Throws <NullReferenceException>(() => sut.Withdraw(100, 1M)); }
public async Task <IActionResult> Buy(Guid id, int units, long creditCard, string returnUrl) { var user = await userManager.GetUserAsync(HttpContext.User); var ad = adRepository.GetAd(id); if (BankSystem.Pay(creditCard)) { AddPurchase(user, ad, units); } else { notificationRepository.AddNotification( new Notification { User = user, Message = $"Sorry, there was problem with your credit card while paying for {units} unit(s) of {ad.Product}", DateTime = DateTime.Now, Type = NotificationType.Error }); } return(Redirect(returnUrl)); }