public override object ReadJson(JsonReader reader,
                                        Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            var jsonObject = JObject.Load(reader);
            var accounts   = AccountFactory.CreateAccount(jsonObject.Value <int>("AccountNumber"),
                                                          jsonObject.Value <char>("AccountType"),
                                                          jsonObject.Value <int>("CustomerID"),
                                                          jsonObject.Value <decimal>("Balance"));

            serializer.Populate(jsonObject.CreateReader(), accounts);
            return(accounts);
        }
Example #2
0
        public Account SelectById(int id)
        {
            using (var conn = GetConnection())
            {
                conn.Open();
                SqlCommand AccCmd = new SqlCommand("SELECT * FROM ACCOUNT WHERE AccountNumber = @AccountNumber", conn);
                AccCmd.Parameters.AddWithValue("@AccountNumber", id);
                AccCmd.ExecuteNonQuery();

                read = AccCmd.ExecuteReader();
                Account a = null;
                while (read.Read())
                {
                    a = AccountFactory.CreateAccount(read.GetInt32(0), read.GetString(1)[0], read.GetInt32(2), read.GetDecimal(3));
                }
                return(a);
            }
        }
Example #3
0
        public List <Account> SelectAll(int id)
        {
            using (var conn = GetConnection())
            {
                conn.Open();
                List <Account> list   = new List <Account>();
                SqlCommand     AccCmd = new SqlCommand("SELECT * FROM ACCOUNT WHERE CustomerID = @CustomerID", conn);
                AccCmd.Parameters.AddWithValue("@CustomerID", id);
                AccCmd.ExecuteNonQuery();

                read = AccCmd.ExecuteReader();
                while (read.Read())
                {
                    Account a = AccountFactory.CreateAccount(read.GetInt32(0), read.GetString(1)[0], read.GetInt32(2), read.GetDecimal(3));
                    list.Add(a);
                }
                return(list);
            }
        }
Example #4
0
        static Account AccountCreationMenu()
        {
            AccountFactory acctFactory = new AccountFactory();
            int            opt;

            do
            {
                Console.WriteLine("\t*-------------Create Account Menu-------------*");

                Console.WriteLine("Choose an account type to create: ");
                Console.WriteLine("1) Checking Account");
                Console.WriteLine("2) Businness Account");
                Console.WriteLine("3) Loan Account");
                Console.WriteLine("4) Term Deposit Account");
                Console.WriteLine("0) Go Back");
                Console.Write("Enter Option: ");
                string st = Console.ReadLine();
                if (!int.TryParse(st, out opt))
                {
                    Console.WriteLine($"Error: [{st}] is not a option");
                }
                else if (opt == 0)
                {
                    break;
                }
                else if (opt < 1 || opt > 4)
                {
                    Console.WriteLine($"Error: {opt} is not an option");
                }
                else
                {
                    //Console.WriteLine("INSIDE CREATE");
                    Console.WriteLine((AccountFactory.AccountsType)opt);
                    Account createdAccount = acctFactory.CreateAccount((AccountFactory.AccountsType)opt);
                    return(createdAccount);
                }
            } while (true);
            return(null);
        }