コード例 #1
0
        private IEnumerable <BankAccount> LoadStorage()
        {
            var result = new List <BankAccount>();

            using (var currentFileStream = new FileStream(_storagePath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.Read))
            {
                using (var currentBinaryReader = new BinaryReader(currentFileStream))
                {
                    while (currentBinaryReader.BaseStream.Position != currentBinaryReader.BaseStream.Length)
                    {
                        var accountId      = currentBinaryReader.ReadInt32();
                        var ammount        = currentBinaryReader.ReadDecimal();
                        var bonus          = currentBinaryReader.ReadInt32();
                        var isClosed       = currentBinaryReader.ReadBoolean();
                        var ownerFirstName = currentBinaryReader.ReadString();
                        var ownerLastName  = currentBinaryReader.ReadString();
                        BankAccountTypes bankAccountType = (BankAccountTypes)currentBinaryReader.ReadInt32();
                        var bonusRate         = currentBinaryReader.ReadInt32();
                        var loadedBankAccount = new BankAccount(accountId, ownerFirstName, ownerLastName, ammount, bonus, isClosed, bankAccountType, bonusRate);
                        result.Add(loadedBankAccount);
                    }
                }
            }

            return(result);
        }
コード例 #2
0
 public BankAccount(int accountId, string ownerFirstName, string ownerLastName, decimal ammount, int bonus, bool isClosed, BankAccountTypes bankAccountType, int bonusRate)
 {
     AccountId       = accountId;
     OwnerFirstName  = ownerFirstName;
     OwnerLastName   = ownerLastName;
     Ammount         = ammount;
     Bonus           = bonus;
     IsClosed        = isClosed;
     BankAccountType = bankAccountType;
     BonusRate       = bonusRate;
 }
コード例 #3
0
        public BankAccount Create(string name, decimal balance, int bonusPoints, Status status, BankAccountTypes type)
        {
            switch (type)
            {
            case BankAccountTypes.Prime:
                return(new PrimeAccount(AccountIdGenerator.GenerateAccountNumber(), name, balance, bonusPoints, status));

            case BankAccountTypes.Silver:
                return(new SilverAccount(AccountIdGenerator.GenerateAccountNumber(), name, balance, bonusPoints, status));

            case BankAccountTypes.Gold:
                return(new GoldAccount(AccountIdGenerator.GenerateAccountNumber(), name, balance, bonusPoints, status));

            case BankAccountTypes.Platinum:
                return(new PlatinumAccount(AccountIdGenerator.GenerateAccountNumber(), name, balance, bonusPoints, status));

            default:
                return(new PrimeAccount(AccountIdGenerator.GenerateAccountNumber(), name, balance, bonusPoints, status));
            }
        }