示例#1
0
        public void GetRow(string id, out Account account)
        {
            bool foundAccount = false;

            account = null;

            using (StreamReader stream = new StreamReader(_accountsPath))
            {
                while (!stream.EndOfStream && !foundAccount)
                {
                    var line = stream.ReadLine();
                    if (line == "ID;Name;Type;Balance")
                    {
                        continue;
                    }
                    var values = line.Split(";");

                    if (values[0] == id)
                    {
                        int.TryParse(values[2], out int _type);
                        var type = (AccountType)_type;
                        decimal.TryParse(values[2], out decimal balance);
                        switch (type)
                        {
                        case AccountType.ConsumerAccount:
                            account = new ConsumerAccount(values[0], values[1])
                            {
                                Balance = balance
                            };
                            break;

                        case AccountType.CheckingAccount:
                            account = new CheckingAccount(values[0], values[1])
                            {
                                Balance = balance
                            };
                            break;

                        case AccountType.SavingsAccount:
                            account = new SavingsAccount(values[0], values[1])
                            {
                                Balance = balance
                            };
                            break;

                        default:
                            break;
                        }

                        foundAccount = true;
                    }
                }
            }
        }
示例#2
0
        public Account CreateAccount(string name, AccountType accountType, decimal balance = 0M)
        {
            _lastId += 1;

            switch (accountType)
            {
            case AccountType.ConsumerAccount:
                var newConsumerAccount = new ConsumerAccount(name)
                {
                    Balance = balance
                };
                _fileRepository.AddRow(newConsumerAccount);
                LoggerService.Write($"[NEW_ACCOUNT] NEW CONSUMER ACCOUNT, ID = {newConsumerAccount.Id}");
                return(newConsumerAccount);

            case AccountType.CheckingAccount:
                var newCheckingAccount = new CheckingAccount(name)
                {
                    Balance = balance
                };
                _fileRepository.AddRow(newCheckingAccount);
                LoggerService.Write($"[NEW_ACCOUNT] NEW CHECKING ACCOUNT, ID = {newCheckingAccount.Id}");
                return(newCheckingAccount);

            case AccountType.SavingsAccount:
                var newSavingsAccount = new SavingsAccount(name)
                {
                    Balance = balance
                };
                _fileRepository.AddRow(newSavingsAccount);
                LoggerService.Write($"[NEW_ACCOUNT] NEW SAVINGS ACCOUNT, ID = {newSavingsAccount.Id}");
                return(newSavingsAccount);

            default:
                throw new Exception("MissingAccountType");
                break;
            }
        }