/// <inheritdoc/> public void OpenAccount(string owner, AccountGrade grade, IAccountIdGenerator generator) { if (string.IsNullOrWhiteSpace(owner)) { throw new ArgumentNullException(nameof(owner)); } if (!Enum.IsDefined(typeof(AccountGrade), grade)) { throw new ArgumentException($"Value '{grade}' is not defined."); } if (generator is null) { throw new ArgumentNullException(nameof(generator)); } var dto = new AccountDto() { Id = generator.GenerateGuidId(), Type = (int)grade, Owner = owner, Balance = 0, Bonus = 0, }; this.repository.AddRecord(dto); }
/// <summary> /// The assembly entry point. /// </summary> internal static void Main() { IAccountService service = Resolver.Get <IAccountService>(); IAccountIdGenerator generator = Resolver.Get <IAccountIdGenerator>(); service.OpenAccount("Ivan Petrovich Sidorov", AccountGrade.Base, generator); service.OpenAccount("Sidor Ivanovich Petrov", AccountGrade.Silver, generator); service.OpenAccount("Petr Sidorovich Ivanov", AccountGrade.Gold, generator); service.OpenAccount("William Henry Gates", AccountGrade.Platinum, generator); var accountIdSet = service.GetAllAccounts().Select(acc => acc.Id).ToArray(); Console.WriteLine(new string('-', 15)); Console.WriteLine("Depositing 100:"); Console.WriteLine(new string('-', 15)); Console.WriteLine(); foreach (var id in accountIdSet) { service.MakeDeposit(id, 100); } foreach (var account in service.GetAllAccounts()) { ShowAccount(account); } Console.WriteLine(new string('-', 15)); Console.WriteLine("Withdrawing 10:"); Console.WriteLine(new string('-', 15)); Console.WriteLine(); foreach (var id in accountIdSet) { service.MakeWithdrawal(id, 10); } foreach (var account in service.GetAllAccounts()) { ShowAccount(account); } Console.ReadKey(); }
/// <summary> /// Open a new bank account. /// </summary> /// <param name="generator">Generates the account id.</param> /// <param name="holder">Holder of the account.</param> /// <param name="accountType">Type of the account.</param> /// <returns>Id of the created account.</returns> /// <exception cref="ArgumentNullException">Some argument is null.</exception> /// <exception cref="ArgumentException">The account type is not defined./exception> public string OpenAccount(IAccountIdGenerator generator, AccountHolder holder, string accountType) { if (generator == null || holder == null || accountType == null) { throw new ArgumentNullException(); } BankAccount account = null; switch (accountType.ToLower()) { case "base": { _storage?.AddBankAccount(account = new BaseAccount(holder, generator)); break; } case "platinum": { _storage?.AddBankAccount(account = new PlatinumAccount(holder, generator)); break; } case "gold": { _storage?.AddBankAccount(account = new GoldAccount(holder, generator)); break; } default: { throw new ArgumentException(nameof(accountType) + " is not defined."); } } return(account?.Id); }
public string OpenAccount(AccountHolder bankUser, IAccountIdGenerator idGenerator, decimal sum, AccountType accountType = AccountType.Base) { throw new System.NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="GoldAccount"/> class. /// </summary> /// <param name="holder">The account holder.</param> /// <param name="idGenerator">The identifier generator.</param> public GoldAccount(AccountHolder holder, IAccountIdGenerator idGenerator) : base(holder, idGenerator) { }
/// <summary> /// Initializes a new instance of the <see cref="BankAccount"/> class. /// </summary> /// <param name="AccHolder">The account holder.</param> /// <param name="idGenerator">The identifier generator.</param> protected BankAccount(AccountHolder accHolder, IAccountIdGenerator idGenerator) { Holder = accHolder; Id = idGenerator.Generate(); }
/// <summary> /// Initializes a new instance of the <see cref="PlatinumAccount"/> class. /// </summary> /// <param name="holder">The account holder.</param> /// <param name="idGenerator">The identifier generator.</param> public PlatinumAccount(AccountHolder holder, IAccountIdGenerator idGenerator) : base(holder, idGenerator) { }