private BankAccount UpdateAccounts(BankAccount account, bool isClosed = false, int amount = 0, int bonus = 0) { if (account == null) { throw new ArgumentNullException(nameof(account)); } BankAccount newAccount; switch (account.TypeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; case BankAccountType.Gold: newAccount = new GoldAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(account.User, account.AccountId, account.TypeAccount, (uint)(account.Amount + amount), (uint)(account.Bonus + bonus), isClosed); break; default: throw new InvalidEnumArgumentException(nameof(account.TypeAccount)); } return(newAccount); }
/// <summary> /// Opens the account. /// </summary> /// <param name="user">The user.</param> /// <param name="accountType">The type of account.</param> /// <param name="id">The identifier.</param> public void OpenAccount(User user, AccountType accountType) { BankAccount bankAccount; string id = this.GenerateAccountId(user.ToString() + " " + accountType.ToString()); switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } case 1: { bankAccount = new GoldAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } case 2: { bankAccount = new PlatinumAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } default: { bankAccount = new BaseAccount(id, user, accountType, AccountStatus.Open, 0, 0); break; } } bankAccount.Status = AccountStatus.Open; this.bankAccounts.Create(bankAccount); }
private BankAccount CreateAccounts(string accountId, string userId, string firstName, string lastName, BankAccountType typeAccount, uint amount, uint bonus, bool isClosed) { BankAccount newAccount; BankUser bankUser = new BankUser(userId, firstName, lastName); switch (typeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; case BankAccountType.Gold: newAccount = new GoldAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(bankUser, accountId, typeAccount, amount, bonus, isClosed); break; default: throw new InvalidEnumArgumentException(nameof(typeAccount)); } return(newAccount); }
public void Add(string accType, string name, string lastname) { using (AcountStorageDB db = new AcountStorageDB()) { Account acc = new BaseAccount(name, lastname); switch (accType) { case "Basic": acc = new BaseAccount(name, lastname); break; case "Gold": acc = new GoldAccount(name, lastname); break; case "Platinum": acc = new PlatinumAccount(name, lastname); break; } AcountModel acount = new AcountModel(); acount.accid = acc.AccId; acount.ownerName = acc.OwnerName; acount.ownerLastname = acc.OwnerLastName; acount.balance = acc.Balance; acount.bonusPoints = acc.BonusPoints; acount.acouintType = accType; } }
/// <summary> /// Creates new bank account with specified type and adds it to the repository /// </summary> /// <param name="accountOwner">Account owner</param> /// <param name="accountID">Account ID</param> /// <param name="invoiceAmount">Invoice amount</param> /// <param name="bonusScores">Bonus Scores</param> /// <param name="accountType">Account type</param> private void Create(AccountOwner accountOwner, string accountID, decimal invoiceAmount, double bonusScores, AccountType accountType) { BankAccount newAccount; switch (accountType) { case AccountType.Base: { newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base)); } break; case AccountType.Platinum: { newAccount = new PlatinumAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Platinum)); } break; case AccountType.Gold: { newAccount = new GoldAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Gold)); } break; default: { newAccount = new BaseAccount(accountOwner, accountID, invoiceAmount, bonusScores); repository.AddAccount(Mappers.BankAccountsMapper.ToDalBankAccount(newAccount, AccountType.Base)); } break; } }
static void Main() { IAccount vGoldAccount = new GoldAccount(); IAccount vSaverAccount = new SaverAccount(); ITransferAccount vCurAccount = new CurrentAccount(); vGoldAccount.Credit(10000); vSaverAccount.Credit(100); Console.WriteLine($"Gold Account Balance {vGoldAccount.Balance,6:C}"); Console.WriteLine(vSaverAccount.ToString()); vSaverAccount.Debit(1000); IAccount[] allAccounts = new IAccount[2]; allAccounts[0] = vGoldAccount; allAccounts[1] = vSaverAccount; //Dividend... foreach (IAccount Acc in allAccounts) { Acc.Credit(10); } vCurAccount.Transfer(vSaverAccount, vCurAccount); }
/// <summary> /// Opens a new account for <paramref name="holder"/> with <paramref name="startBalance"/>. /// </summary> /// <param name="holder">person's full name</param> /// <param name="startBalance">first deposit amount</param> /// <returns>IBAN of a new account</returns> /// <exception cref="ArgumentException">Start balance is lesser than minimal.</exception> public string OpenNewAccount(string holder, decimal startBalance) { if (string.IsNullOrWhiteSpace(holder)) { throw new ArgumentException("No significant characters are given.", "holder"); } if (startBalance < MINDEPOSIT) { throw new ArgumentException($"Cannot create a bank account with balance lesser than {MINDEPOSIT}"); } BankAccount account; if (startBalance <= 1000) { account = new StandardAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 0); } else if (startBalance <= 10000) { account = new GoldAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 5); } else { account = new PlatinumAccount(ibanGenerator.GenerateIBAN(), holder, startBalance, bonusPoints: 10); } storage.AddAccount(account); return(account.IBAN); }
public Account OpenAccount(string owner, AccountType accountType, IAccountNumberCreateService creator) { Account account; string[] fullName = owner.Split(); switch (accountType) { case AccountType.Base: account = new BaseAccount(creator.GenerateId(), fullName[0], fullName[1]); break; case AccountType.Silver: account = new SilverAccount(creator.GenerateId(), fullName[0], fullName[1]); break; case AccountType.Gold: account = new GoldAccount(creator.GenerateId(), fullName[0], fullName[1]); break; case AccountType.Platinum: account = new PlatinumAccount(creator.GenerateId(), fullName[0], fullName[1]); break; default: account = new BaseAccount(creator.GenerateId(), fullName[0], fullName[1]); break; } this.repository.AddAccount(account.ToDalAccount()); return(account); }
/// <summary> /// Opens the account. /// </summary> /// <param name="user">The user.</param> /// <param name="accountType">The type of account.</param> /// <param name="id">The identifier.</param> public void OpenAccount(User user, AccountType accountType, out int id) { BankAccount bankAccount; switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(user, accountType, AccountStatus.Open, 0, 0); break; } case 1: { bankAccount = new GoldAccount(user, accountType, AccountStatus.Open, 0, 0); break; } case 2: { bankAccount = new PlatinumAccount(user, accountType, AccountStatus.Open, 0, 0); break; } default: { bankAccount = new BaseAccount(user, accountType, AccountStatus.Open, 0, 0); break; } } bankAccount.Status = AccountStatus.Open; this.bankAccounts.Create(bankAccount); id = bankAccount.Id; }
public static BankAccount ToBankAccount(DalBankAccount dalBankAccount) { BankAccount bankAccount; switch (dalBankAccount.AccountType) { case AccountType.Base: { bankAccount = new BaseAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; case AccountType.Platinum: { bankAccount = new PlatinumAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; case AccountType.Gold: { bankAccount = new GoldAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; default: { bankAccount = new BaseAccount(AccountOwnersMapper.ToAccountOwner(dalBankAccount.AccountOwner), dalBankAccount.BankAccountNumber, dalBankAccount.InvoiceAmount, dalBankAccount.BonusScores, dalBankAccount.IsClosed); } break; } return(bankAccount); }
private BankAccount CreateAccountByType(BankUser bankUser, BankAccountType typeAccount) { if (bankUser == null) { throw new ArgumentNullException(nameof(bankUser)); } BankAccount newAccount; switch (typeAccount) { case BankAccountType.Base: newAccount = new BaseAccount(bankUser); break; case BankAccountType.Gold: newAccount = new GoldAccount(bankUser); break; case BankAccountType.Platinum: newAccount = new PlatinumAccount(bankUser); break; default: throw new InvalidEnumArgumentException(nameof(typeAccount)); } return(newAccount); }
public void OpenAccount(IAccountNumberGenerator gen, AccountHolder person, AccountType priveledge, AccountStatus status, int sum, int bonus, out string id) { BankAccount bankAccount; id = gen.GenerateAccountNumber(person + " " + priveledge); switch ((int)priveledge) { case 1: { bankAccount = new BaseAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } case 2: { bankAccount = new GoldAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } case 3: { bankAccount = new PlatinumAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } default: { bankAccount = new BaseAccount(int.Parse(id), person, status, priveledge, sum, bonus); break; } } bankAccount.Status = AccountStatus.Active; fakeRepository.Create(bankAccount); }
public void OpenAccount(string name, AccountType accountType, IAccountNumberCreateService accountNumberCreateService) { _ = name ?? throw new ArgumentNullException(); _ = accountNumberCreateService ?? throw new ArgumentNullException(); Account account; int number = accountNumberCreateService.CreateAccountNumber(); switch (accountType) { case AccountType.Base: account = new BaseAccount(number, name, 0, 0); break; case AccountType.Silver: account = new SilverAccount(number, name, 0, 0); break; case AccountType.Gold: account = new GoldAccount(number, name, 0, 0); break; case AccountType.Platinum: account = new PlatinumAccount(number, name, 0, 0); break; default: throw new ArgumentException(); } accountRepository.Add(account); }
public void InitNewGame(GameMode.GameModeType type) { GameModeCtrl = GameMode.CreateGameMode(type); switch (type) { case GameMode.GameModeType.Demo: #if UNITY_EDITOR GoldAccount = new GoldAccountModeDemo(1000000f); #else GoldAccount = new GoldAccountModeDemo(190f); #endif break; case GameMode.GameModeType.LTE: GoldAccount = new GoldAccountModeLTE(190f); break; case GameMode.GameModeType.Test: GoldAccount = new GoldAccountModeDemo(10000f); break; default: GoldAccount = new GoldAccountModeDemo(190f); break; } GameModeCtrl.GoldAccount = GoldAccount; }
private List <BankAccount> ReadFromFile() { List <BankAccount> bankAccounts = new List <BankAccount>(); try { using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.OpenOrCreate))) { while (reader.PeekChar() > -1) { string id = reader.ReadString(); int status = reader.ReadInt32(); decimal balance = reader.ReadDecimal(); int bonusPoints = reader.ReadInt32(); string userFirstName = reader.ReadString(); string userLastName = reader.ReadString(); int accountType = reader.ReadInt32(); User user = new User(userFirstName, userLastName); BankAccount bankAccount; switch ((int)accountType) { case 0: { bankAccount = new BaseAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } case 1: { bankAccount = new GoldAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } case 2: { bankAccount = new PlatinumAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } default: { bankAccount = new BaseAccount(id, user, (AccountType)accountType, (AccountStatus)status, balance, bonusPoints); break; } } bankAccounts.Add(bankAccount); } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return(bankAccounts); }
private IRequestAccountHandler ChainOfAccountsInitializer() { var account = new ClassicAccount(new ClassicAccountBenefitsRepository()); var silverAccount = new SilverAccount(new SilverAccountBenefitsRepository()); var goldAccount = new GoldAccount(new GoldAccountBenefitsRepository()); account.Successor = silverAccount; silverAccount.Successor = goldAccount; return(account); }
public override bool SellUnit(ActionUnit sellUnit) { float price = GetSellPriceUnit(sellUnit); if (base.SellUnit(sellUnit)) { GoldAccount.ApplyAdd(price); return(true); } return(false); }
public void GoldAccountsGetABonusOnDepositsBeforeEOB() { var account = new GoldAccount(); var openingBalance = account.GetBalance(); var amountToDeposit = 100M; account.Deposit(amountToDeposit); Assert.Equal( openingBalance + amountToDeposit + 7, account.GetBalance()); }
static void Main() { IBankAccount venusAccount = new SaverAccount(); IBankAccount jupiterAccount = new GoldAccount(); venusAccount.PayIn(200); venusAccount.Withdraw(100); Console.WriteLine(venusAccount.ToString()); jupiterAccount.PayIn(500); jupiterAccount.Withdraw(600); jupiterAccount.Withdraw(100); Console.WriteLine(jupiterAccount.ToString()); }
public override bool DeductGoldForShop() { if (GoldAccount.ApplyDeduct(GetShopPrice()) >= 0) { return(true); } else { MainMenuControl.Instance.ShowUserMessage(UserMessageManager.MES_GOLD_INVALID, 1f); GoldAccount.ApplyAdd(GetShopPrice()); return(false); } }
public static void Main(string[] args) { BankAccount a = new BaseAccount(new AccountNumberGenerator(), new AccountHolder("Vanya", "Trashchenko", "*****@*****.**")); BankAccount b = new SilverAccount(new AccountNumberGenerator(), new AccountHolder("Vova", "Lenin", "*****@*****.**")); BankAccount c = new GoldAccount(new AccountNumberGenerator(), new AccountHolder("Sasha", "Pavlov", "*****@*****.**")); BankAccount d = new PlatinumAccount(new AccountNumberGenerator(), new AccountHolder("Katya", "Ivanova", "*****@*****.**")); a.Deposite(100); b.Deposite(100); c.Deposite(100); d.Deposite(100); IRepository rep = new Repository(a, b, c); rep.Save(d); rep.Delete(b); IService ser = new Service(rep); ser.OpenAccount(new AccountNumberGenerator(), new AccountHolder("Sasha", "Vrashchenko", "*****@*****.**"), new GoldAccountFactory()); ser.OpenAccount(new AccountNumberGenerator(), new AccountHolder("Dasha", "Mrashchenko", "*****@*****.**")); // ser.Dump(); foreach (var item in ser.Repository.Accounts) { Console.WriteLine(item.Id); } /* 1427432362 1292111581 1369438661 990816398 746003708 */ ser.Deposite("746003708", 1000); // ser.Withdraw("990816398", 200); throws InvalidBalanceException ser.Transfer("746003708", "990816398", 1); ser.CloseAccount("1427432362"); foreach (var item in ser.Repository.Accounts) { Console.WriteLine(item.ToString()); } Console.ReadKey(); }
static void Main(String[] args) { // 创建两个接口引用变量,接口引用可以引用任何实现该接口的类 IBankAccount vensusAccount = new SaveAccount(); ITransferAccount jupiterAccount = new GoldAccount(); vensusAccount.PayIn(200); jupiterAccount.PayIn(500); // 实现jupiterAccount向venusAccount账户转账 jupiterAccount.TransferTo(vensusAccount, 100); Console.WriteLine(vensusAccount.ToString()); Console.WriteLine(jupiterAccount.ToString()); Console.Read(); }
/// <summary> /// Determines the type of account for its creation. /// </summary> /// <param name="_id">Bank account's id.</param> /// <param name="firstName">Bank account's first name.</param> /// <param name="lastName">Bank account's last name.</param> /// <param name="phone">Bank account's phone number.</param> /// <param name="status">Bank account's status.</param> /// <param name="type">Bank account's type.</param> /// <param name="sum">Bank account's first added sum.</param> /// <param name="points">Bank account's first added points.</param> /// <returns>Bank account instance.</returns> internal BankAccount DefineAccount(int _id, string firstName, string lastName, string phone, AccountStatus status, AccountType type, int sum, int points) { BankAccount account = null; switch (type) { case AccountType.Base: account = new BaseAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); break; case AccountType.Gold: account = new GoldAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); break; case AccountType.Premium: account = new PlatinumAccount(_id, new AccountHolder(firstName, lastName, phone), status, type, sum, points); break; } return(account); }
private void button1_Click(object sender, EventArgs e) { IBankAccount venusAccount = new SaverAccount(); IBankAccount jupiterAccount = new GoldAccount(); venusAccount.PayIn(200); venusAccount.Withdraw(100); Console.WriteLine(venusAccount.ToString()); jupiterAccount.PayIn(500); jupiterAccount.Withdraw(600); jupiterAccount.Withdraw(100); Console.WriteLine(jupiterAccount.ToString()); }
public static AccountBase CreateAccount(AccountType type) { AccountBase account = null; switch (type) { case AccountType.Silver: account = new SilverAccount(); break; case AccountType.Gold: account=new GoldAccount(); break; case AccountType.Platinum: account=new PlatinumAccount(); break; } return account; }
public List <Account> GetAccounts() { using (AcountStorageDB db = new AcountStorageDB()) { List <AcountModel> tempacc = db.Acounts.ToList(); if (tempacc != null) { List <Account> listaccs = new List <Account>(); foreach (AcountModel acc in tempacc) { Account accentity; switch (acc.acouintType) { case "Basic": accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Gold": accentity = new GoldAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; case "Platinum": accentity = new PlatinumAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; default: accentity = new BaseAccount(acc.ownerName, acc.ownerLastname, acc.accid); break; } accentity.BonusPoints = acc.bonusPoints; accentity.Balance = acc.balance; listaccs.Add(accentity); } return(listaccs); } else { throw new Exception(); } } }
static void Main(string[] args) { IBankAccount saver = new SaverAccount(); IBankAccount gold = new GoldAccount(); try { Console.WriteLine("First count:"); Console.WriteLine($"Number of Gold Accounts: {GoldAccount.NumOfAccounts}"); Console.WriteLine($"Number of Saver Accounts: {SaverAccount.NumOfAccounts}"); IBankAccount saver1 = new SaverAccount(); IBankAccount gold1 = new GoldAccount(); Console.WriteLine("Second count:"); Console.WriteLine($"Number of Gold Accounts: {GoldAccount.NumOfAccounts}"); Console.WriteLine($"Number of Saver Accounts: {SaverAccount.NumOfAccounts}"); gold1 = null; saver1 = null; GC.Collect(); Console.WriteLine("After null:"); Console.WriteLine($"Number of Gold Accounts: {GoldAccount.NumOfAccounts}"); Console.WriteLine($"Number of Saver Accounts: {SaverAccount.NumOfAccounts}"); saver.Deposit(1250.75M); saver.Withdraw(700.50M); gold.Deposit(5000.38M); gold.Withdraw(5678.90M); } catch (Exception ex) { Console.WriteLine(ex.Message); } finally { Console.WriteLine($"after withdrawal of $700.50...{saver.ToString()}"); Console.WriteLine($"after (failed)withdrawal of $5678.90...{gold.ToString()}"); } }
static void Main(String[] args) { // 创建两个接口引用变量,接口引用可以引用任何实现该接口的类 IBankAccount vensusAccount = new SaveAccount(); IBankAccount jupiterAccount = new GoldAccount(); vensusAccount.PayIn(200); vensusAccount.WithDraw(100); Console.WriteLine(vensusAccount.ToString()); jupiterAccount.PayIn(500); jupiterAccount.WithDraw(600); jupiterAccount.WithDraw(100); Console.WriteLine(jupiterAccount.ToString()); Console.Read(); // 创建接口数组,其中每个元素都是不同的类 IBankAccount[] accounts = new IBankAccount[2]; accounts[0] = new SaveAccount(); accounts[1] = new GoldAccount(); }
/// <summary> /// Creates new account. /// </summary> /// <param name="name">Name of account's owner.</param> /// <param name="accountType">Type of account.</param> /// <param name="creator">Service for creating number of account.</param> public void OpenAccount(string name, string email, AccountType accountType, IAccountNumberCreateService creator) { Account account = null; switch (accountType) { case AccountType.Base: account = new BaseAccount(creator.Create(accountNum++), name, email); break; case AccountType.Gold: account = new GoldAccount(creator.Create(accountNum++), name, email); break; case AccountType.Platinum: account = new PlatinumAccount(creator.Create(accountNum++), name, email); break; } repository.Create(account.ToAccountDto()); }
public static AccountBase CreateAccount(AccountType type) { AccountBase account = null; switch (type) { case AccountType.Silver: account = new SilverAccount(); break; case AccountType.Gold: account = new GoldAccount(); break; case AccountType.Platinum: account = new PlatinumAccount(); break; } return(account); }
public static void Main() { IBankAccount venusAccount = new SaverAccount(); IBankAccount jupiterAccount = new GoldAccount(); venusAccount.PayIn(200); venusAccount.Withdraw(100); Console.WriteLine(venusAccount.ToString()); jupiterAccount.PayIn(500); jupiterAccount.Withdraw(600); jupiterAccount.Withdraw(100); Console.WriteLine(jupiterAccount.ToString()); ITransferBankAccount jupiterAccount2 = new CurrentAccount(); jupiterAccount2.PayIn(500); jupiterAccount2.TransferTo(venusAccount, 100); Console.WriteLine(venusAccount.ToString()); Console.WriteLine(jupiterAccount2.ToString()); }